Ejemplo n.º 1
0
def test_ignore_glob(caplog):
    # Lint two files in the ref/ directory, and pass in ignore_glob to omit one
    # of them.
    # When we omit absolute.html, no lint errors appear since the other file is
    # clean.
    with _mock_lint("check_path") as mocked_check_path:
        with _mock_lint("check_file_contents") as mocked_check_file_contents:
            rv = lint(_dummy_repo, [
                "broken.html", "ref/absolute.html",
                "ref/existent_relative.html"
            ], "normal", ["broken*", "*solu*"])
            assert rv == 0
            # Also confirm that only one file is checked
            assert mocked_check_path.call_count == 1
            assert mocked_check_file_contents.call_count == 1
            assert caplog.text == ""
    # However, linting the same two files without ignore_glob yields lint errors.
    with _mock_lint("check_path") as mocked_check_path:
        with _mock_lint("check_file_contents") as mocked_check_file_contents:
            rv = lint(_dummy_repo, [
                "broken.html", "ref/absolute.html",
                "ref/existent_relative.html"
            ], "normal")
            assert rv == 2
            assert mocked_check_path.call_count == 3
            assert mocked_check_file_contents.call_count == 3
            assert "TRAILING WHITESPACE" in caplog.text
            assert "ABSOLUTE-URL-REF" in caplog.text
Ejemplo n.º 2
0
def check_wpt_lint_errors(files):
    wpt_working_dir = os.path.abspath(os.path.join(".", "tests", "wpt", "web-platform-tests"))
    site.addsitedir(wpt_working_dir)
    from tools.lint import lint
    returncode = lint.lint(files)
    if returncode:
        yield ("WPT Lint Tool", "", "lint error(s) in Web Platform Tests: exit status {0}".format(returncode))
Ejemplo n.º 3
0
def test_about_blank_as_ref(caplog):
    with _mock_lint("check_path"):
        with _mock_lint("check_file_contents") as mocked_check_file_contents:
            rv = lint(_dummy_repo, ["about_blank.html"], "normal")
            assert rv == 0
            assert mocked_check_file_contents.call_count == 1
    assert caplog.text == ""
Ejemplo n.º 4
0
def check_wpt_lint_errors(files):
    wpt_working_dir = os.path.abspath(os.path.join(".", "tests", "wpt", "web-platform-tests"))
    site.addsitedir(wpt_working_dir)
    from tools.lint import lint
    returncode = lint.lint(files)
    if returncode:
        yield ("WPT Lint Tool", "", "lint error(s) in Web Platform Tests: exit status {0}".format(returncode))
Ejemplo n.º 5
0
def test_css_manual_path_testharness(caplog):
    rv = lint(_dummy_repo,
              ["css/css-unique/relative-testharness-interact.html"], "normal")
    assert rv == 3
    assert "CONTENT-MANUAL" in caplog.text
    assert "TESTHARNESS-PATH" in caplog.text
    assert "TESTHARNESSREPORT-PATH" in caplog.text
Ejemplo n.º 6
0
def test_check_css_globally_unique_ignored_dir(caplog):
    with _mock_lint("check_path") as mocked_check_path:
        with _mock_lint("check_file_contents") as mocked_check_file_contents:
            rv = lint(_dummy_repo, ["css/css-unique/support/a.html"], "normal")
            assert rv == 0
            assert mocked_check_path.call_count == 1
            assert mocked_check_file_contents.call_count == 1
    assert caplog.text == ""
Ejemplo n.º 7
0
def test_ref_existent_relative(caplog):
    with _mock_lint("check_path") as mocked_check_path:
        with _mock_lint("check_file_contents") as mocked_check_file_contents:
            rv = lint(_dummy_repo, ["ref/existent_relative.html"], "normal")
            assert rv == 0
            assert mocked_check_path.call_count == 1
            assert mocked_check_file_contents.call_count == 1
    assert caplog.text == ""
Ejemplo n.º 8
0
def test_lint_passing(caplog):
    with _mock_lint("check_path") as mocked_check_path:
        with _mock_lint("check_file_contents") as mocked_check_file_contents:
            rv = lint(_dummy_repo, ["okay.html"], "normal")
            assert rv == 0
            assert mocked_check_path.call_count == 1
            assert mocked_check_file_contents.call_count == 1
    assert caplog.text == ""
Ejemplo n.º 9
0
def test_lint_ignored_file(caplog):
    with _mock_lint("check_path") as mocked_check_path:
        with _mock_lint("check_file_contents") as mocked_check_file_contents:
            rv = lint(_dummy_repo, ["broken_ignored.html"], "normal")
            assert rv == 0
            assert not mocked_check_path.called
            assert not mocked_check_file_contents.called
    assert caplog.text == ""
Ejemplo n.º 10
0
def test_lint_failing(caplog):
    with _mock_lint("check_path") as mocked_check_path:
        with _mock_lint("check_file_contents") as mocked_check_file_contents:
            rv = lint(_dummy_repo, ["broken.html"], "normal")
            assert rv == 1
            assert mocked_check_path.call_count == 1
            assert mocked_check_file_contents.call_count == 1
    assert "TRAILING WHITESPACE" in caplog.text
    assert "broken.html:1" in caplog.text
Ejemplo n.º 11
0
def test_ref_same_file_path(caplog):
    with _mock_lint("check_path") as mocked_check_path:
        with _mock_lint("check_file_contents") as mocked_check_file_contents:
            rv = lint(_dummy_repo, ["ref/same_file_path.html"], "normal")
            assert rv == 1
            assert mocked_check_path.call_count == 1
            assert mocked_check_file_contents.call_count == 1
    assert "SAME-FILE-REF" in caplog.text
    assert "same_file_path.html" in caplog.text
Ejemplo n.º 12
0
def test_ref_absolute_url(caplog):
    with _mock_lint("check_path") as mocked_check_path:
        with _mock_lint("check_file_contents") as mocked_check_file_contents:
            rv = lint(_dummy_repo, ["ref/absolute.html"], "normal")
            assert rv == 1
            assert mocked_check_path.call_count == 1
            assert mocked_check_file_contents.call_count == 1
    assert "ABSOLUTE-URL-REF" in caplog.text
    assert "http://example.com/reference.html" in caplog.text
    assert "ref/absolute.html" in caplog.text
Ejemplo n.º 13
0
def test_lint_not_existing_file(caplog):
    with _mock_lint("check_path") as mocked_check_path:
        with _mock_lint("check_file_contents") as mocked_check_file_contents:
            # really long path-linted filename
            name = "a" * 256 + ".html"
            rv = lint(_dummy_repo, [name], "normal")
            assert rv == 0
            assert not mocked_check_path.called
            assert not mocked_check_file_contents.called
    assert caplog.text == ""
Ejemplo n.º 14
0
 def run(self):
     wpt_working_dir = os.path.abspath(os.path.join(WPT_PATH, "web-platform-tests"))
     for suite in SUITES:
         files = self._get_wpt_files(suite)
         site.addsitedir(wpt_working_dir)
         from tools.lint import lint
         file_dir = os.path.abspath(os.path.join(WPT_PATH, suite))
         returncode = lint.lint(file_dir, files, output_json=False)
         if returncode:
             yield ("WPT Lint Tool", "", "lint error(s) in Web Platform Tests: exit status %s" % returncode)
Ejemplo n.º 15
0
def test_check_css_globally_unique_ref_identical(caplog):
    with _mock_lint("check_path") as mocked_check_path:
        with _mock_lint("check_file_contents") as mocked_check_file_contents:
            rv = lint(_dummy_repo, [
                "css/css-unique/a-ref.html", "css/css-unique/match/a-ref.html"
            ], "normal")
            assert rv == 0
            assert mocked_check_path.call_count == 2
            assert mocked_check_file_contents.call_count == 2
    assert caplog.text == ""
Ejemplo n.º 16
0
def test_ref_non_existent_root_relative(caplog):
    with _mock_lint("check_path") as mocked_check_path:
        with _mock_lint("check_file_contents") as mocked_check_file_contents:
            rv = lint(_dummy_repo, ["ref/non_existent_root_relative.html"],
                      "normal")
            assert rv == 1
            assert mocked_check_path.call_count == 1
            assert mocked_check_file_contents.call_count == 1
    assert "NON-EXISTENT-REF" in caplog.text
    assert "ref/non_existent_root_relative.html" in caplog.text
    assert "/non_existent_file.html" in caplog.text
Ejemplo n.º 17
0
def test_check_css_globally_unique_ref_different(caplog):
    with _mock_lint("check_path") as mocked_check_path:
        with _mock_lint("check_file_contents") as mocked_check_file_contents:
            rv = lint(_dummy_repo, [
                "css/css-unique/not-match/a-ref.html",
                "css/css-unique/a-ref.html"
            ], "normal")
            assert rv == 2
            assert mocked_check_path.call_count == 2
            assert mocked_check_file_contents.call_count == 2
    assert "CSS-COLLIDING-REF-NAME" in caplog.text
Ejemplo n.º 18
0
def test_check_css_globally_unique_different_spec_test(caplog):
    with _mock_lint("check_path") as mocked_check_path:
        with _mock_lint("check_file_contents") as mocked_check_file_contents:
            rv = lint(
                _dummy_repo,
                ["css/css-unique/selectors/a.html", "css/css-unique/a.html"],
                "normal")
            assert rv == 0
            assert mocked_check_path.call_count == 2
            assert mocked_check_file_contents.call_count == 2
    assert caplog.text == ""
Ejemplo n.º 19
0
def test_check_unique_testharness_basename_not_testharness(caplog):
    # Precondition: There are non-testharness files with conflicting basename paths.
    assert os.path.exists(os.path.join(_dummy_repo, 'tests', 'dir1', 'a.html'))
    assert os.path.exists(os.path.join(_dummy_repo, 'tests', 'dir1', 'a.js'))

    with _mock_lint("check_path") as mocked_check_path:
        with _mock_lint("check_file_contents") as mocked_check_file_contents:
            rv = lint(_dummy_repo, ["tests/dir1/a.html", "tests/dir1/a.js"],
                      "normal")
            assert rv == 0
            assert mocked_check_path.call_count == 2
            assert mocked_check_file_contents.call_count == 2
    assert caplog.text == ""
Ejemplo n.º 20
0
    def run(self):
        if self.stylo:
            return

        wpt_working_dir = os.path.abspath(os.path.join(WPT_PATH, "web-platform-tests"))
        for suite in SUITES:
            files = self._get_wpt_files(suite)
            sys.path.insert(0, wpt_working_dir)
            from tools.lint import lint
            sys.path.remove(wpt_working_dir)
            file_dir = os.path.abspath(os.path.join(WPT_PATH, suite))
            returncode = lint.lint(file_dir, list(files), output_format="json", css_mode=False)
            if returncode:
                yield ("WPT Lint Tool", "", "lint error(s) in Web Platform Tests: exit status %s" % returncode)
Ejemplo n.º 21
0
    def run(self):
        if self.stylo:
            return

        wpt_working_dir = os.path.abspath(os.path.join(WPT_PATH, "web-platform-tests"))
        for suite in SUITES:
            files = self._get_wpt_files(suite)
            sys.path.insert(0, wpt_working_dir)
            from tools.lint import lint
            sys.path.remove(wpt_working_dir)
            file_dir = os.path.abspath(os.path.join(WPT_PATH, suite))
            returncode = lint.lint(file_dir, list(files), output_format="json")
            if returncode:
                yield ("WPT Lint Tool", "", "lint error(s) in Web Platform Tests: exit status %s" % returncode)
Ejemplo n.º 22
0
def test_check_unique_testharness_basename_different_name(caplog):
    # Precondition: There are two testharness files in the same directory with
    # different names.
    assert os.path.exists(os.path.join(_dummy_repo, 'tests', 'dir1', 'a.html'))
    assert os.path.exists(os.path.join(_dummy_repo, 'tests', 'dir1', 'b.html'))

    with _mock_lint("check_path") as mocked_check_path:
        with _mock_lint("check_file_contents") as mocked_check_file_contents:
            rv = lint(_dummy_repo, ["tests/dir1/a.html", "tests/dir1/b.html"],
                      "normal")
            assert rv == 0
            assert mocked_check_path.call_count == 2
            assert mocked_check_file_contents.call_count == 2
    assert caplog.text == ""
Ejemplo n.º 23
0
def test_check_unique_testharness_basename_same_basename(caplog):
    # Precondition: There are testharness files with conflicting basename paths.
    assert os.path.exists(os.path.join(_dummy_repo, 'tests', 'dir1', 'a.html'))
    assert os.path.exists(os.path.join(_dummy_repo, 'tests', 'dir1',
                                       'a.xhtml'))

    with _mock_lint("check_path") as mocked_check_path:
        with _mock_lint("check_file_contents") as mocked_check_file_contents:
            rv = lint(_dummy_repo, ["tests/dir1/a.html", "tests/dir1/a.xhtml"],
                      "normal")
            # There will be one failure for each file.
            assert rv == 2
            assert mocked_check_path.call_count == 2
            assert mocked_check_file_contents.call_count == 2
    assert "DUPLICATE-BASENAME-PATH" in caplog.text
Ejemplo n.º 24
0
def test_lint_no_files(caplog):
    rv = lint(_dummy_repo, [], "normal")
    assert rv == 0
    assert caplog.text == ""
Ejemplo n.º 25
0
def test_manual_path_testharness(caplog):
    rv = lint(_dummy_repo, ["tests/relative-testharness-manual.html"],
              "normal")
    assert rv == 2
    assert "TESTHARNESS-PATH" in caplog.text
    assert "TESTHARNESSREPORT-PATH" in caplog.text