def test_make_argument_parser(require_src, expect): """Parser from ``make_argument_parser()`` fails if src required but not provided""" parser = make_argument_parser(require_src) with raises_if_exception(expect): args = parser.parse_args([]) assert args.src == expect
def test_fill_line(line, width, indent, expect): """``_fill_line()`` wraps lines correctly""" with raises_if_exception(expect): result = argparse_helpers._fill_line( # pylint: disable=protected-access line, width, indent) assert result.splitlines() == expect
def test_revisionrange_parse_pre_commit(environ, expect): """RevisionRange.parse(':PRE-COMMIT:') gets the range from environment variables""" with patch.dict(os.environ, environ), raises_if_exception(expect): result = RevisionRange.parse(":PRE-COMMIT:") expect_rev1, expect_rev2 = expect assert result.rev1 == expect_rev1 assert result.rev2 == expect_rev2 assert result.use_common_ancestor
def test_revision(git_repo, monkeypatch, capsys, revision, worktree_content, expect): monkeypatch.chdir(git_repo.root) # 2: HEAD~2: paths = git_repo.add( { "+2.py": "ORIGINAL=1\n", "+2M1.py": "ORIGINAL=1\n", "+2-1.py": "ORIGINAL=1\n", "+2M1-0.py": "ORIGINAL=1\n", }, commit="First commit", ) # 1: HEAD~1 i.e. HEAD^ paths.update( git_repo.add( { "+2M1.py": "MODIFIED=1\n", "+1.py": "ORIGINAL=1\n", "+1M0.py": "ORIGINAL=1\n", "+2-1.py": None, "+2M1-0.py": "MODIFIED=1\n", }, commit="Second commit", )) # 0: HEAD~0 i.e. HEAD: git_repo.add( { "+1M0.py": "MODIFIED=1\n", "+2M1-0.py": None }, commit="Third commit", ) # Working tree: for path in paths.values(): path.write_bytes(worktree_content) arguments = ["--diff", "--revision", revision, "."] with raises_if_exception(expect): main(arguments) modified_files = [ line[4:-3] for line in capsys.readouterr().out.splitlines() if line.startswith("+++ ") ] assert modified_files == expect
def test_parse_command_line_config_src( tmpdir, monkeypatch, config, argv, expect, ): """The ``src`` positional argument from config and cmdline is handled correctly""" monkeypatch.chdir(tmpdir) if config is not None: toml.dump({"tool": {"darker": config}}, tmpdir / "pyproject.toml") with raises_if_exception(expect): args, effective_cfg, modified_cfg = parse_command_line(argv) assert filter_dict(args.__dict__, "src") == expect assert filter_dict(effective_cfg, "src") == expect assert filter_dict(modified_cfg, "src") == expect