blob: 957509aa627888e4d8e176889f61f3bcc765f2f1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
"""
Part of the bsfs test suite.
A copy of the license is provided with the project.
Author: Matthias Baumgartner, 2022
"""
# imports
import contextlib
import io
import os
import sys
import unittest
import unittest.mock
# bsie imports
from bsfs.schema import Schema
# objects to test
from bsfs.apps.migrate import main
## code ##
class TestMigrate(unittest.TestCase):
def test_main(self):
config = os.path.join(os.path.dirname(__file__), 'config.json')
schema_1 = os.path.join(os.path.dirname(__file__), 'schema-1.nt')
schema_2 = os.path.join(os.path.dirname(__file__), 'schema-2.nt')
# provide no config
with contextlib.redirect_stderr(io.StringIO()):
self.assertRaises(SystemExit, main, [])
# read schema from file
with open(schema_1) as ifile:
target = Schema.from_string(ifile.read())
graph = main([config, schema_1])
self.assertTrue(target <= graph.schema)
# read schema from multiple files
with open(schema_1) as ifile:
target = Schema.from_string(ifile.read())
with open(schema_2) as ifile:
target = target + Schema.from_string(ifile.read())
graph = main([config, schema_1, schema_2])
self.assertTrue(target <= graph.schema)
# read schema from stdin
with open(schema_1, 'rt') as ifile:
target = Schema.from_string(ifile.read())
with open(schema_1, 'rt') as ifile:
with unittest.mock.patch('sys.stdin', ifile):
graph = main([config])
self.assertTrue(target <= graph.schema)
# remove predicates
# NOTE: cannot currently test this since there's nothing to remove in the loaded (empty) schema.
## main ##
if __name__ == '__main__':
unittest.main()
## EOF ##
|