Exemple #1
0
def test_flake8_checks(mock_config, mock_revision, mock_hgmo, mock_task):
    """
    Check flake8 check detection
    """

    # Valid issue
    issue = MozLintIssue(
        mock_task(MozLintTask, "mock-lint-flake8"),
        "test.py",
        1,
        "error",
        1,
        "flake8",
        "Dummy test",
        "dummy rule",
        mock_revision,
    )
    assert not issue.is_disabled_check()
    assert issue.validates()

    # Flake8 bad quotes
    issue = MozLintIssue(
        mock_task(MozLintTask, "mock-lint-flake8"),
        "test.py",
        1,
        "error",
        1,
        "flake8",
        "Remove bad quotes or whatever.",
        "Q000",
        mock_revision,
    )
    assert issue.is_disabled_check()
    assert not issue.validates()

    assert issue.as_dict() == {
        "analyzer": "mock-lint-flake8",
        "check": "Q000",
        "column": 1,
        "in_patch": False,
        "level": "error",
        "line": 1,
        "message": "Remove bad quotes or whatever.",
        "nb_lines": 1,
        "path": "test.py",
        "publishable": False,
        "validates": False,
        "hash": "28e40e8a562fa8ebea98f984abd503fd",
        "fix": None,
    }
Exemple #2
0
def test_flake8_checks(mock_config, mock_revision, mock_hgmo):
    """
    Check flake8 check detection
    """

    # Valid issue
    issue = MozLintIssue(
        "mock-lint-flake8",
        "test.py",
        1,
        "error",
        1,
        "flake8",
        "Dummy test",
        "dummy rule",
        mock_revision,
    )
    assert not issue.is_disabled_check()
    assert issue.validates()

    # Flake8 bad quotes
    issue = MozLintIssue(
        "mock-lint-flake8",
        "test.py",
        1,
        "error",
        1,
        "flake8",
        "Remove bad quotes or whatever.",
        "Q000",
        mock_revision,
    )
    assert issue.is_disabled_check()
    assert not issue.validates()

    assert issue.as_dict() == {
        "analyzer": "mock-lint-flake8",
        "check": "Q000",
        "column": 1,
        "in_patch": False,
        "level": "error",
        "line": 1,
        "message": "Remove bad quotes or whatever.",
        "nb_lines": 1,
        "path": "test.py",
        "publishable": False,
        "validates": False,
        "hash": "57a49008d6a3ec23f987c0bf62c43d75",
    }
Exemple #3
0
def test_as_text(mock_config, mock_revision, mock_hgmo, mock_task):
    """
    Test text export for ClangTidyIssue
    """

    issue = MozLintIssue(
        mock_task(MozLintTask, "mock-lint-flake8"),
        "test.py",
        1,
        "error",
        1,
        "flake8",
        "dummy test withUppercaseChars",
        "dummy rule",
        mock_revision,
    )

    assert (issue.as_text() ==
            "Error: Dummy test withUppercaseChars [flake8: dummy rule]")

    assert issue.as_phabricator_lint() == {
        "char": 1,
        "code": "dummy rule",
        "line": 1,
        "name": "mock-lint-flake8",
        "description": "(IMPORTANT) ERROR: dummy test withUppercaseChars",
        "path": "test.py",
        "severity": "error",
    }

    assert issue.as_dict() == {
        "analyzer": "mock-lint-flake8",
        "check": "dummy rule",
        "column": 1,
        "in_patch": False,
        "level": "error",
        "line": 1,
        "message": "dummy test withUppercaseChars",
        "nb_lines": 1,
        "path": "test.py",
        "publishable": True,
        "validates": True,
        "hash": "f8d818d42677f3ffdc0be647453278b8",
        "fix": None,
    }
Exemple #4
0
def test_as_text(mock_config, mock_revision, mock_hgmo):
    """
    Test text export for ClangTidyIssue
    """

    issue = MozLintIssue(
        "mock-lint-flake8",
        "test.py",
        1,
        "error",
        1,
        "flake8",
        "dummy test withUppercaseChars",
        "dummy rule",
        mock_revision,
    )

    assert (issue.as_text() ==
            "Error: Dummy test withUppercaseChars [flake8: dummy rule]")

    assert issue.as_phabricator_lint() == {
        "char": 1,
        "code": "dummy rule",
        "line": 1,
        "name": "mock-lint-flake8",
        "description": "dummy test withUppercaseChars",
        "path": "test.py",
        "severity": "error",
    }

    assert issue.as_dict() == {
        "analyzer": "mock-lint-flake8",
        "check": "dummy rule",
        "column": 1,
        "in_patch": False,
        "level": "error",
        "line": 1,
        "message": "dummy test withUppercaseChars",
        "nb_lines": 1,
        "path": "test.py",
        "publishable": True,
        "validates": True,
        "hash": "34c27d119c21ea5a2cd3f6ac230d8c4e",
    }
Exemple #5
0
def test_full_file(mock_revision, mock_hgmo, mock_task):
    """
    Test build hash algorithm when using a full file (line is -1)
    """
    # Hardcode revision & repo
    mock_revision.repository = "test-try"
    mock_revision.mercurial_revision = "deadbeef1234"

    issue = MozLintIssue(
        mock_task(MozLintTask, "mock-analyzer-fullfile"),
        "path/to/afile.py",
        0,
        "error",
        -1,
        "fullfile",
        "Some issue found on a file",
        "EXXX",
        mock_revision,
    )
    assert (
        str(issue) ==
        "mock-analyzer-fullfile issue EXXX@error path/to/afile.py full file")
    assert issue.line is None

    # Build hash should use the full file
    assert issue.build_hash() == "76a76ba6e023d933acba9e07ae2897f6"

    # Check positive integers or None are used in report
    assert issue.as_dict() == {
        "analyzer": "mock-analyzer-fullfile",
        "check": "EXXX",
        "column": 0,
        "hash": "76a76ba6e023d933acba9e07ae2897f6",
        "in_patch": False,
        "level": "error",
        "line": None,
        "message": "Some issue found on a file",
        "nb_lines": 1,
        "path": "path/to/afile.py",
        "publishable": True,
        "validates": True,
        "fix": None,
    }