Beispiel #1
0
 def test_args(self, monkeypatch):
     # Confirm failure when wrong amount of args
     wrong = [['env-list', 0], ['env-location', 0], ['env-modules', 0, 0], ['env-run'],
         ['env-rm', 0, 0]]
     for args in wrong:
         self._patch_argv(monkeypatch, args)
         with pytest.raises(SystemExit):
             npmenv._cli()
Beispiel #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
Beispiel #3
0
 def test_npm(self, monkeypatch, capfd):
     # Confirm calls npm and adds own help info to npm's
     self._patch_argv(monkeypatch, ['help'])
     with assert_exit_with_success(True):
         npmenv._cli()
     stdout = capfd.readouterr().out
     assert 'npmenv' in stdout  # Own help text
     assert 'publish' in stdout  # npm's help text
Beispiel #4
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
Beispiel #5
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()
Beispiel #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
Beispiel #7
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()
Beispiel #8
0
 def test_env_location(self, monkeypatch, sandbox, capfd):
     self._patch_argv(monkeypatch, ['env-location'])
     npmenv._cli()
     assert str(sandbox['env_dir']) == capfd.readouterr().out