コード例 #1
0
def test_obtain_branches_to_delete(mock_stash_api, github_api, branch_name,
                                   expected_message, success):
    branches_to_delete = list()
    stash_api = StashAPI("https://myserver.com/stash",
                         username="******",
                         password="******")
    lines = list(
        obtain_branches_to_delete(
            stash_api,
            github_api,
            ["PROJ-A", "PROJ-B"],
            ["esss"],
            branch_name,
            branches_to_delete,
        ))

    from _pytest.pytester import LineMatcher

    matcher = LineMatcher(sorted(lines))

    if success:
        matching_lines = [
            f"Found branch `{branch_name}` in these repositories:"
        ]
        matching_lines.extend(expected_message)
        matching_lines.append(r"*To confirm, please repeat the command*")
        assert len(branches_to_delete) == len(expected_message)
    else:
        matching_lines = expected_message
    matcher.re_match_lines(sorted(matching_lines))
コード例 #2
0
ファイル: test_pytester.py プロジェクト: swetaj6/pytest
def test_linematcher_match_failure() -> None:
    lm = LineMatcher(["foo", "foo", "bar"])
    with pytest.raises(Failed) as e:
        lm.fnmatch_lines(["foo", "f*", "baz"])
    assert e.value.msg is not None
    assert e.value.msg.splitlines() == [
        "exact match: 'foo'",
        "fnmatch: 'f*'",
        "   with: 'foo'",
        "nomatch: 'baz'",
        "    and: 'bar'",
        "remains unmatched: 'baz'",
    ]

    lm = LineMatcher(["foo", "foo", "bar"])
    with pytest.raises(Failed) as e:
        lm.re_match_lines(["foo", "^f.*", "baz"])
    assert e.value.msg is not None
    assert e.value.msg.splitlines() == [
        "exact match: 'foo'",
        "re.match: '^f.*'",
        "    with: 'foo'",
        " nomatch: 'baz'",
        "     and: 'bar'",
        "remains unmatched: 'baz'",
    ]
コード例 #3
0
def call_merge(branch_text,
               matching_lines,
               *,
               force=False,
               github_organizations=None):
    try:
        lines = list(
            merge(
                "https://myserver.com/stash",
                ["PROJ-A", "PROJ-B"],
                stash_username="******",
                stash_password="******",
                github_username_or_token="",
                github_password="",
                github_organizations=list()
                if github_organizations is None else github_organizations,
                branch_text=branch_text,
                confirm=True,
                force=force,
            ))
    except CheckError as e:
        lines = list(e.lines)
    from _pytest.pytester import LineMatcher

    matcher = LineMatcher(sorted(lines))
    matcher.re_match_lines(sorted(matching_lines))
コード例 #4
0
def call_merge(branch_text, matching_lines):
    try:
        lines = list(merge('https://myserver.com/stash', ['PROJ-A', 'PROJ-B'], username='******', password='******',
                           branch_text=branch_text, confirm=True))
    except CheckError as e:
        lines = e.lines
    from _pytest.pytester import LineMatcher
    matcher = LineMatcher(list(lines))
    matcher.re_match_lines(matching_lines)
コード例 #5
0
ファイル: test_pytester.py プロジェクト: vestigegroup/pytest
def test_linematcher_consecutive():
    lm = LineMatcher(["1", "", "2"])
    with pytest.raises(pytest.fail.Exception) as excinfo:
        lm.fnmatch_lines(["1", "2"], consecutive=True)
    assert str(excinfo.value).splitlines() == [
        "exact match: '1'",
        "no consecutive match: '2'",
        "   with: ''",
    ]

    lm.re_match_lines(["1", r"\d?", "2"], consecutive=True)
    with pytest.raises(pytest.fail.Exception) as excinfo:
        lm.re_match_lines(["1", r"\d", "2"], consecutive=True)
    assert str(excinfo.value).splitlines() == [
        "exact match: '1'",
        r"no consecutive match: '\\d'",
        "    with: ''",
    ]
コード例 #6
0
def test_linematcher_with_nonlist() -> None:
    """Test LineMatcher with regard to passing in a set (accidentally)."""
    from _pytest._code.source import Source

    lm = LineMatcher([])
    with pytest.raises(TypeError, match="invalid type for lines2: set"):
        lm.fnmatch_lines(set())  # type: ignore[arg-type]
    with pytest.raises(TypeError, match="invalid type for lines2: dict"):
        lm.fnmatch_lines({})  # type: ignore[arg-type]
    with pytest.raises(TypeError, match="invalid type for lines2: set"):
        lm.re_match_lines(set())  # type: ignore[arg-type]
    with pytest.raises(TypeError, match="invalid type for lines2: dict"):
        lm.re_match_lines({})  # type: ignore[arg-type]
    with pytest.raises(TypeError, match="invalid type for lines2: Source"):
        lm.fnmatch_lines(Source())  # type: ignore[arg-type]
    lm.fnmatch_lines([])
    lm.fnmatch_lines(())
    lm.fnmatch_lines("")
    assert lm._getlines({}) == {}  # type: ignore[arg-type,comparison-overlap]
    assert lm._getlines(set()) == set()  # type: ignore[arg-type,comparison-overlap]
    assert lm._getlines(Source()) == []
    assert lm._getlines(Source("pass\npass")) == ["pass", "pass"]
コード例 #7
0
def test_delete_branches(mock_stash_api, github_api, branch_name,
                         expected_message):
    stash_api = StashAPI("https://myserver.com/stash",
                         username="******",
                         password="******")
    branches_to_delete = create_plans(
        stash_api,
        github_api,
        ["PROJ-A", "PROJ-B"],
        ["esss"],
        branch_name,
        exactly_branch_name=True,
        assure_has_prs=False,
    )
    lines = list(delete_branches(stash_api, github_api, branches_to_delete))

    from _pytest.pytester import LineMatcher

    matcher = LineMatcher(sorted(lines))
    matching_lines = [f"Deleting Branches `{branch_name}`:"]
    matching_lines.extend(expected_message)
    matcher.re_match_lines(sorted(matching_lines))