def test_show_with_check(self): with tempfile.TemporaryDirectory() as tmp_dir: sys.argv = ["git_workon", "show", "-d", tmp_dir] cli.main() self.mc_show.assert_called_once_with(check_status=True)
def test_command_error(self): self.mc_clone.side_effect = git.CommandError("Oops") with tempfile.TemporaryDirectory() as tmp_dir: sys.argv = ["git_workon", "start", "my_project", "-d", tmp_dir, "-s", "any"] with pytest.raises(SystemExit) as exc: cli.main() assert int(str(exc.value)) == 1
def test_parse_args_command_no_args(self): sys.argv = ["git_workon", "start", "my_project"] with pytest.raises(SystemExit) as exc: cli.main() assert int(str(exc.value)) == 2 sys.argv = ["git_workon", "done"] with pytest.raises(SystemExit) as exc: cli.main() assert int(str(exc.value)) == 2
def test_user_config_sources_used(self): with tempfile.TemporaryDirectory() as tmp_dir: sys.argv = [ "git_workon", "start", "my_project", "-d", tmp_dir, ] cli.main() self.mc_clone.assert_called_once_with("my_project", ["third", "fourth"])
def test_all_projects(self): with tempfile.TemporaryDirectory() as tmp_dir: sys.argv = [ "git_workon", "done", "-d", tmp_dir, ] cli.main() assert not self.mc_clone.called assert not self.mc_open.called self.mc_remove.assert_called_once_with(None, False)
def test_one_project_name_stripped(self): with tempfile.TemporaryDirectory() as tmp_dir: sys.argv = [ "git_workon", "done", "my_project/", "-d", tmp_dir, ] cli.main() assert not self.mc_clone.called assert not self.mc_open.called self.mc_remove.assert_called_once_with("my_project", False)
def test_cloned_and_opened(self): with tempfile.TemporaryDirectory() as tmp_dir: sys.argv = [ "git_workon", "start", "my_project", "-d", tmp_dir, "-s", "any", ] cli.main() self.mc_clone.assert_called_once_with("my_project", ["any"]) self.mc_open.assert_called_once_with("my_project", None)
def test_already_cloned_opened(self): with tempfile.TemporaryDirectory() as tmp_dir: project_name = os.path.basename(tempfile.mkdtemp(dir=tmp_dir)) sys.argv = [ "git_workon", "start", os.path.basename(project_name), "-d", tmp_dir, "-s", "any", ] cli.main() assert not self.mc_clone.called self.mc_open.assert_called_once_with(os.path.basename(project_name), None)
def test_no_args(self): sys.argv = ["git_workon"] with pytest.raises(SystemExit): cli.main()
def test_dir_is_not_specified_exit(self): sys.argv = ["git_workon", "show"] with pytest.raises(SystemExit) as exc: cli.main() assert int(str(exc.value)) == 2
def test_initialize(self, mc_init_config, mc_load_config): sys.argv = ["git_workon", "config"] cli.main() mc_init_config.assert_called_once_with() assert mc_load_config.call_count == 2
def test_source_not_defined_exception_raised(self): with tempfile.TemporaryDirectory() as tmp_dir: sys.argv = ["git_workon", "start", "my_project", "-d", tmp_dir] with pytest.raises(SystemExit) as exc: cli.main() assert int(str(exc.value)) == 2