Ejemplo n.º 1
0
def test_env_list():
    # Fresh env so should be none
    assert not npmenv.env_list()
    # Trigger creating env for CWD
    npmenv.env_npm()
    # Ensure list gives new env
    assert npmenv.env_list()[0][1] == Path.cwd()
Ejemplo n.º 2
0
 def test_env_modules(self, monkeypatch, sandbox, capfd):
     npmenv.env_npm(f'install "{EXAMPLE_PACKAGE}"').check_returncode()
     self._patch_argv(monkeypatch, ['env-modules'])
     npmenv._cli()
     assert 'to-no-case' in capfd.readouterr().out
     self._patch_argv(monkeypatch, ['env-modules', 'to-no-case'])
     npmenv._cli()
     assert 'index.js' in capfd.readouterr().out
Ejemplo n.º 3
0
 def test_env_list(self, sandbox, monkeypatch, capfd):
     # Trigger env creation
     npmenv.env_npm()
     capfd.readouterr()
     # Test
     self._patch_argv(monkeypatch, ['env-list'])
     npmenv._cli()
     assert str(sandbox['proj_dir']) in capfd.readouterr().out
Ejemplo n.º 4
0
 def test_env_rm(self, monkeypatch):
     # Confirm exit if removing env that doesn't exist (also test arg taking)
     self._patch_argv(monkeypatch, ['env-rm', '/tmp/fake'])
     with pytest.raises(SystemExit):
         npmenv._cli()
     # Confirm no exit if removing env dir that does exist (also test no arg)
     npmenv.env_npm()
     self._patch_argv(monkeypatch, ['env-rm'])
     npmenv._cli()
Ejemplo n.º 5
0
 def test_only_package(self, insert_project_files):
     """ `env_npm` should use existing package file """
     sandbox = insert_project_files(package=True)
     npmenv.env_npm('install').check_returncode()
     # Confirm original file not modified
     assert json.loads(sandbox['proj_package'].read_text()) == json.loads(PACKAGE_JSON)
     # Confirm links created
     assert sandbox['env_package'].resolve(strict=True) == sandbox['proj_package']
     assert sandbox['env_lock'].resolve(strict=True) == sandbox['proj_lock']
     # Confirm module installed
     assert sandbox['env_module'].is_dir()
Ejemplo n.º 6
0
 def test_env_cleanup(self, monkeypatch, sandbox, insert_project_files, tmpdir, capfd):
     # Test two projects, only one having config files
     proj1 = str(sandbox['proj_dir'])
     proj2 = str(tmpdir)
     insert_project_files(package=True)  # Into proj1 (sandbox)
     npmenv.env_npm(proj_dir=proj1)
     npmenv.env_npm(proj_dir=proj2)
     self._patch_argv(monkeypatch, ['env-cleanup'])
     npmenv._cli()
     stdout = capfd.readouterr().out
     assert proj1 not in stdout
     assert proj2 in stdout
Ejemplo n.º 7
0
def test_env_run(sandbox, capfd):
    # Confirm exception if no bin dir
    with pytest.raises(npmenv.NpmenvException):
        npmenv.env_run('username --help')
    npmenv.env_npm()
    with pytest.raises(npmenv.NpmenvException):
        npmenv.env_run('username --help')
    # Confirm runs executable from .bin dir
    # Install a tiny CLI program that shouldn't exist on system yet
    npmenv.env_npm(f'install "{EXAMPLE_PACKAGE_WITH_SCRIPT}"').check_returncode()
    capfd.readouterr()
    npmenv.env_run('username --help').check_returncode()
    assert 'sindresorhus' in capfd.readouterr().out
Ejemplo n.º 8
0
 def test_unlink(self, insert_project_files):
     """ `env_npm` should remove links to files that don't exist anymore """
     sandbox = insert_project_files(package=True, lock=True)
     # Trigger linking
     npmenv.env_npm()
     assert sandbox['env_package'].is_symlink()
     assert sandbox['env_lock'].is_symlink()
     # Remove originals
     sandbox['proj_package'].unlink()
     sandbox['proj_lock'].unlink()
     # Confirm links removed
     npmenv.env_npm()
     assert not sandbox['env_package'].is_symlink()
     assert not sandbox['env_lock'].is_symlink()
Ejemplo n.º 9
0
def test_env_cleanup(sandbox, insert_project_files, tmpdir_factory):
    # Put lock file in sandbox project
    insert_project_files(lock=True)
    npmenv.env_npm()

    # Create additional project with no config
    npmenv.env_npm(proj_dir=str(tmpdir_factory.mktemp('npmenv_test_project')))

    # Create additional project and then delete
    proj3 = Path(str(tmpdir_factory.mktemp('npmenv_test_project')))
    npmenv.env_npm(proj_dir=proj3)
    proj3.rmdir()

    # Confirm issues
    issues = set([env[2] for env in npmenv.env_list()])
    assert issues == set([None, 'missing', 'no_config'])

    # Remove envs with issues
    removed = npmenv.env_cleanup()

    # Confirm only removed envs with issues
    assert len(removed) == 2
    assert None not in (env[2] for env in removed)
Ejemplo n.º 10
0
 def rm_with_checks(*args):
     assert not npmenv.env_list()
     npmenv.env_npm()
     assert npmenv.env_list()
     npmenv.env_rm(*args)
     assert not npmenv.env_list()
Ejemplo n.º 11
0
 def test_no_files_install(self, sandbox):
     """ `env_npm` should transfer new lock file created by npm install """
     npmenv.env_npm(f'install "{EXAMPLE_PACKAGE}"').check_returncode()
     assert sandbox['env_lock'].resolve(strict=True) == sandbox['proj_lock']
     assert sandbox['env_module'].is_dir()
Ejemplo n.º 12
0
 def test_no_files_init(self, sandbox):
     """ `env_npm` should transfer new package file created by npm init """
     npmenv.env_npm('init --yes').check_returncode()
     assert sandbox['env_package'].resolve(strict=True) == sandbox['proj_package']
     assert not sandbox['env_lock'].is_symlink()
Ejemplo n.º 13
0
 def test_env_run(self, monkeypatch):
     npmenv.env_npm(f'install "{EXAMPLE_PACKAGE_WITH_SCRIPT}"').check_returncode()
     self._patch_argv(monkeypatch, ['env-run', 'username', '--help'])
     with assert_exit_with_success(True):
         npmenv._cli()