def test_load_module_error(tmpdir): root = tmpdir.mkdir('loader_mods') mod_file = root.join('file_mod.py') mod_file.write(MOCK_MODULE_CONTENT) with pytest.raises(TypeError): loader.load_module('file_mod', mod_file.strpath, None)
def test_clean_module_commands(tmpdir, tmpconfig): root = tmpdir.mkdir('loader_mods') mod_file = root.join('file_mod.py') mod_file.write(MOCK_MODULE_CONTENT) test_mod, _ = loader.load_module('file_mod', mod_file.strpath, imp.PY_SOURCE) callables, jobs, shutdowns, urls = loader.clean_module(test_mod, tmpconfig) assert len(callables) == 2 assert test_mod.first_command in callables assert test_mod.second_command in callables assert len(jobs) == 2 assert test_mod.interval5s in jobs assert test_mod.interval10s in jobs assert len(shutdowns) assert test_mod.shutdown in shutdowns assert len(urls) == 1 assert test_mod.example_url in urls # ignored function is ignored assert test_mod.ignored not in callables assert test_mod.ignored not in jobs assert test_mod.ignored not in shutdowns assert test_mod.ignored not in urls
def test_clean_module_commands(tmpdir, tmpconfig): root = tmpdir.mkdir('loader_mods') mod_file = root.join('file_mod.py') mod_file.write(MOCK_MODULE_CONTENT) test_mod, _ = loader.load_module( 'file_mod', mod_file.strpath, imp.PY_SOURCE) callables, jobs, shutdowns, urls = loader.clean_module( test_mod, tmpconfig) assert len(callables) == 2 assert test_mod.first_command in callables assert test_mod.second_command in callables assert len(jobs) == 2 assert test_mod.interval5s in jobs assert test_mod.interval10s in jobs assert len(shutdowns) assert test_mod.shutdown in shutdowns assert len(urls) == 1 assert test_mod.example_url in urls # ignored function is ignored assert test_mod.ignored not in callables assert test_mod.ignored not in jobs assert test_mod.ignored not in shutdowns assert test_mod.ignored not in urls
def test_load_module_pymod(tmpdir): root = tmpdir.mkdir('loader_mods') mod_file = root.join('file_mod.py') mod_file.write(MOCK_MODULE_CONTENT) test_mod, timeinfo = loader.load_module('file_mod', mod_file.strpath, imp.PY_SOURCE) assert hasattr(test_mod, 'first_command') assert hasattr(test_mod, 'second_command') assert hasattr(test_mod, 'interval5s') assert hasattr(test_mod, 'interval10s') assert hasattr(test_mod, 'example_url') assert hasattr(test_mod, 'shutdown') assert hasattr(test_mod, 'ignored') assert timeinfo == os.path.getmtime(mod_file.strpath)
def test_load_module_pymod(tmpdir): root = tmpdir.mkdir('loader_mods') mod_file = root.join('file_mod.py') mod_file.write(MOCK_MODULE_CONTENT) test_mod, timeinfo = loader.load_module( 'file_mod', mod_file.strpath, imp.PY_SOURCE) assert hasattr(test_mod, 'first_command') assert hasattr(test_mod, 'second_command') assert hasattr(test_mod, 'interval5s') assert hasattr(test_mod, 'interval10s') assert hasattr(test_mod, 'example_url') assert hasattr(test_mod, 'shutdown') assert hasattr(test_mod, 'ignored') assert timeinfo == os.path.getmtime(mod_file.strpath)
def test_load_module_pypackage(tmpdir): root = tmpdir.mkdir('loader_mods') package_dir = root.mkdir('dir_mod') mod_file = package_dir.join('__init__.py') mod_file.write(MOCK_MODULE_CONTENT) test_mod, timeinfo = loader.load_module('dir_mod', package_dir.strpath, imp.PKG_DIRECTORY) assert hasattr(test_mod, 'first_command') assert hasattr(test_mod, 'second_command') assert hasattr(test_mod, 'interval5s') assert hasattr(test_mod, 'interval10s') assert hasattr(test_mod, 'example_url') assert hasattr(test_mod, 'shutdown') assert hasattr(test_mod, 'ignored') assert timeinfo == os.path.getmtime(package_dir.strpath)
def test_load_module_pypackage(tmpdir): root = tmpdir.mkdir('loader_mods') package_dir = root.mkdir('dir_mod') mod_file = package_dir.join('__init__.py') mod_file.write(MOCK_MODULE_CONTENT) test_mod, timeinfo = loader.load_module( 'dir_mod', package_dir.strpath, imp.PKG_DIRECTORY) assert hasattr(test_mod, 'first_command') assert hasattr(test_mod, 'second_command') assert hasattr(test_mod, 'interval5s') assert hasattr(test_mod, 'interval10s') assert hasattr(test_mod, 'example_url') assert hasattr(test_mod, 'shutdown') assert hasattr(test_mod, 'ignored') assert timeinfo == os.path.getmtime(package_dir.strpath)