Пример #1
0
def test_get_module_raises_on_inner_import(known_dirs):
    """get_module should not hide failing import statements in imported mod."""
    p = Path.cwd().joinpath('tests')
    moduleloader.set_working_directory(p)

    with pytest.raises(PyModuleNotFoundError) as err:
        moduleloader.get_module('arbpack.arbinvalidimportmod')

    assert str(err.value) == (
        'error importing module blahblah in arbpack.arbinvalidimportmod')

    assert sys.path == ['arb', str(p)]
Пример #2
0
def test_get_module_raises():
    """On get_module ModuleNotFoundError on module not found."""
    with pytest.raises(PyModuleNotFoundError) as err:
        moduleloader.get_module('unlikelyblahmodulenameherexxssz')

    assert str(err.value) == (
        "unlikelyblahmodulenameherexxssz.py should be in your working "
        "dir or it should be installed to the python path."
        "\nIf you have 'package.sub.mod' your current working "
        "dir should contain ./package/sub/mod.py\n"
        "If you specified 'mymodulename', your current "
        "working dir should contain ./mymodulename.py\n"
        "If the module is not in your current working dir, it "
        "must exist in your current python path - so you "
        "should have run pip install or setup.py")
Пример #3
0
def test_get_module_in_package_pass(known_dirs):
    """See get_module find a module in a package in cwd using dot notation."""
    p = Path.cwd().joinpath('tests')
    moduleloader.set_working_directory(p)
    arb_module = moduleloader.get_module('arbpack.arbmod')

    assert arb_module
    assert arb_module.__name__ == 'arbpack.arbmod'
    assert hasattr(arb_module, 'arbmod_attribute')

    assert sys.path == ['arb', str(p)]
Пример #4
0
def test_get_module_raises_friendly_on_package_import(known_dirs):
    """get_module should not obscure missing module in existing package."""
    p = Path.cwd().joinpath('tests')
    moduleloader.set_working_directory(p)

    with pytest.raises(PyModuleNotFoundError) as err:
        moduleloader.get_module('arbpack.idontexist')

    assert str(
        err.value) == ("arbpack.idontexist.py should be in your working "
                       "dir or it should be installed to the python path."
                       "\nIf you have 'package.sub.mod' your current working "
                       "dir should contain ./package/sub/mod.py\n"
                       "If you specified 'mymodulename', your current "
                       "working dir should contain ./mymodulename.py\n"
                       "If the module is not in your current working dir, it "
                       "must exist in your current python path - so you "
                       "should have run pip install or setup.py")

    assert sys.path == ['arb', str(p)]
Пример #5
0
def test_get_module_pass(known_dirs):
    """Pass when get_module finds a module in cwd."""
    p = Path.cwd().joinpath('tests', 'testfiles')
    moduleloader.set_working_directory(p)

    arb_module = moduleloader.get_module('arb')

    assert arb_module
    assert arb_module.__name__ == 'arb'
    assert hasattr(arb_module, 'arb_attribute')

    assert sys.path == ['arb', str(p)]
Пример #6
0
def test_get_module_raises_compatible_error():
    """get_module should raise error compatible with ModuleNotFoundError."""
    with pytest.raises(ModuleNotFoundError):
        moduleloader.get_module('unlikelyblahmodulenameherexxssz')