""" 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 ##