Exemple #1
0
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)
Exemple #2
0
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)
Exemple #3
0
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
Exemple #4
0
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
Exemple #5
0
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)
Exemple #6
0
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)
Exemple #7
0
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)
Exemple #8
0
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)