diff options
author | Matthias Baumgartner <dev@igsor.net> | 2022-12-24 10:27:09 +0100 |
---|---|---|
committer | Matthias Baumgartner <dev@igsor.net> | 2022-12-24 10:27:09 +0100 |
commit | 266c2c9a072bf3289fd7f2d75278b7d59528378c (patch) | |
tree | 60760e0fec84d5cd7b3f3efef11e3892df5cc85a /test/utils/test_loading.py | |
parent | ed2074ae88f2db6cb6b38716b43b35e29eb2e16c (diff) | |
download | bsie-266c2c9a072bf3289fd7f2d75278b7d59528378c.tar.gz bsie-266c2c9a072bf3289fd7f2d75278b7d59528378c.tar.bz2 bsie-266c2c9a072bf3289fd7f2d75278b7d59528378c.zip |
package restructuring: base
* Reader and Extractor to respective reader/extractor modules
* ReaderBuilder to reader module
* ExtractorBuilder to extractor module
* Loading module in utils (safe_load, unpack_name)
* Pipeline and PipelineBuilder to lib module
* errors to utils
* documentation: "standard import" and "external import"
Diffstat (limited to 'test/utils/test_loading.py')
-rw-r--r-- | test/utils/test_loading.py | 48 |
1 files changed, 48 insertions, 0 deletions
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 ## |