diff options
author | Matthias Baumgartner <dev@igsor.net> | 2023-03-02 08:58:29 +0100 |
---|---|---|
committer | Matthias Baumgartner <dev@igsor.net> | 2023-03-02 08:58:29 +0100 |
commit | ba6329bbe14c832d42773dee2fe30bd7669ca255 (patch) | |
tree | 4cd2771d95adaba0663fd7879b1666ebd3ef3cb9 /test/apps | |
parent | 70d77819a84c73292825b81f952e162bb30753d7 (diff) | |
download | bsie-ba6329bbe14c832d42773dee2fe30bd7669ca255.tar.gz bsie-ba6329bbe14c832d42773dee2fe30bd7669ca255.tar.bz2 bsie-ba6329bbe14c832d42773dee2fe30bd7669ca255.zip |
various minor fixes
Diffstat (limited to 'test/apps')
-rw-r--r-- | test/apps/test_main.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/test/apps/test_main.py b/test/apps/test_main.py new file mode 100644 index 0000000..a1d8a49 --- /dev/null +++ b/test/apps/test_main.py @@ -0,0 +1,57 @@ + +# standard imports +import contextlib +import io +import json +import os +import tempfile +import unittest +import yaml + +# objects to test +from bsie.apps import main + + +## code ## + +class TestMain(unittest.TestCase): + def setUp(self): + config = { + 'ReaderBuilder': {}, + 'ExtractorBuilder': [ + {'bsie.extractor.generic.stat.Stat': {}}, + {'bsie.extractor.generic.path.Path': {}}, + ] + } + # create config file + _, self.config_path = tempfile.mkstemp(prefix='bsie-test-', suffix='.yaml') + with open(self.config_path, 'wt') as cfile: + yaml.dump(config, cfile) + + def tearDown(self): + if os.path.exists(self.config_path): + os.unlink(self.config_path) + + def test_main(self): + # must at least pass an app + with contextlib.redirect_stderr(io.StringIO()): + self.assertRaises(SystemExit, main, []) + # app takes over + with contextlib.redirect_stderr(io.StringIO()): + self.assertRaises(SystemExit, main, ['info']) + outbuf = io.StringIO() + with contextlib.redirect_stdout(outbuf): + main(['info', '--config', self.config_path, 'predicates']) + self.assertEqual(set(outbuf.getvalue().strip().split('\n')), { + 'http://bsfs.ai/schema/Entity#filename', + 'http://bsfs.ai/schema/Entity#filesize', + 'http://bsfs.ai/schema/Predicate', + }) + + +## main ## + +if __name__ == '__main__': + unittest.main() + +## EOF ## |