Ejemplo n.º 1
0
def test_load_nox_module_needs_version_dynamic(reset_needs_version, tmp_path):
    text = dedent("""
        import nox
        NOX_NEEDS_VERSION = ">=9999.99.99"
        nox.needs_version = NOX_NEEDS_VERSION
        """)
    noxfile = tmp_path / "noxfile.py"
    noxfile.write_text(text)
    config = _options.options.namespace(noxfile=str(noxfile))
    tasks.load_nox_module(config)
    # Dynamic version requirements are not checked.
    assert nox.needs_version == ">=9999.99.99"
Ejemplo n.º 2
0
def test_load_nox_module_not_found(caplog, tmp_path):
    bogus_noxfile = tmp_path / "bogus.py"
    config = _options.options.namespace(noxfile=str(bogus_noxfile))

    assert tasks.load_nox_module(config) == 2
    assert (f"Failed to load Noxfile {bogus_noxfile}, no such file exists."
            in caplog.text)
Ejemplo n.º 3
0
def test_load_nox_module_os_error(caplog):
    noxfile = os.path.join(RESOURCES, "noxfile.py")
    config = _options.options.namespace(noxfile=noxfile)
    with mock.patch("nox.tasks.check_nox_version",
                    autospec=True) as version_checker:
        version_checker.side_effect = OSError
        assert tasks.load_nox_module(config) == 2
        assert f"Failed to load Noxfile {noxfile}" in caplog.text
Ejemplo n.º 4
0
def test_load_nox_module_needs_version_static(reset_needs_version, tmp_path):
    text = dedent("""
        import nox
        nox.needs_version = ">=9999.99.99"
        """)
    noxfile = tmp_path / "noxfile.py"
    noxfile.write_text(text)
    config = _options.options.namespace(noxfile=str(noxfile))
    assert tasks.load_nox_module(config) == 2
Ejemplo n.º 5
0
def _session_completer(prefix, parsed_args, **kwargs):
    global_config = parsed_args
    module = load_nox_module(global_config)
    manifest = discover_manifest(module, global_config)
    filtered_manifest = filter_manifest(manifest, global_config)
    return [
        session.friendly_name
        for session, _ in filtered_manifest.list_all_sessions()
    ]
Ejemplo n.º 6
0
def _session_completer(prefix: str, parsed_args: argparse.Namespace,
                       **kwargs: Any) -> List[str]:
    global_config = parsed_args
    module = load_nox_module(global_config)
    manifest = discover_manifest(module, global_config)
    filtered_manifest = filter_manifest(manifest, global_config)
    if isinstance(filtered_manifest, int):
        return []
    return [
        session.friendly_name
        for session, _ in filtered_manifest.list_all_sessions()
    ]
Ejemplo n.º 7
0
def test_load_nox_module_expandvars():
    # Assert that variables are expanded when looking up the path to the noxfile
    # This is particular importand in Windows when one needs to use variables like
    # %TEMP% to point to the noxfile.py
    with mock.patch.dict(os.environ, {"RESOURCES_PATH": RESOURCES}):
        if platform.system().lower().startswith("win"):
            config = argparse.Namespace(noxfile="%RESOURCES_PATH%/noxfile.py")
        else:
            config = argparse.Namespace(noxfile="${RESOURCES_PATH}/noxfile.py")
        noxfile_module = tasks.load_nox_module(config)
    assert noxfile_module.__file__ == os.path.join(RESOURCES, "noxfile.py")
    assert noxfile_module.SIGIL == "123"
Ejemplo n.º 8
0
def test_load_nox_module_IOError(caplog):

    # Need to give it a noxfile that exists so load_nox_module can progress
    # past FileNotFoundError
    # use our own noxfile.py for this
    our_noxfile = Path(__file__).parent.parent.joinpath("noxfile.py")
    config = _options.options.namespace(noxfile=str(our_noxfile))

    with mock.patch("nox.tasks.importlib.util.module_from_spec") as mock_load:
        mock_load.side_effect = IOError

        assert tasks.load_nox_module(config) == 2
        assert "Failed to load Noxfile" in caplog.text
Ejemplo n.º 9
0
def test_load_nox_module_not_found():
    config = Namespace(noxfile='bogus.py')
    assert tasks.load_nox_module(config) == 2
Ejemplo n.º 10
0
def test_load_nox_module():
    config = Namespace(noxfile=os.path.join(RESOURCES, 'noxfile.py'))
    noxfile_module = tasks.load_nox_module(config)
    assert noxfile_module.SIGIL == '123'
Ejemplo n.º 11
0
def test_load_nox_module_not_found():
    config = argparse.Namespace(noxfile="bogus.py")
    assert tasks.load_nox_module(config) == 2
Ejemplo n.º 12
0
def test_load_nox_module():
    config = argparse.Namespace(noxfile=os.path.join(RESOURCES, "noxfile.py"))
    noxfile_module = tasks.load_nox_module(config)
    assert noxfile_module.SIGIL == "123"
Ejemplo n.º 13
0
def test_load_nox_module_not_found():
    config = _options.options.namespace(noxfile="bogus.py")
    assert tasks.load_nox_module(config) == 2