From 9d7fd077776220188344d0e6fa506e6dc9d2575a Mon Sep 17 00:00:00 2001 From: drforse Date: Fri, 17 Dec 2021 20:37:50 +0300 Subject: [PATCH] add missing commit with tests for `import all modules in dir` --- tests/test_utils/test_imports.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/test_utils/test_imports.py b/tests/test_utils/test_imports.py index e877201c..446d9e76 100644 --- a/tests/test_utils/test_imports.py +++ b/tests/test_utils/test_imports.py @@ -1,7 +1,7 @@ import pytest import aiogram -from aiogram.utils.imports import import_module +from aiogram.utils.imports import import_module, import_all_modules class TestImports: @@ -27,3 +27,23 @@ class TestImports: value = import_module("aiogram:__version__") isinstance(value, str) assert value == aiogram.__version__ + + +class TestAllModulesImports: + def test_relative_import_without_package(self): + with pytest.raises(TypeError, match="the 'package' argument is required to perform a relative import for"): + import_all_modules(".kaboom") + + def test_non_existing_root(self): + with pytest.raises(ModuleNotFoundError): + import_all_modules("kaboom") + + def test_non_existing_package(self): + with pytest.raises(ModuleNotFoundError): + import_all_modules("test", "kaboom") + + def test_imported(self, capfd): + import_all_modules("tests.modules_for_tests") + captured = capfd.readouterr() + assert captured.out == "__init__ imported\nsmall_module imported\n" \ + "small_package imported\nnested_small_module imported\n"