Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
 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
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
0
 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"])
Ejemplo n.º 5
0
    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)
Ejemplo n.º 6
0
    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)
Ejemplo n.º 7
0
    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)
Ejemplo n.º 8
0
    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)
Ejemplo n.º 9
0
 def test_no_args(self):
     sys.argv = ["git_workon"]
     with pytest.raises(SystemExit):
         cli.main()
Ejemplo n.º 10
0
    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
Ejemplo n.º 11
0
    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
Ejemplo n.º 12
0
 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