Ejemplo n.º 1
0
    def test_with_option_dryrun_on_cmdline(self, capsys):
        config = Config(DEFAULT_CONFIG)
        ctx = EchoMockContext(run=Result(), config=config)

        git_clean(ctx, dry_run=True)
        captured = capsys.readouterr()
        expected = "INVOKED: git clean --interactive --dry-run ."
        assert expected in captured.out
Ejemplo n.º 2
0
    def test_with_invoke_option_dry_on_cmdline(self, capsys):
        config = Config(DEFAULT_CONFIG)
        ctx = EchoMockContext(run=Result(), config=config)
        ctx.config.run.dry = True  # CMDLINE-EMULATION

        git_clean(ctx)
        captured = capsys.readouterr()
        expected = "INVOKED: git clean --interactive --dry-run ."
        assert expected in captured.out
Ejemplo n.º 3
0
    def test_with_option_force_on_cmdline(self, capsys):
        config = Config(DEFAULT_CONFIG)
        ctx = EchoMockContext(run=Result(), config=config)
        # ctx.config.git_clean.interactive = False

        git_clean(ctx, force=True)
        captured = capsys.readouterr()
        expected = "INVOKED: git clean --interactive --force ."
        assert expected in captured.out
Ejemplo n.º 4
0
    def test_without_options_if_config_disables_interactive_mode(self, capsys):
        config = Config(DEFAULT_CONFIG)
        ctx = EchoMockContext(run=Result(), config=config)
        ctx.config.git_clean.interactive = False

        git_clean(ctx)
        captured = capsys.readouterr()
        expected = "INVOKED: git clean  ."
        assert expected in captured.out
Ejemplo n.º 5
0
    def test_with_option_dryrun_in_configfile(self, capsys):
        config = Config(DEFAULT_CONFIG)
        ctx = EchoMockContext(run=Result(), config=config)
        # ctx.config.git_clean.interactive = False
        ctx.config.git_clean.dry_run = True

        git_clean(ctx)
        captured = capsys.readouterr()
        expected = "INVOKED: git clean --interactive --dry-run ."
        assert expected in captured.out
Ejemplo n.º 6
0
    def test_removes_uncommitted_files(self, mode, tmp_path, capsys,
                                       monkeypatch):
        # -- SETUP:
        setup_workdir(tmp_path, [
            "one.xxx",
            "two.xxx",
        ])
        my_file1 = tmp_path / "one.xxx"
        my_file2 = tmp_path / "two.xxx"
        assert my_file1.exists() and my_file1.is_file()
        assert my_file2.exists() and my_file2.is_file()

        # -- EXECUTE AND VERIFY:
        Path = tmp_path.__class__
        git_clean_dry_run = (mode == "dry_run")
        curdir = Path(".").resolve()
        with cd(str(tmp_path)):
            work_dir = Path(".").resolve()
            not_in_curdir = not tmp_path.samefile(curdir)
            print("WORK_DIR: %s (work_dir is not CURDIR: %s)" %
                  (work_dir, not_in_curdir))
            assert not_in_curdir, "DANGER_ZONE.SANITY_CHECK_BARRIER.saved_you"

            # with capsys.disabled():
            run("git init")
            git_dir = tmp_path / ".git/"
            assert git_dir.is_dir()
            run('git add one.xxx')
            run('git commit -m"INITIAL" one.xxx')
            run("git status")

            config = Config(DEFAULT_CONFIG)
            ctx = Context(config=config)
            ctx.config.run.dry = False
            ctx.config.git_clean.interactive = False
            monkeypatch.setattr("_pytest.capture.DontReadFromInput.read",
                                mock_read_from_stdin)
            git_clean(ctx, force=True, dry_run=git_clean_dry_run)

        assert my_file1.exists(), "OOPS: my_file1 was REMOVED"
        if git_clean_dry_run:
            # -- DRY-RUN MODE:
            captured = capsys.readouterr()
            assert "Would remove two.xxx" in captured.out
            assert my_file2.exists(), "OOPS: my_file2 was REMOVED"
        else:
            assert not my_file2.exists(), "OOPS: my_file2 was NOT_REMOVED"