diff options
Diffstat (limited to 'test/utils')
-rw-r--r-- | test/utils/filematcher/test_parser.py | 6 | ||||
-rw-r--r-- | test/utils/test_loading.py | 48 |
2 files changed, 51 insertions, 3 deletions
diff --git a/test/utils/filematcher/test_parser.py b/test/utils/filematcher/test_parser.py index a81d2ed..c594747 100644 --- a/test/utils/filematcher/test_parser.py +++ b/test/utils/filematcher/test_parser.py @@ -4,11 +4,11 @@ Part of the bsie test suite. A copy of the license is provided with the project. Author: Matthias Baumgartner, 2022 """ -# imports +# standard imports import unittest -# inner-module imports -from bsie.base import errors +# bsie imports +from bsie.utils import errors from bsie.utils.filematcher import matcher # objects to test diff --git a/test/utils/test_loading.py b/test/utils/test_loading.py new file mode 100644 index 0000000..58ff166 --- /dev/null +++ b/test/utils/test_loading.py @@ -0,0 +1,48 @@ +""" + +Part of the bsie test suite. +A copy of the license is provided with the project. +Author: Matthias Baumgartner, 2022 +""" +# standard imports +import unittest + +# bsie imports +from bsie.utils import errors + +# objects to test +from bsie.utils.loading import safe_load, unpack_qualified_name + + +## code ## + +class TestUtils(unittest.TestCase): + def test_safe_load(self): + # invalid module + self.assertRaises(errors.LoaderError, safe_load, 'dBGHMSAYOoKeKMpywDoKZQycENFPvN', 'foobar') + self.assertRaises(errors.LoaderError, safe_load, 'dBGHMSAYOoKeKMpywDoKZQycENFPvN.bar', 'foobar') + # partially valid module + self.assertRaises(errors.LoaderError, safe_load, 'os.foo', 'foobar') + # invalid class + self.assertRaises(errors.LoaderError, safe_load, 'os.path', 'foo') + # valid module and class + cls = safe_load('collections.abc', 'Container') + import collections.abc + self.assertEqual(cls, collections.abc.Container) + + def test_unpack_qualified_name(self): + self.assertRaises(TypeError, unpack_qualified_name, 123) + self.assertRaises(TypeError, unpack_qualified_name, None) + self.assertRaises(ValueError, unpack_qualified_name, '') + self.assertRaises(ValueError, unpack_qualified_name, 'path') + self.assertRaises(ValueError, unpack_qualified_name, '.Path') + self.assertEqual(unpack_qualified_name('path.Path'), ('path', 'Path')) + self.assertEqual(unpack_qualified_name('path.foo.bar.Path'), ('path.foo.bar', 'Path')) + + +## main ## + +if __name__ == '__main__': + unittest.main() + +## EOF ## |