Esempio n. 1
0
    def test_analyze_csswg_manual_test(self):
        """Tests analyze_test() using a test that is neither a reftest or jstest, in csswg-test"""

        test_html = """<html>
<head>
<title>CSS Test: DESCRIPTION OF TEST</title>
<link rel="author" title="NAME_OF_AUTHOR" />
<style type="text/css"><![CDATA[
CSS FOR TEST
]]></style>
</head>
<body>
CONTENT OF TEST
</body>
</html>
"""
        parser = TestParser('/some/wpt/css/path/somefile.html', MockHost())
        test_info = parser.analyze_test(test_contents=test_html)
        self.assertIsNotNone(test_info, 'test_info should not be None')
        self.assertIn('test', test_info.keys(), 'should find a test file')
        self.assertNotIn('reference', test_info.keys(),
                         'shold not have found a reference file')
        self.assertNotIn('refsupport', test_info.keys(),
                         'there should be no refsupport files for this test')
        self.assertNotIn('jstest', test_info.keys(),
                         'test should not be a jstest')
Esempio n. 2
0
    def test_analyze_test_reftest_match_and_mismatch(self):
        test_html = """<head>
<link rel="match" href="green-box-ref.xht" />
<link rel="match" href="blue-box-ref.xht" />
<link rel="mismatch" href="orange-box-notref.xht" />
</head>
"""
        oc = OutputCapture()
        oc.capture_output()

        try:
            test_path = os.path.join(os.path.sep, 'some', 'madeup', 'path')
            parser = TestParser(options,
                                os.path.join(test_path, 'somefile.html'))
            test_info = parser.analyze_test(test_contents=test_html)
        finally:
            _, _, logs = oc.restore_output()

        self.assertNotEqual(test_info, None, 'did not find a test')
        self.assertTrue('test' in test_info.keys(), 'did not find a test file')
        self.assertTrue('reference' in test_info.keys(),
                        'did not find a reference file')
        self.assertTrue(test_info['reference'].startswith(test_path),
                        'reference path is not correct')
        self.assertFalse('refsupport' in test_info.keys(),
                         'there should be no refsupport files for this test')
        self.assertFalse('jstest' in test_info.keys(),
                         'test should not have been analyzed as a jstest')

        self.assertEqual(
            logs,
            'Multiple references are not supported. Importing the first ref defined in somefile.html\n'
        )
Esempio n. 3
0
    def test_analyze_test_reftest_multiple_matches(self):
        test_html = """<head>
<link rel="match" href="green-box-ref.xht" />
<link rel="match" href="blue-box-ref.xht" />
<link rel="match" href="orange-box-ref.xht" />
</head>
"""
        oc = OutputCapture()
        oc.capture_output()
        try:
            test_path = "/some/madeup/path/"
            parser = TestParser(options, test_path + "somefile.html")
            test_info = parser.analyze_test(test_contents=test_html)
        finally:
            _, _, logs = oc.restore_output()

        self.assertNotEqual(test_info, None, "did not find a test")
        self.assertTrue("test" in test_info.keys(), "did not find a test file")
        self.assertTrue("reference" in test_info.keys(), "did not find a reference file")
        self.assertTrue(test_info["reference"].startswith(test_path), "reference path is not correct")
        self.assertFalse("refsupport" in test_info.keys(), "there should be no refsupport files for this test")
        self.assertFalse("jstest" in test_info.keys(), "test should not have been analyzed as a jstest")

        self.assertEqual(
            logs, "Multiple references are not supported. Importing the first ref defined in somefile.html\n"
        )
Esempio n. 4
0
    def test_analyze_wpt_manual_test(self):
        """Tests analyze_test() with a manual test that is not in csswg-test."""

        test_html = """<html>
<head>
<title>CSS Test: DESCRIPTION OF TEST</title>
<link rel="author" title="NAME_OF_AUTHOR" />
<style type="text/css"><![CDATA[
CSS FOR TEST
]]></style>
</head>
<body>
CONTENT OF TEST
</body>
</html>
"""
        test_path = '/some/madeup/path/'
        parser = TestParser(test_path + 'somefile-manual.html', MockHost())
        test_info = parser.analyze_test(test_contents=test_html)

        self.assertNotEqual(test_info, None, 'test_info is None')
        self.assertTrue('test' in test_info.keys(), 'did not find a test file')
        self.assertFalse('reference' in test_info.keys(),
                         'shold not have found a reference file')
        self.assertFalse('refsupport' in test_info.keys(),
                         'there should be no refsupport files for this test')
        self.assertFalse('jstest' in test_info.keys(),
                         'test should not be a jstest')
Esempio n. 5
0
    def test_analyze_test_reftest_multiple_matches(self):
        test_html = """<head>
<link rel="match" href="green-box-ref.xht" />
<link rel="match" href="blue-box-ref.xht" />
<link rel="match" href="orange-box-ref.xht" />
</head>
"""
        with OutputCapture(level=logging.INFO) as captured:
            test_path = os.path.join(os.path.sep, 'some', 'madeup', 'path')
            parser = TestParser(options,
                                os.path.join(test_path, 'somefile.html'))
            test_info = parser.analyze_test(test_contents=test_html)

        self.assertNotEqual(test_info, None, 'did not find a test')
        self.assertTrue('test' in test_info.keys(), 'did not find a test file')
        self.assertTrue('reference' in test_info.keys(),
                        'did not find a reference file')
        self.assertTrue(test_info['reference'].startswith(test_path),
                        'reference path is not correct')
        self.assertFalse('refsupport' in test_info.keys(),
                         'there should be no refsupport files for this test')
        self.assertFalse('jstest' in test_info.keys(),
                         'test should not have been analyzed as a jstest')

        self.assertEqual(
            captured.root.log.getvalue(),
            'Multiple references are not supported. Importing the first ref defined in somefile.html\n',
        )
Esempio n. 6
0
    def test_analyze_css_manual_test(self):
        """ Tests analyze_test() using a css manual test """

        test_path = os.path.join(os.path.sep, 'some', 'madeup', 'path')
        parser = TestParser(options, os.path.join(test_path, 'somefile.html'))

        for content in [
                "", "flag1", "flag1 flag2", "flag1 flag2 flag3", "asis"
        ]:
            test_html = """
<head>
  <meta name="flags" content="%s">
</head>""" % content
            test_info = parser.analyze_test(test_contents=test_html)
            self.assertEqual(test_info, None, 'test_info should be None')

        for flag in [
                "animated", "font", "history", "interact", "paged", "speech",
                "userstyle"
        ]:
            test_html = """
<head>
  <meta name="flags" content="flag1 flag2">
  <meta name="flags" content="flag3 %s flag4 flag5">
  <meta name="flags" content="flag6">
</head>
""" % flag
            test_info = parser.analyze_test(test_contents=test_html)
            self.assertTrue(test_info['manualtest'],
                            'test with CSS flag %s should be manual' % flag)
Esempio n. 7
0
    def test_analyze_pixel_test_all_false(self):
        """ Tests analyze_test() using a test that is neither a reftest or jstest, with -all=False """

        test_html = """<html>
<head>
<title>CSS Test: DESCRIPTION OF TEST</title>
<link rel="author" title="NAME_OF_AUTHOR" />
<style type="text/css"><![CDATA[
CSS FOR TEST
]]></style>
</head>
<body>
CONTENT OF TEST
</body>
</html>
"""
        # Set all to false so this gets skipped
        global options
        orig_options = options.copy()
        try:
            options['all'] = False

            test_path = os.path.join(os.path.sep, 'some', 'madeup', 'path')
            parser = TestParser(options,
                                os.path.join(test_path, 'somefile.html'))
            test_info = parser.analyze_test(test_contents=test_html)

            self.assertEqual(test_info, None, 'test should have been skipped')
        finally:
            options = orig_options
    def test_analyze_test_reftest_match_and_mismatch(self):
        test_html = """<head>
<link rel="match" href="green-box-ref.xht" />
<link rel="match" href="blue-box-ref.xht" />
<link rel="mismatch" href="orange-box-notref.xht" />
</head>
"""
        oc = OutputCapture()
        oc.capture_output()

        try:
            test_path = '/some/madeup/path/'
            parser = TestParser(options, test_path + 'somefile.html')
            test_info = parser.analyze_test(test_contents=test_html)
        finally:
            output, _, _ = oc.restore_output()

        self.assertNotEqual(test_info, None, 'did not find a test')
        self.assertTrue('test' in test_info.keys(), 'did not find a test file')
        self.assertTrue('reference' in test_info.keys(),
                        'did not find a reference file')
        self.assertTrue(test_info['reference'].startswith(test_path),
                        'reference path is not correct')
        self.assertFalse('refsupport' in test_info.keys(),
                         'there should be no refsupport files for this test')
        self.assertFalse('jstest' in test_info.keys(),
                         'test should not have been analyzed as a jstest')

        warnings = output.splitlines()
        self.assertEquals(warnings, [
            "Warning: Webkit does not support multiple references. Importing the first ref defined in somefile.html"
        ])
Esempio n. 9
0
    def test_analyze_wpt_manual_test(self):
        """Tests analyze_test() with a manual test that is not in csswg-test."""

        test_html = """<html>
<head>
<title>CSS Test: DESCRIPTION OF TEST</title>
<link rel="author" title="NAME_OF_AUTHOR" />
<style type="text/css"><![CDATA[
CSS FOR TEST
]]></style>
</head>
<body>
CONTENT OF TEST
</body>
</html>
"""
        test_path = '/some/madeup/path/'
        parser = TestParser(test_path + 'somefile-manual.html', MockHost())
        test_info = parser.analyze_test(test_contents=test_html)

        self.assertNotEqual(test_info, None, 'test_info is None')
        self.assertTrue('test' in test_info.keys(), 'did not find a test file')
        self.assertFalse('reference' in test_info.keys(), 'shold not have found a reference file')
        self.assertFalse('refsupport' in test_info.keys(), 'there should be no refsupport files for this test')
        self.assertFalse('jstest' in test_info.keys(), 'test should not be a jstest')
Esempio n. 10
0
    def test_analyze_test_reftest_with_ref_support_Files(self):
        """Tests analyze_test() using a reftest that has refers to a
        reference file outside of the tests directory and the reference
        file has paths to other support files.
        """

        test_html = """<html>
<head>
<link rel="match" href="../reference/green-box-ref.xht" />
</head>
"""
        ref_html = """<head>
<link href="support/css/ref-stylesheet.css" rel="stylesheet" type="text/css">
<style type="text/css">
    background-image: url("../../support/some-image.png")
</style>
</head>
<body>
<div><img src="../support/black96x96.png" alt="Image download support must be enabled" /></div>
</body>
</html>
"""
        test_path = '/some/madeup/path/'
        parser = TestParser(test_path + 'somefile.html', MockHost())
        test_info = parser.analyze_test(test_contents=test_html, ref_contents=ref_html)

        self.assertNotEqual(test_info, None, 'did not find a test')
        self.assertTrue('test' in test_info.keys(), 'did not find a test file')
        self.assertTrue('reference' in test_info.keys(), 'did not find a reference file')
        self.assertTrue(test_info['reference'].startswith(test_path), 'reference path is not correct')
        self.assertTrue('reference_support_info' in test_info.keys(), 'there should be reference_support_info for this test')
        self.assertEquals(len(test_info['reference_support_info']['files']), 3, 'there should be 3 support files in this reference')
        self.assertFalse('jstest' in test_info.keys(), 'test should not have been analyzed as a jstest')
Esempio n. 11
0
    def test_analyze_test_reftest_with_ref_support_Files(self):
        """ Tests analyze_test() using a reftest that has refers to a reference file outside of the tests directory and the reference file has paths to other support files """

        test_html = """<html>
<head>
<link rel="match" href="../reference/green-box-ref.xht" />
</head>
"""
        ref_html = """<head>
<link href="support/css/ref-stylesheet.css" rel="stylesheet" type="text/css">
<style type="text/css">
    background-image: url("../../support/some-image.png")
</style>
</head>
<body>
<div><img src="../support/black96x96.png" alt="Image download support must be enabled" /></div>
</body>
</html>
"""
        test_path = '/some/madeup/path/'
        parser = TestParser(options, test_path + 'somefile.html')
        test_info = parser.analyze_test(test_contents=test_html, ref_contents=ref_html)

        self.assertNotEqual(test_info, None, 'did not find a test')
        self.assertTrue('test' in test_info.keys(), 'did not find a test file')
        self.assertTrue('reference' in test_info.keys(), 'did not find a reference file')
        self.assertTrue(test_info['reference'].startswith(test_path), 'reference path is not correct')
        self.assertTrue('refsupport' in test_info.keys(), 'there should be refsupport files for this test')
        self.assertEquals(len(test_info['refsupport']), 3, 'there should be 3 support files in this reference')
        self.assertFalse('jstest' in test_info.keys(), 'test should not have been analyzed as a jstest')
Esempio n. 12
0
    def test_analyze_pixel_test_all_true(self):
        """ Tests analyze_test() using a test that is neither a reftest or jstest with all=False """

        test_html = """<html>
<head>
<title>CSS Test: DESCRIPTION OF TEST</title>
<link rel="author" title="NAME_OF_AUTHOR" />
<style type="text/css"><![CDATA[
CSS FOR TEST
]]></style>
</head>
<body>
CONTENT OF TEST
</body>
</html>
"""
        # Set options to 'all' so this gets found
        options['all'] = True

        test_path = '/some/madeup/path/'
        parser = TestParser(options, test_path + 'somefile.html')
        test_info = parser.analyze_test(test_contents=test_html)

        self.assertNotEqual(test_info, None, 'test_info is None')
        self.assertTrue('test' in test_info.keys(), 'did not find a test file')
        self.assertFalse('reference' in test_info.keys(), 'shold not have found a reference file')
        self.assertFalse('refsupport' in test_info.keys(), 'there should be no refsupport files for this test')
        self.assertFalse('jstest' in test_info.keys(), 'test should not be a jstest')
Esempio n. 13
0
    def test_analyze_test_reftest_match_and_mismatch(self):
        test_html = """<head>
<link rel="match" href="green-box-ref.xht" />
<link rel="match" href="blue-box-ref.xht" />
<link rel="mismatch" href="orange-box-notref.xht" />
</head>
"""
        oc = OutputCapture()
        oc.capture_output()

        try:
            test_path = '/some/madeup/path/'
            parser = TestParser(options, test_path + 'somefile.html')
            test_info = parser.analyze_test(test_contents=test_html)
        finally:
            _, _, logs = oc.restore_output()

        self.assertNotEqual(test_info, None, 'did not find a test')
        self.assertTrue('test' in test_info.keys(), 'did not find a test file')
        self.assertTrue('reference' in test_info.keys(), 'did not find a reference file')
        self.assertTrue(test_info['reference'].startswith(test_path), 'reference path is not correct')
        self.assertFalse('refsupport' in test_info.keys(), 'there should be no refsupport files for this test')
        self.assertFalse('jstest' in test_info.keys(), 'test should not have been analyzed as a jstest')

        self.assertEqual(logs, 'Multiple references are not supported. Importing the first ref defined in somefile.html\n')
Esempio n. 14
0
    def test_analyze_pixel_test_all_true(self):
        """ Tests analyze_test() using a test that is neither a reftest or jstest with all=False """

        test_html = """<html>
<head>
<title>CSS Test: DESCRIPTION OF TEST</title>
<link rel="author" title="NAME_OF_AUTHOR" />
<style type="text/css"><![CDATA[
CSS FOR TEST
]]></style>
</head>
<body>
CONTENT OF TEST
</body>
</html>
"""
        # Set options to 'all' so this gets found
        options['all'] = True

        test_path = os.path.join(os.path.sep, 'some', 'madeup', 'path')
        parser = TestParser(options, os.path.join(test_path, 'somefile.html'))
        test_info = parser.analyze_test(test_contents=test_html)

        self.assertNotEqual(test_info, None, 'test_info is None')
        self.assertTrue('test' in test_info.keys(), 'did not find a test file')
        self.assertFalse('reference' in test_info.keys(),
                         'shold not have found a reference file')
        self.assertFalse('refsupport' in test_info.keys(),
                         'there should be no refsupport files for this test')
        self.assertFalse('jstest' in test_info.keys(),
                         'test should not be a jstest')
Esempio n. 15
0
 def test_analyze_non_html_file(self):
     """ Tests analyze_test() with a file that has no html"""
     # FIXME: use a mock filesystem
     parser = TestParser(
         options, os.path.join(os.path.dirname(__file__), 'test_parser.py'))
     test_info = parser.analyze_test()
     self.assertEqual(test_info, None,
                      'no tests should have been found in this file')
Esempio n. 16
0
    def find_importable_tests(self, directory):
        # FIXME: use filesystem
        for root, dirs, files in os.walk(directory):
            _log.info('Scanning ' + root + '...')
            total_tests = 0
            reftests = 0
            jstests = 0

            dirs[:] = [subdir for subdir in dirs if self.should_keep_subdir(root, subdir)]

            copy_list = []

            for filename in files:
                # FIXME: This block should really be a separate function, but the early-continues make that difficult.

                if filename.startswith('.') or filename.endswith('.pl'):
                    continue  # For some reason the w3c repo contains random perl scripts we don't care about.

                fullpath = os.path.join(root, filename)

                mimetype = mimetypes.guess_type(fullpath)
                if not 'html' in str(mimetype[0]) and not 'application/xhtml+xml' in str(mimetype[0]) and not 'application/xml' in str(mimetype[0]):
                    copy_list.append({'src': fullpath, 'dest': filename})
                    continue

                test_parser = TestParser(vars(self.options), filename=fullpath)
                test_info = test_parser.analyze_test()
                if test_info is None:
                    continue

                if 'reference' in test_info.keys():
                    reftests += 1
                    total_tests += 1
                    test_basename = os.path.basename(test_info['test'])

                    # Add the ref file, following WebKit style.
                    # FIXME: Ideally we'd support reading the metadata
                    # directly rather than relying  on a naming convention.
                    # Using a naming convention creates duplicate copies of the
                    # reference files.
                    ref_file = os.path.splitext(test_basename)[0] + '-expected'
                    ref_file += os.path.splitext(test_basename)[1]

                    copy_list.append({'src': test_info['reference'], 'dest': ref_file, 'reference_support_info': test_info['reference_support_info']})
                    copy_list.append({'src': test_info['test'], 'dest': filename})

                elif 'jstest' in test_info.keys():
                    jstests += 1
                    total_tests += 1
                    copy_list.append({'src': fullpath, 'dest': filename})
                else:
                    total_tests += 1
                    copy_list.append({'src': fullpath, 'dest': filename})

            if copy_list:
                # Only add this directory to the list if there's something to import
                self.import_list.append({'dirname': root, 'copy_list': copy_list,
                    'reftests': reftests, 'jstests': jstests, 'total_tests': total_tests})
Esempio n. 17
0
    def test_analyze_manual_wpt_test(self):
        """ Tests analyze_test() using a manual jstest """

        test_html = """<head>
<link href="/resources/testharness.css" rel="stylesheet" type="text/css">
<script src="/resources/testharness.js"></script>
</head>
"""
        test_path = os.path.join(os.path.sep, 'some', 'madeup', 'path')
        parser = TestParser(options,
                            os.path.join(test_path, 'somefile-manual.html'))
        test_info = parser.analyze_test(test_contents=test_html)
        self.assertTrue(test_info['manualtest'], 'test_info is manual')

        parser = TestParser(
            options, os.path.join(test_path, 'somefile-manual.https.html'))
        test_info = parser.analyze_test(test_contents=test_html)
        self.assertTrue(test_info['manualtest'], 'test_info is manual')

        parser = TestParser(
            options, os.path.join(test_path, 'somefile-manual-https.html'))
        test_info = parser.analyze_test(test_contents=test_html)
        self.assertFalse(
            'manualtest' in test_info.keys() and test_info['manualtest'],
            'test_info is not manual')
Esempio n. 18
0
    def is_js_test(self, test_path):
        """Checks whether a given file is a testharness.js test.

        Args:
            test_path: A file path relative to the layout tests directory.
                This might correspond to a deleted file or a non-test.
        """
        absolute_path = self.host.filesystem.join(self.finder.layout_tests_dir(), test_path)
        test_parser = TestParser(absolute_path, self.host)
        if not test_parser.test_doc:
            return False
        return test_parser.is_jstest()
Esempio n. 19
0
    def test_analyze_manual_wpt_test(self):
        """ Tests analyze_test() using a manual jstest """

        test_html = """<head>
<link href="/resources/testharness.css" rel="stylesheet" type="text/css">
<script src="/resources/testharness.js"></script>
</head>
"""
        test_path = os.path.join(os.path.sep, 'some', 'madeup', 'path')
        parser = TestParser(options, os.path.join(test_path, 'somefile-manual.html'))
        test_info = parser.analyze_test(test_contents=test_html)

        self.assertTrue(test_info['manualtest'], 'test_info is None')
Esempio n. 20
0
    def test_analyze_manual_wpt_test(self):
        """ Tests analyze_test() using a manual jstest """

        test_html = """<head>
<link href="/resources/testharness.css" rel="stylesheet" type="text/css">
<script src="/resources/testharness.js"></script>
</head>
"""
        test_path = '/some/madeup/path/'
        parser = TestParser(options, test_path + 'somefile-manual.html')
        test_info = parser.analyze_test(test_contents=test_html)

        self.assertEqual(test_info, None, 'test_info is None')
    def test_analyze_manual_wpt_test(self):
        """ Tests analyze_test() using a manual jstest """

        test_html = """<head>
<link href="/resources/testharness.css" rel="stylesheet" type="text/css">
<script src="/resources/testharness.js"></script>
</head>
"""
        test_path = '/some/madeup/path/'
        parser = TestParser(options, test_path + 'somefile-manual.html')
        test_info = parser.analyze_test(test_contents=test_html)

        self.assertEqual(test_info, None, 'test_info is None')
Esempio n. 22
0
    def test_analyze_test_reftest_one_match(self):
        test_html = """<head>
<link rel="match" href="green-box-ref.xht" />
</head>
"""
        test_path = "/some/madeup/path/"
        parser = TestParser(options, test_path + "somefile.html")
        test_info = parser.analyze_test(test_contents=test_html)

        self.assertNotEqual(test_info, None, "did not find a test")
        self.assertTrue("test" in test_info.keys(), "did not find a test file")
        self.assertTrue("reference" in test_info.keys(), "did not find a reference file")
        self.assertTrue(test_info["reference"].startswith(test_path), "reference path is not correct")
        self.assertFalse("refsupport" in test_info.keys(), "there should be no refsupport files for this test")
        self.assertFalse("jstest" in test_info.keys(), "test should not have been analyzed as a jstest")
Esempio n. 23
0
    def test_analyze_test_reftest_one_match(self):
        test_html = """<head>
<link rel="match" href="green-box-ref.xht" />
</head>
"""
        test_path = '/some/madeup/path/'
        parser = TestParser(options, test_path + 'somefile.html')
        test_info = parser.analyze_test(test_contents=test_html)

        self.assertNotEqual(test_info, None, 'did not find a test')
        self.assertTrue('test' in test_info.keys(), 'did not find a test file')
        self.assertTrue('reference' in test_info.keys(), 'did not find a reference file')
        self.assertTrue(test_info['reference'].startswith(test_path), 'reference path is not correct')
        self.assertFalse('refsupport' in test_info.keys(), 'there should be no refsupport files for this test')
        self.assertFalse('jstest' in test_info.keys(), 'test should not have been analyzed as a jstest')
Esempio n. 24
0
    def test_analyze_test_reftest_one_match(self):
        test_html = """<head>
<link rel="match" href="green-box-ref.xht" />
</head>
"""
        test_path = '/some/madeup/path/'
        parser = TestParser(test_path + 'somefile.html', MockHost())
        test_info = parser.analyze_test(test_contents=test_html)

        self.assertNotEqual(test_info, None, 'did not find a test')
        self.assertTrue('test' in test_info.keys(), 'did not find a test file')
        self.assertTrue('reference' in test_info.keys(), 'did not find a reference file')
        self.assertTrue(test_info['reference'].startswith(test_path), 'reference path is not correct')
        self.assertFalse('refsupport' in test_info.keys(), 'there should be no refsupport files for this test')
        self.assertFalse('jstest' in test_info.keys(), 'test should not have been analyzed as a jstest')
Esempio n. 25
0
    def test_analyze_jstest(self):
        """Tests analyze_test() using a jstest"""

        test_html = """<head>
<link href="/resources/testharness.css" rel="stylesheet" type="text/css">
<script src="/resources/testharness.js"></script>
</head>
"""
        test_path = '/some/madeup/path/'
        parser = TestParser(test_path + 'somefile.html', MockHost())
        test_info = parser.analyze_test(test_contents=test_html)

        self.assertNotEqual(test_info, None, 'test_info is None')
        self.assertTrue('test' in test_info.keys(), 'did not find a test file')
        self.assertFalse('reference' in test_info.keys(), 'should not have found a reference file')
        self.assertFalse('refsupport' in test_info.keys(), 'there should be no refsupport files for this test')
        self.assertTrue('jstest' in test_info.keys(), 'test should be a jstest')
Esempio n. 26
0
    def test_analyze_jstest(self):
        """ Tests analyze_test() using a jstest """

        test_html = """<head>
<link href="/resources/testharness.css" rel="stylesheet" type="text/css">
<script src="/resources/testharness.js"></script>
</head>
"""
        test_path = '/some/madeup/path/'
        parser = TestParser(options, test_path + 'somefile.html')
        test_info = parser.analyze_test(test_contents=test_html)

        self.assertNotEqual(test_info, None, 'test_info is None')
        self.assertTrue('test' in test_info.keys(), 'did not find a test file')
        self.assertFalse('reference' in test_info.keys(), 'shold not have found a reference file')
        self.assertFalse('refsupport' in test_info.keys(), 'there should be no refsupport files for this test')
        self.assertTrue('jstest' in test_info.keys(), 'test should be a jstest')
Esempio n. 27
0
    def is_js_test(self, test_path):
        """Checks whether a given file is a testharness.js test.

        TODO(qyearsley): This may not behave how we want it to for virtual tests.
        TODO(qyearsley): Avoid using TestParser; maybe this should use
        Port.test_type, or Port.reference_files to see whether it's not
        a reference test?

        Args:
            test_path: A file path relative to the layout tests directory.
                This might correspond to a deleted file or a non-test.
        """
        absolute_path = self.host.filesystem.join(self.finder.layout_tests_dir(), test_path)
        test_parser = TestParser(absolute_path, self.host)
        if not test_parser.test_doc:
            return False
        return test_parser.is_jstest()
Esempio n. 28
0
    def test_reference_test(self):
        """ Tests analyze_test() using a test that is a reference file having a <link rel="match"> tag"""

        test_html = """<html>
<head>
<title>CSS Test: DESCRIPTION OF TEST</title>
<link rel="match" href="test-ref.html" />
<link rel="author" title="NAME_OF_AUTHOR" />
<style type="text/css"><![CDATA[
CSS FOR TEST
]]></style>
</head>
<body>
CONTENT OF TEST
</body>
</html>
"""
        test_path = os.path.join(os.path.sep, 'some', 'madeup', 'path')
        parser = TestParser(options, os.path.join(test_path, 'test-ref.html'))
        test_info = parser.analyze_test(test_contents=test_html)

        self.assertTrue('referencefile' in test_info, 'test should be detected as reference file')
Esempio n. 29
0
    def test_reference_test(self):
        """ Tests analyze_test() using a test that is a reference file having a <link rel="match"> tag"""

        test_html = """<html>
<head>
<title>CSS Test: DESCRIPTION OF TEST</title>
<link rel="match" href="test-ref.html" />
<link rel="author" title="NAME_OF_AUTHOR" />
<style type="text/css"><![CDATA[
CSS FOR TEST
]]></style>
</head>
<body>
CONTENT OF TEST
</body>
</html>
"""
        test_path = os.path.join(os.path.sep, 'some', 'madeup', 'path')
        parser = TestParser(options, os.path.join(test_path, 'test-ref.html'))
        test_info = parser.analyze_test(test_contents=test_html)

        self.assertTrue('referencefile' in test_info, 'test should be detected as reference file')
Esempio n. 30
0
    def test_analyze_pixel_test_all_false(self):
        """Tests analyze_test() using a test that is neither a reftest or jstest, with -all=False"""

        test_html = """<html>
<head>
<title>CSS Test: DESCRIPTION OF TEST</title>
<link rel="author" title="NAME_OF_AUTHOR" />
<style type="text/css"><![CDATA[
CSS FOR TEST
]]></style>
</head>
<body>
CONTENT OF TEST
</body>
</html>
"""
        # Set 'all' to False so this gets skipped.
        options = {'all': False}

        test_path = '/some/madeup/path/'
        parser = TestParser(test_path + 'somefile.html', MockHost(), options)
        test_info = parser.analyze_test(test_contents=test_html)
        self.assertEqual(test_info, None, 'test should have been skipped')
Esempio n. 31
0
    def test_analyze_csswg_manual_test(self):
        """Tests analyze_test() using a test that is neither a reftest or jstest, in csswg-test"""

        test_html = """<html>
<head>
<title>CSS Test: DESCRIPTION OF TEST</title>
<link rel="author" title="NAME_OF_AUTHOR" />
<style type="text/css"><![CDATA[
CSS FOR TEST
]]></style>
</head>
<body>
CONTENT OF TEST
</body>
</html>
"""
        parser = TestParser('/some/csswg-test/path/somefile.html', MockHost())
        test_info = parser.analyze_test(test_contents=test_html)
        self.assertIsNotNone(test_info, 'test_info should not be None')
        self.assertIn('test', test_info.keys(), 'should find a test file')
        self.assertNotIn('reference', test_info.keys(), 'shold not have found a reference file')
        self.assertNotIn('refsupport', test_info.keys(), 'there should be no refsupport files for this test')
        self.assertNotIn('jstest', test_info.keys(), 'test should not be a jstest')
    def test_analyze_test_reftest_multiple_matches(self):
        test_html = """<head>
<link rel="match" href="green-box-ref.xht" />
<link rel="match" href="blue-box-ref.xht" />
<link rel="match" href="orange-box-ref.xht" />
</head>
"""
        oc = OutputCapture()
        oc.capture_output()
        try:
            test_path = '/some/madeup/path/'
            parser = TestParser(options, test_path + 'somefile.html')
            test_info = parser.analyze_test(test_contents=test_html)
        finally:
            output, _, _ = oc.restore_output()

        self.assertNotEqual(test_info, None, 'did not find a test')
        self.assertTrue('test' in test_info.keys(), 'did not find a test file')
        self.assertTrue('reference' in test_info.keys(), 'did not find a reference file')
        self.assertTrue(test_info['reference'].startswith(test_path), 'reference path is not correct')
        self.assertFalse('refsupport' in test_info.keys(), 'there should be no refsupport files for this test')
        self.assertFalse('jstest' in test_info.keys(), 'test should not have been analyzed as a jstest')

        self.assertTrue(output.startswith('Warning'), 'no warning about multiple matches')
Esempio n. 33
0
    def test_analyze_pixel_test_all_false(self):
        """ Tests analyze_test() using a test that is neither a reftest or jstest, with -all=False """

        test_html = """<html>
<head>
<title>CSS Test: DESCRIPTION OF TEST</title>
<link rel="author" title="NAME_OF_AUTHOR" />
<style type="text/css"><![CDATA[
CSS FOR TEST
]]></style>
</head>
<body>
CONTENT OF TEST
</body>
</html>
"""
        # Set all to false so this gets skipped
        options['all'] = False

        test_path = os.path.join(os.path.sep, 'some', 'madeup', 'path')
        parser = TestParser(options, os.path.join(test_path, 'somefile.html'))
        test_info = parser.analyze_test(test_contents=test_html)

        self.assertEqual(test_info, None, 'test should have been skipped')
Esempio n. 34
0
    def test_analyze_non_test_file_returns_none(self):
        """Tests analyze_test() using a non-test file."""

        parser = TestParser('/some/madeup/path/somefile.html', MockHost())
        test_info = parser.analyze_test(test_contents='<html>')
        self.assertIsNone(test_info, 'test should have been skipped')
Esempio n. 35
0
 def test_parser_initialization_non_existent_file(self):
     parser = TestParser('some/bogus/path.html', MockHost())
     self.assertEqual(parser.filename, 'some/bogus/path.html')
     self.assertIsNone(parser.test_doc)
     self.assertIsNone(parser.ref_doc)
Esempio n. 36
0
    def find_importable_tests(self, directory):
        # FIXME: use filesystem
        paths_to_skip = self.find_paths_to_skip()

        for root, dirs, files in os.walk(directory):
            cur_dir = root.replace(self.layout_tests_dir + '/', '') + '/'
            _log.info('  scanning ' + cur_dir + '...')
            total_tests = 0
            reftests = 0
            jstests = 0

            # "archive" and "data" dirs are internal csswg things that live in every approved directory.
            # FIXME: skip 'incoming' tests for now, but we should rework the 'test_status' concept and
            # support reading them as well.
            DIRS_TO_SKIP = ('.git', '.hg', 'data', 'archive', 'incoming')
            if dirs:
                for d in DIRS_TO_SKIP:
                    if d in dirs:
                        dirs.remove(d)

                for path in paths_to_skip:
                    path_base = path.replace(cur_dir, '')
                    path_full = self.filesystem.join(root, path_base)
                    if path_base in dirs:
                        dirs.remove(path_base)
                        if not self.options.dry_run and self.import_in_place:
                            _log.info("  pruning %s" % path_base)
                            self.filesystem.rmtree(path_full)

            copy_list = []

            for filename in files:
                path_full = self.filesystem.join(root, filename)
                path_base = path_full.replace(self.layout_tests_dir + '/', '')
                if path_base in paths_to_skip:
                    if not self.options.dry_run and self.import_in_place:
                        _log.info("  pruning %s" % path_base)
                        self.filesystem.remove(path_full)
                        continue
                # FIXME: This block should really be a separate function, but the early-continues make that difficult.

                if filename.startswith('.') or filename.endswith('.pl'):
                    continue  # For some reason the w3c repo contains random perl scripts we don't care about.

                fullpath = os.path.join(root, filename)

                mimetype = mimetypes.guess_type(fullpath)
                if not 'html' in str(mimetype[0]) and not 'xml' in str(mimetype[0]):
                    copy_list.append({'src': fullpath, 'dest': filename})
                    continue

                if root.endswith('resources'):
                    copy_list.append({'src': fullpath, 'dest': filename})
                    continue

                test_parser = TestParser(vars(self.options), filename=fullpath)
                test_info = test_parser.analyze_test()
                if test_info is None:
                    continue

                if 'reference' in test_info.keys():
                    reftests += 1
                    total_tests += 1
                    test_basename = os.path.basename(test_info['test'])

                    # Add the ref file, following WebKit style.
                    # FIXME: Ideally we'd support reading the metadata
                    # directly rather than relying  on a naming convention.
                    # Using a naming convention creates duplicate copies of the
                    # reference files.
                    ref_file = os.path.splitext(test_basename)[0] + '-expected'
                    ref_file += os.path.splitext(test_basename)[1]

                    copy_list.append({'src': test_info['reference'], 'dest': ref_file})
                    copy_list.append({'src': test_info['test'], 'dest': filename})

                    # Update any support files that need to move as well to remain relative to the -expected file.
                    if 'refsupport' in test_info.keys():
                        for support_file in test_info['refsupport']:
                            source_file = os.path.join(os.path.dirname(test_info['reference']), support_file)
                            source_file = os.path.normpath(source_file)

                            # Keep the dest as it was
                            to_copy = {'src': source_file, 'dest': support_file}

                            # Only add it once
                            if not(to_copy in copy_list):
                                copy_list.append(to_copy)
                elif 'jstest' in test_info.keys():
                    jstests += 1
                    total_tests += 1
                    copy_list.append({'src': fullpath, 'dest': filename})
                else:
                    total_tests += 1
                    copy_list.append({'src': fullpath, 'dest': filename})

            if not total_tests:
                # We can skip the support directory if no tests were found.
                if 'support' in dirs:
                    dirs.remove('support')

            if copy_list:
                # Only add this directory to the list if there's something to import
                self.import_list.append({'dirname': root, 'copy_list': copy_list,
                    'reftests': reftests, 'jstests': jstests, 'total_tests': total_tests})
Esempio n. 37
0
    def find_importable_tests(self, directory):
        # FIXME: use filesystem
        for root, dirs, files in os.walk(directory):
            print "Scanning " + root + "..."
            total_tests = 0
            reftests = 0
            jstests = 0

            # "archive" and "data" dirs are internal csswg things that live in every approved directory.
            DIRS_TO_SKIP = (".git", ".hg", "data", "archive")
            for d in DIRS_TO_SKIP:
                if d in dirs:
                    dirs.remove(d)

            copy_list = []

            for filename in files:
                # FIXME: This block should really be a separate function, but the early-continues make that difficult.

                if filename.startswith(".") or filename.endswith(".pl"):
                    continue  # For some reason the w3c repo contains random perl scripts we don't care about.

                fullpath = os.path.join(root, filename)

                mimetype = mimetypes.guess_type(fullpath)
                if not "html" in str(mimetype[0]) and not "xml" in str(mimetype[0]):
                    copy_list.append({"src": fullpath, "dest": filename})
                    continue

                test_parser = TestParser(vars(self.options), filename=fullpath)
                test_info = test_parser.analyze_test()
                if test_info is None:
                    continue

                if "reference" in test_info.keys():
                    reftests += 1
                    total_tests += 1
                    test_basename = os.path.basename(test_info["test"])

                    # Add the ref file, following WebKit style.
                    # FIXME: Ideally we'd support reading the metadata
                    # directly rather than relying  on a naming convention.
                    # Using a naming convention creates duplicate copies of the
                    # reference files.
                    ref_file = os.path.splitext(test_basename)[0] + "-expected"
                    ref_file += os.path.splitext(test_basename)[1]

                    copy_list.append({"src": test_info["reference"], "dest": ref_file})
                    copy_list.append({"src": test_info["test"], "dest": filename})

                    # Update any support files that need to move as well to remain relative to the -expected file.
                    if "refsupport" in test_info.keys():
                        for support_file in test_info["refsupport"]:
                            source_file = os.path.join(os.path.dirname(test_info["reference"]), support_file)
                            source_file = os.path.normpath(source_file)

                            # Keep the dest as it was
                            to_copy = {"src": source_file, "dest": support_file}

                            # Only add it once
                            if not (to_copy in copy_list):
                                copy_list.append(to_copy)
                elif "jstest" in test_info.keys():
                    jstests += 1
                    total_tests += 1
                    copy_list.append({"src": fullpath, "dest": filename})
                else:
                    total_tests += 1
                    copy_list.append({"src": fullpath, "dest": filename})

            if not total_tests:
                # We can skip the support directory if no tests were found.
                if "support" in dirs:
                    dirs.remove("support")

            if copy_list:
                # Only add this directory to the list if there's something to import
                self.import_list.append(
                    {
                        "dirname": root,
                        "copy_list": copy_list,
                        "reftests": reftests,
                        "jstests": jstests,
                        "total_tests": total_tests,
                    }
                )
Esempio n. 38
0
    def find_importable_tests(self, directory):
        def should_keep_subdir(filesystem, path):
            if self._importing_downloaded_tests:
                return True
            subdir = path[len(directory):]
            DIRS_TO_SKIP = ('work-in-progress', 'tools', 'support')
            should_skip = filesystem.basename(subdir).startswith('.') or (subdir in DIRS_TO_SKIP)
            return not should_skip

        directories = self.filesystem.dirs_under(directory, should_keep_subdir)
        for root in directories:
            _log.info('Scanning ' + root + '...')
            total_tests = 0
            reftests = 0
            jstests = 0

            copy_list = []

            for filename in self.filesystem.listdir(root):
                if self.filesystem.isdir(self.filesystem.join(root, filename)):
                    continue
                # FIXME: This block should really be a separate function, but the early-continues make that difficult.

                if self.should_skip_file(filename):
                    continue

                fullpath = self.filesystem.join(root, filename)

                mimetype = mimetypes.guess_type(fullpath)
                if not 'html' in str(mimetype[0]) and not 'application/xhtml+xml' in str(mimetype[0]) and not 'application/xml' in str(mimetype[0]):
                    copy_list.append({'src': fullpath, 'dest': filename})
                    continue

                test_parser = TestParser(vars(self.options), filename=fullpath, host=self.host)
                test_info = test_parser.analyze_test()
                if test_info is None:
                    # This is probably a resource file, but we should generate WPT manifest instead and get the list of resource files from it.
                    if not self._is_in_resources_directory(fullpath):
                        self._potential_test_resource_files.append(fullpath)
                    copy_list.append({'src': fullpath, 'dest': filename})
                    continue
                elif self._is_in_resources_directory(fullpath):
                    _log.warning('%s is a test located in a "resources" folder. This test will be skipped by WebKit test runners.', fullpath)

                if 'slow' in test_info:
                    self._slow_tests.append(fullpath)

                if 'manualtest' in test_info.keys():
                    continue

                if 'referencefile' in test_info.keys():
                    # Skip it since, the corresponding reference test should have a link to this file
                    continue

                if 'reference' in test_info.keys():
                    reftests += 1
                    total_tests += 1
                    test_basename = self.filesystem.basename(test_info['test'])

                    # Add the ref file, following WebKit style.
                    # FIXME: Ideally we'd support reading the metadata
                    # directly rather than relying  on a naming convention.
                    # Using a naming convention creates duplicate copies of the
                    # reference files.
                    ref_file = self.filesystem.splitext(test_basename)[0] + '-expected'
                    ref_file += self.filesystem.splitext(test_info['reference'])[1]

                    copy_list.append({'src': test_info['reference'], 'dest': ref_file, 'reference_support_info': test_info['reference_support_info']})
                    copy_list.append({'src': test_info['test'], 'dest': filename})

                elif 'jstest' in test_info.keys():
                    jstests += 1
                    total_tests += 1
                    copy_list.append({'src': fullpath, 'dest': filename})
                else:
                    total_tests += 1
                    copy_list.append({'src': fullpath, 'dest': filename})

            if copy_list:
                # Only add this directory to the list if there's something to import
                self.import_list.append({'dirname': root, 'copy_list': copy_list,
                    'reftests': reftests, 'jstests': jstests, 'total_tests': total_tests})
Esempio n. 39
0
    def find_importable_tests(self):
        """Walks through the source directory to find what tests should be imported.

        This function sets self.import_list, which contains information about how many
        tests are being imported, and their source and destination paths.
        """
        paths_to_skip = self.find_paths_to_skip()

        for root, dirs, files in self.filesystem.walk(self.source_repo_path):
            cur_dir = root.replace(self.dir_above_repo + '/', '') + '/'
            _log.info('  scanning ' + cur_dir + '...')
            total_tests = 0
            reftests = 0
            jstests = 0

            # Files in 'tools' are not for browser testing, so we skip them.
            # See: http://testthewebforward.org/docs/test-format-guidelines.html#tools
            DIRS_TO_SKIP = ('.git', 'test-plan', 'tools')

            # We copy all files in 'support', including HTML without metadata.
            # See: http://testthewebforward.org/docs/test-format-guidelines.html#support-files
            DIRS_TO_INCLUDE = ('resources', 'support')

            if dirs:
                for d in DIRS_TO_SKIP:
                    if d in dirs:
                        dirs.remove(d)

                for path in paths_to_skip:
                    path_base = path.replace(self.options.destination + '/',
                                             '')
                    path_base = path_base.replace(cur_dir, '')
                    path_full = self.filesystem.join(root, path_base)
                    if path_base in dirs:
                        dirs.remove(path_base)
                        if not self.options.dry_run and self.import_in_place:
                            _log.info("  pruning %s", path_base)
                            self.filesystem.rmtree(path_full)
                        else:
                            _log.info("  skipping %s", path_base)

            copy_list = []

            for filename in files:
                path_full = self.filesystem.join(root, filename)
                path_base = path_full.replace(self.source_repo_path + '/', '')
                path_base = self.destination_directory.replace(
                    self.layout_tests_dir + '/', '') + '/' + path_base
                if path_base in paths_to_skip:
                    if not self.options.dry_run and self.import_in_place:
                        _log.info("  pruning %s", path_base)
                        self.filesystem.remove(path_full)
                        continue
                    else:
                        continue
                # FIXME: This block should really be a separate function, but the early-continues make that difficult.

                if filename.startswith('.') or filename.endswith('.pl'):
                    # The w3cs repos may contain perl scripts, which we don't care about.
                    continue
                if filename == 'OWNERS' or filename == 'reftest.list':
                    # These files fail our presubmits.
                    # See http://crbug.com/584660 and http://crbug.com/582838.
                    continue

                fullpath = self.filesystem.join(root, filename)

                mimetype = mimetypes.guess_type(fullpath)
                if ('html' not in str(mimetype[0])
                        and 'application/xhtml+xml' not in str(mimetype[0])
                        and 'application/xml' not in str(mimetype[0])):
                    copy_list.append({'src': fullpath, 'dest': filename})
                    continue

                if self.filesystem.basename(root) in DIRS_TO_INCLUDE:
                    copy_list.append({'src': fullpath, 'dest': filename})
                    continue

                test_parser = TestParser(fullpath, self.host,
                                         vars(self.options))
                test_info = test_parser.analyze_test()
                if test_info is None:
                    continue

                if self.path_too_long(path_full):
                    _log.warning(
                        '%s skipped due to long path. '
                        'Max length from repo base %d chars; see http://crbug.com/609871.',
                        path_full, MAX_PATH_LENGTH)
                    continue

                if 'reference' in test_info.keys():
                    test_basename = self.filesystem.basename(test_info['test'])
                    # Add the ref file, following WebKit style.
                    # FIXME: Ideally we'd support reading the metadata
                    # directly rather than relying  on a naming convention.
                    # Using a naming convention creates duplicate copies of the
                    # reference files.
                    ref_file = self.filesystem.splitext(
                        test_basename)[0] + '-expected'
                    # Make sure to use the extension from the *reference*, not
                    # from the test, because at least flexbox tests use XHTML
                    # references but HTML tests.
                    ref_file += self.filesystem.splitext(
                        test_info['reference'])[1]

                    if self.path_too_long(path_full.replace(
                            filename, ref_file)):
                        _log.warning(
                            '%s skipped because path of ref file %s would be too long. '
                            'Max length from repo base %d chars; see http://crbug.com/609871.',
                            path_full, ref_file, MAX_PATH_LENGTH)
                        continue

                    reftests += 1
                    total_tests += 1
                    copy_list.append({
                        'src':
                        test_info['reference'],
                        'dest':
                        ref_file,
                        'reference_support_info':
                        test_info['reference_support_info']
                    })
                    copy_list.append({
                        'src': test_info['test'],
                        'dest': filename
                    })

                elif 'jstest' in test_info.keys():
                    jstests += 1
                    total_tests += 1
                    copy_list.append({
                        'src': fullpath,
                        'dest': filename,
                        'is_jstest': True
                    })
                else:
                    total_tests += 1
                    copy_list.append({'src': fullpath, 'dest': filename})

            if copy_list:
                # Only add this directory to the list if there's something to import
                self.import_list.append({
                    'dirname': root,
                    'copy_list': copy_list,
                    'reftests': reftests,
                    'jstests': jstests,
                    'total_tests': total_tests
                })
Esempio n. 40
0
    def find_importable_tests(self, directory):
        def should_keep_subdir(filesystem, path):
            subdir = path[len(directory):]
            DIRS_TO_SKIP = ('work-in-progress', 'tools', 'support')
            should_skip = filesystem.basename(subdir).startswith('.') or (subdir in DIRS_TO_SKIP)
            return not should_skip

        directories = self.filesystem.dirs_under(directory, should_keep_subdir)
        for root in directories:
            _log.info('Scanning ' + root + '...')
            total_tests = 0
            reftests = 0
            jstests = 0

            copy_list = []

            for filename in self.filesystem.listdir(root):
                if self.filesystem.isdir(self.filesystem.join(root, filename)):
                    continue
                # FIXME: This block should really be a separate function, but the early-continues make that difficult.

                if self.should_skip_file(filename):
                    continue

                fullpath = self.filesystem.join(root, filename)

                mimetype = mimetypes.guess_type(fullpath)
                if not 'html' in str(mimetype[0]) and not 'application/xhtml+xml' in str(mimetype[0]) and not 'application/xml' in str(mimetype[0]):
                    copy_list.append({'src': fullpath, 'dest': filename})
                    continue

                test_parser = TestParser(vars(self.options), filename=fullpath)
                test_info = test_parser.analyze_test()
                if test_info is None:
                    # If html file is in a "resources" folder, it should be copied anyway
                    if self.filesystem.basename(self.filesystem.dirname(fullpath)) == "resources":
                        copy_list.append({'src': fullpath, 'dest': filename})
                    continue

                if 'reference' in test_info.keys():
                    reftests += 1
                    total_tests += 1
                    test_basename = self.filesystem.basename(test_info['test'])

                    # Add the ref file, following WebKit style.
                    # FIXME: Ideally we'd support reading the metadata
                    # directly rather than relying  on a naming convention.
                    # Using a naming convention creates duplicate copies of the
                    # reference files.
                    ref_file = self.filesystem.splitext(test_basename)[0] + '-expected'
                    ref_file += self.filesystem.splitext(test_basename)[1]

                    copy_list.append({'src': test_info['reference'], 'dest': ref_file, 'reference_support_info': test_info['reference_support_info']})
                    copy_list.append({'src': test_info['test'], 'dest': filename})

                elif 'jstest' in test_info.keys():
                    jstests += 1
                    total_tests += 1
                    copy_list.append({'src': fullpath, 'dest': filename})
                else:
                    total_tests += 1
                    copy_list.append({'src': fullpath, 'dest': filename})

            if copy_list:
                # Only add this directory to the list if there's something to import
                self.import_list.append({'dirname': root, 'copy_list': copy_list,
                    'reftests': reftests, 'jstests': jstests, 'total_tests': total_tests})
Esempio n. 41
0
    def find_importable_tests(self):
        """Walks through the source directory to find what tests should be imported.

        This function sets self.import_list, which contains information about how many
        tests are being imported, and their source and destination paths.
        """
        paths_to_skip = self.find_paths_to_skip()

        for root, dirs, files in self.filesystem.walk(self.source_repo_path):
            cur_dir = root.replace(self.dir_above_repo + "/", "") + "/"
            _log.info("  scanning " + cur_dir + "...")
            total_tests = 0
            reftests = 0
            jstests = 0

            # Files in 'tools' are not for browser testing, so we skip them.
            # See: http://testthewebforward.org/docs/test-format-guidelines.html#tools
            DIRS_TO_SKIP = (".git", "test-plan", "tools")

            # We copy all files in 'support', including HTML without metadata.
            # See: http://testthewebforward.org/docs/test-format-guidelines.html#support-files
            DIRS_TO_INCLUDE = ("resources", "support")

            if dirs:
                for d in DIRS_TO_SKIP:
                    if d in dirs:
                        dirs.remove(d)

                for path in paths_to_skip:
                    path_base = path.replace(self.options.destination + "/", "")
                    path_base = path_base.replace(cur_dir, "")
                    path_full = self.filesystem.join(root, path_base)
                    if path_base in dirs:
                        dirs.remove(path_base)
                        if not self.options.dry_run and self.import_in_place:
                            _log.info("  pruning %s", path_base)
                            self.filesystem.rmtree(path_full)
                        else:
                            _log.info("  skipping %s", path_base)

            copy_list = []

            for filename in files:
                path_full = self.filesystem.join(root, filename)
                path_base = path_full.replace(self.source_repo_path + "/", "")
                path_base = self.destination_directory.replace(self.layout_tests_dir + "/", "") + "/" + path_base
                if path_base in paths_to_skip:
                    if not self.options.dry_run and self.import_in_place:
                        _log.info("  pruning %s", path_base)
                        self.filesystem.remove(path_full)
                        continue
                    else:
                        continue
                # FIXME: This block should really be a separate function, but the early-continues make that difficult.

                if filename.startswith(".") or filename.endswith(".pl"):
                    # The w3cs repos may contain perl scripts, which we don't care about.
                    continue
                if filename == "OWNERS" or filename == "reftest.list":
                    # These files fail our presubmits.
                    # See http://crbug.com/584660 and http://crbug.com/582838.
                    continue

                fullpath = self.filesystem.join(root, filename)

                mimetype = mimetypes.guess_type(fullpath)
                if (
                    "html" not in str(mimetype[0])
                    and "application/xhtml+xml" not in str(mimetype[0])
                    and "application/xml" not in str(mimetype[0])
                ):
                    copy_list.append({"src": fullpath, "dest": filename})
                    continue

                if self.filesystem.basename(root) in DIRS_TO_INCLUDE:
                    copy_list.append({"src": fullpath, "dest": filename})
                    continue

                test_parser = TestParser(fullpath, self.host, vars(self.options))
                test_info = test_parser.analyze_test()
                if test_info is None:
                    continue

                if self.path_too_long(path_full):
                    _log.warning(
                        "%s skipped due to long path. "
                        "Max length from repo base %d chars; see http://crbug.com/609871.",
                        path_full,
                        MAX_PATH_LENGTH,
                    )
                    continue

                if "reference" in test_info.keys():
                    test_basename = self.filesystem.basename(test_info["test"])
                    # Add the ref file, following WebKit style.
                    # FIXME: Ideally we'd support reading the metadata
                    # directly rather than relying  on a naming convention.
                    # Using a naming convention creates duplicate copies of the
                    # reference files.
                    ref_file = self.filesystem.splitext(test_basename)[0] + "-expected"
                    # Make sure to use the extension from the *reference*, not
                    # from the test, because at least flexbox tests use XHTML
                    # references but HTML tests.
                    ref_file += self.filesystem.splitext(test_info["reference"])[1]

                    if self.path_too_long(path_full.replace(filename, ref_file)):
                        _log.warning(
                            "%s skipped because path of ref file %s would be too long. "
                            "Max length from repo base %d chars; see http://crbug.com/609871.",
                            path_full,
                            ref_file,
                            MAX_PATH_LENGTH,
                        )
                        continue

                    reftests += 1
                    total_tests += 1
                    copy_list.append(
                        {
                            "src": test_info["reference"],
                            "dest": ref_file,
                            "reference_support_info": test_info["reference_support_info"],
                        }
                    )
                    copy_list.append({"src": test_info["test"], "dest": filename})

                elif "jstest" in test_info.keys():
                    jstests += 1
                    total_tests += 1
                    copy_list.append({"src": fullpath, "dest": filename, "is_jstest": True})
                else:
                    total_tests += 1
                    copy_list.append({"src": fullpath, "dest": filename})

            if copy_list:
                # Only add this directory to the list if there's something to import
                self.import_list.append(
                    {
                        "dirname": root,
                        "copy_list": copy_list,
                        "reftests": reftests,
                        "jstests": jstests,
                        "total_tests": total_tests,
                    }
                )
Esempio n. 42
0
    def find_importable_tests(self, directory):
        # FIXME: use filesystem
        paths_to_skip = self.find_paths_to_skip()

        for root, dirs, files in os.walk(directory):
            cur_dir = root.replace(self.dir_above_repo + '/', '') + '/'
            _log.info('  scanning ' + cur_dir + '...')
            total_tests = 0
            reftests = 0
            jstests = 0

            DIRS_TO_SKIP = ('.git', '.hg')
            if dirs:
                for d in DIRS_TO_SKIP:
                    if d in dirs:
                        dirs.remove(d)

                for path in paths_to_skip:
                    path_base = path.replace(self.options.destination + '/', '')
                    path_base = path_base.replace(cur_dir, '')
                    path_full = self.filesystem.join(root, path_base)
                    if path_base in dirs:
                        dirs.remove(path_base)
                        if not self.options.dry_run and self.import_in_place:
                            _log.info("  pruning %s" % path_base)
                            self.filesystem.rmtree(path_full)
                        else:
                            _log.info("  skipping %s" % path_base)


            copy_list = []

            for filename in files:
                path_full = self.filesystem.join(root, filename)
                path_base = path_full.replace(directory + '/', '')
                path_base = self.destination_directory.replace(self.layout_tests_dir + '/', '') + '/' + path_base
                if path_base in paths_to_skip:
                    if not self.options.dry_run and self.import_in_place:
                        _log.info("  pruning %s" % path_base)
                        self.filesystem.remove(path_full)
                        continue
                    else:
                        continue
                # FIXME: This block should really be a separate function, but the early-continues make that difficult.

                if filename.startswith('.') or filename.endswith('.pl'):
                    continue  # For some reason the w3c repo contains random perl scripts we don't care about.

                fullpath = os.path.join(root, filename)

                mimetype = mimetypes.guess_type(fullpath)
                if not 'html' in str(mimetype[0]) and not 'application/xhtml+xml' in str(mimetype[0]) and not 'application/xml' in str(mimetype[0]):
                    copy_list.append({'src': fullpath, 'dest': filename})
                    continue

                if root.endswith('resources'):
                    copy_list.append({'src': fullpath, 'dest': filename})
                    continue

                test_parser = TestParser(vars(self.options), filename=fullpath)
                test_info = test_parser.analyze_test()
                if test_info is None:
                    continue

                if 'reference' in test_info.keys():
                    reftests += 1
                    total_tests += 1
                    test_basename = os.path.basename(test_info['test'])

                    # Add the ref file, following WebKit style.
                    # FIXME: Ideally we'd support reading the metadata
                    # directly rather than relying  on a naming convention.
                    # Using a naming convention creates duplicate copies of the
                    # reference files.
                    ref_file = os.path.splitext(test_basename)[0] + '-expected'
                    ref_file += os.path.splitext(test_basename)[1]

                    copy_list.append({'src': test_info['reference'], 'dest': ref_file, 'reference_support_info': test_info['reference_support_info']})
                    copy_list.append({'src': test_info['test'], 'dest': filename})

                elif 'jstest' in test_info.keys():
                    jstests += 1
                    total_tests += 1
                    copy_list.append({'src': fullpath, 'dest': filename})
                else:
                    total_tests += 1
                    copy_list.append({'src': fullpath, 'dest': filename})

            if copy_list:
                # Only add this directory to the list if there's something to import
                self.import_list.append({'dirname': root, 'copy_list': copy_list,
                    'reftests': reftests, 'jstests': jstests, 'total_tests': total_tests})
Esempio n. 43
0
    def find_importable_tests(self, directory):
        # FIXME: use filesystem
        for root, dirs, files in os.walk(directory):
            _log.info('Scanning ' + root + '...')
            total_tests = 0
            reftests = 0
            jstests = 0

            dirs[:] = [subdir for subdir in dirs if self.should_keep_subdir(root, subdir)]

            copy_list = []

            for filename in files:
                # FIXME: This block should really be a separate function, but the early-continues make that difficult.

                if self.should_skip_file(filename):
                    continue

                fullpath = os.path.join(root, filename)

                mimetype = mimetypes.guess_type(fullpath)
                if not 'html' in str(mimetype[0]) and not 'application/xhtml+xml' in str(mimetype[0]) and not 'application/xml' in str(mimetype[0]):
                    copy_list.append({'src': fullpath, 'dest': filename})
                    continue

                test_parser = TestParser(vars(self.options), filename=fullpath)
                test_info = test_parser.analyze_test()
                if test_info is None:
                    # If html file is in a "resources" folder, it should be copied anyway
                    if os.path.basename(os.path.dirname(fullpath)) == "resources":
                        copy_list.append({'src': fullpath, 'dest': filename})
                    continue

                if 'reference' in test_info.keys():
                    reftests += 1
                    total_tests += 1
                    test_basename = os.path.basename(test_info['test'])

                    # Add the ref file, following WebKit style.
                    # FIXME: Ideally we'd support reading the metadata
                    # directly rather than relying  on a naming convention.
                    # Using a naming convention creates duplicate copies of the
                    # reference files.
                    ref_file = os.path.splitext(test_basename)[0] + '-expected'
                    ref_file += os.path.splitext(test_basename)[1]

                    copy_list.append({'src': test_info['reference'], 'dest': ref_file, 'reference_support_info': test_info['reference_support_info']})
                    copy_list.append({'src': test_info['test'], 'dest': filename})

                elif 'jstest' in test_info.keys():
                    jstests += 1
                    total_tests += 1
                    copy_list.append({'src': fullpath, 'dest': filename})
                else:
                    total_tests += 1
                    copy_list.append({'src': fullpath, 'dest': filename})

            if copy_list:
                # Only add this directory to the list if there's something to import
                self.import_list.append({'dirname': root, 'copy_list': copy_list,
                    'reftests': reftests, 'jstests': jstests, 'total_tests': total_tests})
Esempio n. 44
0
    def test_analyze_non_test_file_returns_none(self):
        """Tests analyze_test() using a non-test file."""

        parser = TestParser('/some/madeup/path/somefile.html', MockHost())
        test_info = parser.analyze_test(test_contents='<html>')
        self.assertIsNone(test_info, 'test should have been skipped')
Esempio n. 45
0
    def find_importable_tests(self):
        """Walks through the source directory to find what tests should be imported.

        This function sets self.import_list, which contains information about how many
        tests are being imported, and their source and destination paths.
        """
        paths_to_skip = self.find_paths_to_skip()

        for root, dirs, files in self.filesystem.walk(self.source_repo_path):
            cur_dir = root.replace(self.dir_above_repo + '/', '') + '/'
            _log.debug('Scanning %s...', cur_dir)
            total_tests = 0
            reftests = 0
            jstests = 0

            # Files in 'tools' are not for browser testing, so we skip them.
            # See: http://web-platform-tests.org/writing-tests/general-guidelines.html#tools
            dirs_to_skip = ('.git', 'test-plan', 'tools')

            # We copy all files in 'support', including HTML without metadata.
            # See: http://web-platform-tests.org/writing-tests/general-guidelines.html#support-files
            dirs_to_include = ('resources', 'support')

            if dirs:
                for name in dirs_to_skip:
                    if name in dirs:
                        dirs.remove(name)

                for path in paths_to_skip:
                    path_base = path.replace(self.dest_dir_name + '/', '')
                    path_base = path_base.replace(cur_dir, '')
                    path_full = self.filesystem.join(root, path_base)
                    if path_base in dirs:
                        _log.info('Skipping: %s', path_full)
                        dirs.remove(path_base)
                        if self.import_in_place:
                            self.filesystem.rmtree(path_full)

            copy_list = []

            for filename in files:
                path_full = self.filesystem.join(root, filename)
                path_base = path_full.replace(self.source_repo_path + '/', '')
                path_base = self.destination_directory.replace(self.layout_tests_dir + '/', '') + '/' + path_base
                if path_base in paths_to_skip:
                    if self.import_in_place:
                        _log.debug('Pruning: %s', path_base)
                        self.filesystem.remove(path_full)
                        continue
                    else:
                        continue
                # FIXME: This block should really be a separate function, but the early-continues make that difficult.

                # TODO(qyearsley): Remove the below block.
                if filename != '.gitignore' and (filename.startswith('.') or filename.endswith('.pl')):
                    _log.debug('Skipping: %s', path_full)
                    _log.debug('  Reason: Hidden files and perl scripts are not necessary.')
                    continue

                if filename == 'OWNERS' or filename == 'reftest.list':
                    # See http://crbug.com/584660 and http://crbug.com/582838.
                    _log.debug('Skipping: %s', path_full)
                    _log.debug('  Reason: This file may cause Chromium presubmit to fail.')
                    continue

                mimetype = mimetypes.guess_type(path_full)
                if ('html' not in str(mimetype[0]) and
                        'application/xhtml+xml' not in str(mimetype[0]) and
                        'application/xml' not in str(mimetype[0])):
                    copy_list.append({'src': path_full, 'dest': filename})
                    continue

                if self.filesystem.basename(root) in dirs_to_include:
                    copy_list.append({'src': path_full, 'dest': filename})
                    continue

                test_parser = TestParser(path_full, self.host)
                test_info = test_parser.analyze_test()
                if test_info is None:
                    copy_list.append({'src': path_full, 'dest': filename})
                    continue

                if 'reference' in test_info.keys():
                    ref_path_full = test_info['reference']
                    if not self.filesystem.exists(ref_path_full):
                        _log.warning('Skipping: %s', path_full)
                        _log.warning('  Reason: Ref file "%s" was not found.', ref_path_full)
                        continue

                    if not self.is_wpt:
                        # For csswg-test, we still need to add a ref file
                        # using WebKit naming conventions. See crbug.com/268729.
                        # FIXME: Remove this when csswg-test is merged into wpt.
                        test_basename = self.filesystem.basename(test_info['test'])
                        ref_file = self.filesystem.splitext(test_basename)[0] + '-expected'
                        ref_file += self.filesystem.splitext(ref_path_full)[1]
                        copy_list.append({
                            'src': test_info['reference'],
                            'dest': ref_file,
                            'reference_support_info': test_info['reference_support_info'],
                        })

                    reftests += 1
                    total_tests += 1
                    copy_list.append({'src': test_info['test'], 'dest': filename})

                elif 'jstest' in test_info.keys():
                    jstests += 1
                    total_tests += 1
                    copy_list.append({'src': path_full, 'dest': filename, 'is_jstest': True})

            if copy_list:
                # Only add this directory to the list if there's something to import
                self.import_list.append({'dirname': root, 'copy_list': copy_list,
                                         'reftests': reftests, 'jstests': jstests, 'total_tests': total_tests})
Esempio n. 46
0
    def find_importable_tests(self, directory):
        # FIXME: use filesystem
        paths_to_skip = self.find_paths_to_skip()

        for root, dirs, files in os.walk(directory):
            cur_dir = root.replace(self.dir_above_repo + "/", "") + "/"
            _log.info("  scanning " + cur_dir + "...")
            total_tests = 0
            reftests = 0
            jstests = 0

            DIRS_TO_SKIP = (".git", ".hg")
            if dirs:
                for d in DIRS_TO_SKIP:
                    if d in dirs:
                        dirs.remove(d)

                for path in paths_to_skip:
                    path_base = path.replace(self.options.destination + "/", "")
                    path_base = path_base.replace(cur_dir, "")
                    path_full = self.filesystem.join(root, path_base)
                    if path_base in dirs:
                        dirs.remove(path_base)
                        if not self.options.dry_run and self.import_in_place:
                            _log.info("  pruning %s" % path_base)
                            self.filesystem.rmtree(path_full)
                        else:
                            _log.info("  skipping %s" % path_base)

            copy_list = []

            for filename in files:
                path_full = self.filesystem.join(root, filename)
                path_base = path_full.replace(directory + "/", "")
                path_base = self.destination_directory.replace(self.layout_tests_dir + "/", "") + "/" + path_base
                if path_base in paths_to_skip:
                    if not self.options.dry_run and self.import_in_place:
                        _log.info("  pruning %s" % path_base)
                        self.filesystem.remove(path_full)
                        continue
                    else:
                        continue
                # FIXME: This block should really be a separate function, but the early-continues make that difficult.

                if filename.startswith(".") or filename.endswith(".pl"):
                    continue  # For some reason the w3c repo contains random perl scripts we don't care about.

                fullpath = os.path.join(root, filename)

                mimetype = mimetypes.guess_type(fullpath)
                if (
                    not "html" in str(mimetype[0])
                    and not "application/xhtml+xml" in str(mimetype[0])
                    and not "application/xml" in str(mimetype[0])
                ):
                    copy_list.append({"src": fullpath, "dest": filename})
                    continue

                if root.endswith("resources"):
                    copy_list.append({"src": fullpath, "dest": filename})
                    continue

                test_parser = TestParser(vars(self.options), filename=fullpath)
                test_info = test_parser.analyze_test()
                if test_info is None:
                    continue

                if "reference" in test_info.keys():
                    reftests += 1
                    total_tests += 1
                    test_basename = os.path.basename(test_info["test"])

                    # Add the ref file, following WebKit style.
                    # FIXME: Ideally we'd support reading the metadata
                    # directly rather than relying  on a naming convention.
                    # Using a naming convention creates duplicate copies of the
                    # reference files.
                    ref_file = os.path.splitext(test_basename)[0] + "-expected"
                    # Make sure to use the extension from the *reference*, not
                    # from the test, because at least flexbox tests use XHTML
                    # references but HTML tests.
                    ref_file += os.path.splitext(test_info["reference"])[1]

                    copy_list.append(
                        {
                            "src": test_info["reference"],
                            "dest": ref_file,
                            "reference_support_info": test_info["reference_support_info"],
                        }
                    )
                    copy_list.append({"src": test_info["test"], "dest": filename})

                elif "jstest" in test_info.keys():
                    jstests += 1
                    total_tests += 1
                    copy_list.append({"src": fullpath, "dest": filename})
                else:
                    total_tests += 1
                    copy_list.append({"src": fullpath, "dest": filename})

            if copy_list:
                # Only add this directory to the list if there's something to import
                self.import_list.append(
                    {
                        "dirname": root,
                        "copy_list": copy_list,
                        "reftests": reftests,
                        "jstests": jstests,
                        "total_tests": total_tests,
                    }
                )
Esempio n. 47
0
    def find_importable_tests(self, directory):
        # FIXME: use filesystem
        for root, dirs, files in os.walk(directory):
            print 'Scanning ' + root + '...'
            total_tests = 0
            reftests = 0
            jstests = 0

            # Ignore any repo stuff
            if '.git' in dirs:
                dirs.remove('.git')
            if '.hg' in dirs:
                dirs.remove('.hg')

            # archive and data dirs are internal csswg things that live in every approved directory
            if 'data' in dirs:
                dirs.remove('data')
            if 'archive' in dirs:
                dirs.remove('archive')

            copy_list = []

            for filename in files:
                # FIXME: This block should really be a separate function, but the early-continues make that difficult.

                if filename.startswith('.') or filename.endswith('.pl'):
                    continue  # For some reason the w3c repo contains random perl scripts we don't care about.

                fullpath = os.path.join(root, filename)

                mimetype = mimetypes.guess_type(fullpath)
                if not 'html' in str(mimetype[0]) and not 'xml' in str(
                        mimetype[0]):
                    copy_list.append({'src': fullpath, 'dest': filename})
                    continue

                test_parser = TestParser(vars(self.options), filename=fullpath)
                test_info = test_parser.analyze_test()
                if test_info is None:
                    continue

                if 'reference' in test_info.keys():
                    reftests += 1
                    total_tests += 1
                    test_basename = os.path.basename(test_info['test'])

                    # Add the ref file, following WebKit style.
                    # FIXME: Ideally we'd support reading the metadata
                    # directly rather than relying  on a naming convention.
                    # Using a naming convention creates duplicate copies of the
                    # reference files.
                    ref_file = os.path.splitext(test_basename)[0] + '-expected'
                    ref_file += os.path.splitext(test_basename)[1]

                    copy_list.append({
                        'src': test_info['reference'],
                        'dest': ref_file
                    })
                    copy_list.append({
                        'src': test_info['test'],
                        'dest': filename
                    })

                    # Update any support files that need to move as well to remain relative to the -expected file.
                    if 'refsupport' in test_info.keys():
                        for support_file in test_info['refsupport']:
                            source_file = os.path.join(
                                os.path.dirname(test_info['reference']),
                                support_file)
                            source_file = os.path.normpath(source_file)

                            # Keep the dest as it was
                            to_copy = {
                                'src': source_file,
                                'dest': support_file
                            }

                            # Only add it once
                            if not (to_copy in copy_list):
                                copy_list.append(to_copy)
                elif 'jstest' in test_info.keys():
                    jstests += 1
                    total_tests += 1
                    copy_list.append({'src': fullpath, 'dest': filename})
                else:
                    total_tests += 1
                    copy_list.append({'src': fullpath, 'dest': filename})

            if not total_tests:
                # We can skip the support directory if no tests were found.
                if 'support' in dirs:
                    dirs.remove('support')

                if copy_list:
                    # Only add this directory to the list if there's something to import
                    self.import_list.append({
                        'dirname': root,
                        'copy_list': copy_list,
                        'reftests': reftests,
                        'jstests': jstests,
                        'total_tests': total_tests
                    })
Esempio n. 48
0
    def find_importable_tests(self, directory):
        # FIXME: use filesystem
        paths_to_skip = self.find_paths_to_skip()

        for root, dirs, files in os.walk(directory):
            cur_dir = root.replace(self.layout_tests_dir + '/', '') + '/'
            _log.info('Scanning ' + cur_dir + '...')
            total_tests = 0
            reftests = 0
            jstests = 0

            # "archive" and "data" dirs are internal csswg things that live in every approved directory.
            # FIXME: skip 'incoming' tests for now, but we should rework the 'test_status' concept and
            # support reading them as well.
            DIRS_TO_SKIP = ('.git', '.hg', 'data', 'archive', 'incoming')
            if dirs:
                for d in DIRS_TO_SKIP:
                    if d in dirs:
                        dirs.remove(d)

                for path in paths_to_skip:
                    path_base = path.replace(cur_dir, '')
                    path_full = self.filesystem.join(root, path_base)
                    if path_base in dirs:
                        dirs.remove(path_base)
                        if not self.options.dry_run and self.import_in_place:
                            _log.info("Pruning %s" % path_full)
                            self.filesystem.rmtree(path_full)

            copy_list = []

            for filename in files:
                path_full = self.filesystem.join(root, filename)
                path_base = path_full.replace(self.layout_tests_dir + '/', '')
                if path_base in paths_to_skip:
                    if not self.options.dry_run and self.import_in_place:
                        _log.info("Pruning %s" % path_base)
                        self.filesystem.remove(path_full)
                        continue
                # FIXME: This block should really be a separate function, but the early-continues make that difficult.

                if filename.startswith('.') or filename.endswith('.pl'):
                    continue  # For some reason the w3c repo contains random perl scripts we don't care about.

                fullpath = os.path.join(root, filename)

                mimetype = mimetypes.guess_type(fullpath)
                if not 'html' in str(mimetype[0]) and not 'xml' in str(
                        mimetype[0]):
                    copy_list.append({'src': fullpath, 'dest': filename})
                    continue

                if root.endswith('resources'):
                    copy_list.append({'src': fullpath, 'dest': filename})
                    continue

                test_parser = TestParser(vars(self.options), filename=fullpath)
                test_info = test_parser.analyze_test()
                if test_info is None:
                    continue

                if 'reference' in test_info.keys():
                    reftests += 1
                    total_tests += 1
                    test_basename = os.path.basename(test_info['test'])

                    # Add the ref file, following WebKit style.
                    # FIXME: Ideally we'd support reading the metadata
                    # directly rather than relying  on a naming convention.
                    # Using a naming convention creates duplicate copies of the
                    # reference files.
                    ref_file = os.path.splitext(test_basename)[0] + '-expected'
                    ref_file += os.path.splitext(test_basename)[1]

                    copy_list.append({
                        'src': test_info['reference'],
                        'dest': ref_file
                    })
                    copy_list.append({
                        'src': test_info['test'],
                        'dest': filename
                    })

                    # Update any support files that need to move as well to remain relative to the -expected file.
                    if 'refsupport' in test_info.keys():
                        for support_file in test_info['refsupport']:
                            source_file = os.path.join(
                                os.path.dirname(test_info['reference']),
                                support_file)
                            source_file = os.path.normpath(source_file)

                            # Keep the dest as it was
                            to_copy = {
                                'src': source_file,
                                'dest': support_file
                            }

                            # Only add it once
                            if not (to_copy in copy_list):
                                copy_list.append(to_copy)
                elif 'jstest' in test_info.keys():
                    jstests += 1
                    total_tests += 1
                    copy_list.append({'src': fullpath, 'dest': filename})
                else:
                    total_tests += 1
                    copy_list.append({'src': fullpath, 'dest': filename})

            if not total_tests:
                # We can skip the support directory if no tests were found.
                if 'support' in dirs:
                    dirs.remove('support')

            if copy_list:
                # Only add this directory to the list if there's something to import
                self.import_list.append({
                    'dirname': root,
                    'copy_list': copy_list,
                    'reftests': reftests,
                    'jstests': jstests,
                    'total_tests': total_tests
                })
Esempio n. 49
0
    def find_importable_tests(self, directory):
        def should_keep_subdir(filesystem, path):
            if self._importing_downloaded_tests:
                return True
            subdir = path[len(directory):]
            DIRS_TO_SKIP = ('work-in-progress', 'tools', 'support')
            should_skip = filesystem.basename(subdir).startswith('.') or (
                subdir in DIRS_TO_SKIP)
            return not should_skip

        directories = self.filesystem.dirs_under(directory, should_keep_subdir)
        for root in directories:
            _log.info('Scanning ' + root + '...')
            total_tests = 0
            reftests = 0
            jstests = 0

            copy_list = []

            for filename in self.filesystem.listdir(root):
                if self.filesystem.isdir(self.filesystem.join(root, filename)):
                    continue
                # FIXME: This block should really be a separate function, but the early-continues make that difficult.

                if self.should_skip_file(filename):
                    continue

                fullpath = self.filesystem.join(root, filename)

                mimetype = mimetypes.guess_type(fullpath)
                if not 'html' in str(
                        mimetype[0]) and not 'application/xhtml+xml' in str(
                            mimetype[0]) and not 'application/xml' in str(
                                mimetype[0]):
                    copy_list.append({'src': fullpath, 'dest': filename})
                    continue

                test_parser = TestParser(vars(self.options),
                                         filename=fullpath,
                                         host=self.host)
                test_info = test_parser.analyze_test()
                if test_info is None:
                    # This is probably a resource file, but we should generate WPT manifest instead and get the list of resource files from it.
                    if not self._is_in_resources_directory(fullpath):
                        self._potential_test_resource_files.append(fullpath)
                    copy_list.append({'src': fullpath, 'dest': filename})
                    continue
                elif self._is_in_resources_directory(fullpath):
                    _log.warning(
                        '%s is a test located in a "resources" folder. This test will be skipped by WebKit test runners.',
                        fullpath)

                if 'manualtest' in test_info.keys():
                    continue

                if 'slow' in test_info:
                    self._slow_tests.append(fullpath)

                if 'referencefile' in test_info.keys():
                    # Skip it since, the corresponding reference test should have a link to this file
                    continue

                if 'reference' in test_info.keys():
                    reftests += 1
                    total_tests += 1
                    test_basename = self.filesystem.basename(test_info['test'])

                    # Add the ref file, following WebKit style.
                    # FIXME: Ideally we'd support reading the metadata
                    # directly rather than relying  on a naming convention.
                    # Using a naming convention creates duplicate copies of the
                    # reference files.
                    ref_file = self.filesystem.splitext(
                        test_basename)[0] + '-expected'
                    ref_file += self.filesystem.splitext(
                        test_info['reference'])[1]

                    copy_list.append({
                        'src':
                        test_info['reference'],
                        'dest':
                        ref_file,
                        'reference_support_info':
                        test_info['reference_support_info']
                    })
                    copy_list.append({
                        'src': test_info['test'],
                        'dest': filename
                    })

                elif 'jstest' in test_info.keys():
                    jstests += 1
                    total_tests += 1
                    copy_list.append({'src': fullpath, 'dest': filename})
                else:
                    total_tests += 1
                    copy_list.append({'src': fullpath, 'dest': filename})

            if copy_list:
                # Only add this directory to the list if there's something to import
                self.import_list.append({
                    'dirname': root,
                    'copy_list': copy_list,
                    'reftests': reftests,
                    'jstests': jstests,
                    'total_tests': total_tests
                })
Esempio n. 50
0
 def test_analyze_non_html_file(self):
     """ Tests analyze_test() with a file that has no html"""
     # FIXME: use a mock filesystem
     parser = TestParser(options, os.path.join(os.path.dirname(__file__), 'test_parser.py'))
     test_info = parser.analyze_test()
     self.assertEqual(test_info, None, 'no tests should have been found in this file')
Esempio n. 51
0
    def find_importable_tests(self, directory):
        def should_keep_subdir(filesystem, path):
            if self._importing_downloaded_tests:
                return True
            subdir = path[len(directory) :]
            DIRS_TO_SKIP = ("work-in-progress", "tools", "support")
            should_skip = filesystem.basename(subdir).startswith(".") or (subdir in DIRS_TO_SKIP)
            return not should_skip

        directories = self.filesystem.dirs_under(directory, should_keep_subdir)
        for root in directories:
            _log.info("Scanning " + root + "...")
            total_tests = 0
            reftests = 0
            jstests = 0

            copy_list = []

            for filename in self.filesystem.listdir(root):
                if self.filesystem.isdir(self.filesystem.join(root, filename)):
                    continue
                # FIXME: This block should really be a separate function, but the early-continues make that difficult.

                if self.should_skip_file(filename):
                    continue

                fullpath = self.filesystem.join(root, filename)

                mimetype = mimetypes.guess_type(fullpath)
                if (
                    not "html" in str(mimetype[0])
                    and not "application/xhtml+xml" in str(mimetype[0])
                    and not "application/xml" in str(mimetype[0])
                ):
                    copy_list.append({"src": fullpath, "dest": filename})
                    continue

                test_parser = TestParser(vars(self.options), filename=fullpath, host=self.host)
                test_info = test_parser.analyze_test()
                if test_info is None:
                    # This is probably a resource file.
                    if self.filesystem.basename(self.filesystem.dirname(fullpath)) != "resources":
                        self._potential_test_resource_files.append({"src": fullpath, "dest": filename})
                    copy_list.append({"src": fullpath, "dest": filename})
                    continue

                if "manualtest" in test_info.keys():
                    continue

                if "referencefile" in test_info.keys():
                    # Skip it since, the corresponding reference test should have a link to this file
                    continue

                if "reference" in test_info.keys():
                    reftests += 1
                    total_tests += 1
                    test_basename = self.filesystem.basename(test_info["test"])

                    # Add the ref file, following WebKit style.
                    # FIXME: Ideally we'd support reading the metadata
                    # directly rather than relying  on a naming convention.
                    # Using a naming convention creates duplicate copies of the
                    # reference files.
                    ref_file = self.filesystem.splitext(test_basename)[0] + "-expected"
                    ref_file += self.filesystem.splitext(test_info["reference"])[1]

                    copy_list.append(
                        {
                            "src": test_info["reference"],
                            "dest": ref_file,
                            "reference_support_info": test_info["reference_support_info"],
                        }
                    )
                    copy_list.append({"src": test_info["test"], "dest": filename})

                elif "jstest" in test_info.keys():
                    jstests += 1
                    total_tests += 1
                    copy_list.append({"src": fullpath, "dest": filename})
                else:
                    total_tests += 1
                    copy_list.append({"src": fullpath, "dest": filename})

            if copy_list:
                # Only add this directory to the list if there's something to import
                self.import_list.append(
                    {
                        "dirname": root,
                        "copy_list": copy_list,
                        "reftests": reftests,
                        "jstests": jstests,
                        "total_tests": total_tests,
                    }
                )
Esempio n. 52
0
    def find_importable_tests(self, directory):
        paths_to_skip = self.find_paths_to_skip()

        for root, dirs, files in self.filesystem.walk(directory):
            cur_dir = root.replace(self.dir_above_repo + '/', '') + '/'
            _log.info('  scanning ' + cur_dir + '...')
            total_tests = 0
            reftests = 0
            jstests = 0

            # Files in 'tools' are not for browser testing (e.g., a script for generating test files).
            # http://testthewebforward.org/docs/test-format-guidelines.html#tools
            DIRS_TO_SKIP = ('.git', 'test-plan', 'tools')

            # Need to copy all files in 'support', including HTML without meta data.
            # http://testthewebforward.org/docs/test-format-guidelines.html#support-files
            DIRS_TO_INCLUDE = ('resources', 'support')

            if dirs:
                for d in DIRS_TO_SKIP:
                    if d in dirs:
                        dirs.remove(d)

                for path in paths_to_skip:
                    path_base = path.replace(self.options.destination + '/', '')
                    path_base = path_base.replace(cur_dir, '')
                    path_full = self.filesystem.join(root, path_base)
                    if path_base in dirs:
                        dirs.remove(path_base)
                        if not self.options.dry_run and self.import_in_place:
                            _log.info("  pruning %s" % path_base)
                            self.filesystem.rmtree(path_full)
                        else:
                            _log.info("  skipping %s" % path_base)

            copy_list = []

            for filename in files:
                path_full = self.filesystem.join(root, filename)
                path_base = path_full.replace(directory + '/', '')
                path_base = self.destination_directory.replace(self.layout_tests_dir + '/', '') + '/' + path_base
                if path_base in paths_to_skip:
                    if not self.options.dry_run and self.import_in_place:
                        _log.info("  pruning %s" % path_base)
                        self.filesystem.remove(path_full)
                        continue
                    else:
                        continue
                # FIXME: This block should really be a separate function, but the early-continues make that difficult.

                if filename.startswith('.') or filename.endswith('.pl'):
                    continue  # For some reason the w3c repo contains random perl scripts we don't care about.

                fullpath = self.filesystem.join(root, filename)

                mimetype = mimetypes.guess_type(fullpath)
                if not 'html' in str(mimetype[0]) and not 'application/xhtml+xml' in str(mimetype[0]) and not 'application/xml' in str(mimetype[0]):
                    copy_list.append({'src': fullpath, 'dest': filename})
                    continue

                if self.filesystem.basename(root) in DIRS_TO_INCLUDE:
                    copy_list.append({'src': fullpath, 'dest': filename})
                    continue

                test_parser = TestParser(vars(self.options), filename=fullpath)
                test_info = test_parser.analyze_test()
                if test_info is None:
                    continue

                if 'reference' in test_info.keys():
                    reftests += 1
                    total_tests += 1
                    test_basename = self.filesystem.basename(test_info['test'])

                    # Add the ref file, following WebKit style.
                    # FIXME: Ideally we'd support reading the metadata
                    # directly rather than relying  on a naming convention.
                    # Using a naming convention creates duplicate copies of the
                    # reference files.
                    ref_file = self.filesystem.splitext(test_basename)[0] + '-expected'
                    # Make sure to use the extension from the *reference*, not
                    # from the test, because at least flexbox tests use XHTML
                    # references but HTML tests.
                    ref_file += self.filesystem.splitext(test_info['reference'])[1]

                    copy_list.append({'src': test_info['reference'], 'dest': ref_file,
                                      'reference_support_info': test_info['reference_support_info']})
                    copy_list.append({'src': test_info['test'], 'dest': filename})

                elif 'jstest' in test_info.keys():
                    jstests += 1
                    total_tests += 1
                    copy_list.append({'src': fullpath, 'dest': filename})
                else:
                    total_tests += 1
                    copy_list.append({'src': fullpath, 'dest': filename})

            if copy_list:
                # Only add this directory to the list if there's something to import
                self.import_list.append({'dirname': root, 'copy_list': copy_list,
                                         'reftests': reftests, 'jstests': jstests, 'total_tests': total_tests})
Esempio n. 53
0
    def find_importable_tests(self):
        """Walks through the source directory to find what tests should be imported.

        This function sets self.import_list, which contains information about how many
        tests are being imported, and their source and destination paths.
        """
        paths_to_skip = self.find_paths_to_skip()

        for root, dirs, files in self.filesystem.walk(self.source_repo_path):
            cur_dir = root.replace(self.dir_above_repo + '/', '') + '/'
            _log.info('  scanning ' + cur_dir + '...')
            total_tests = 0
            reftests = 0
            jstests = 0

            # Files in 'tools' are not for browser testing, so we skip them.
            # See: http://testthewebforward.org/docs/test-format-guidelines.html#tools
            DIRS_TO_SKIP = ('.git', 'test-plan', 'tools')

            # We copy all files in 'support', including HTML without metadata.
            # See: http://testthewebforward.org/docs/test-format-guidelines.html#support-files
            DIRS_TO_INCLUDE = ('resources', 'support')

            if dirs:
                for d in DIRS_TO_SKIP:
                    if d in dirs:
                        dirs.remove(d)

                for path in paths_to_skip:
                    path_base = path.replace(self.options.destination + '/', '')
                    path_base = path_base.replace(cur_dir, '')
                    path_full = self.filesystem.join(root, path_base)
                    if path_base in dirs:
                        dirs.remove(path_base)
                        if not self.options.dry_run and self.import_in_place:
                            _log.info("  pruning %s", path_base)
                            self.filesystem.rmtree(path_full)
                        else:
                            _log.info("  skipping %s", path_base)

            copy_list = []

            for filename in files:
                path_full = self.filesystem.join(root, filename)
                path_base = path_full.replace(self.source_repo_path + '/', '')
                path_base = self.destination_directory.replace(self.layout_tests_dir + '/', '') + '/' + path_base
                if path_base in paths_to_skip:
                    if not self.options.dry_run and self.import_in_place:
                        _log.info("  pruning %s", path_base)
                        self.filesystem.remove(path_full)
                        continue
                    else:
                        continue
                # FIXME: This block should really be a separate function, but the early-continues make that difficult.

                if filename.startswith('.') or filename.endswith('.pl'):
                    # The w3cs repos may contain perl scripts, which we don't care about.
                    continue
                if filename == 'OWNERS' or filename == 'reftest.list':
                    # These files fail our presubmits.
                    # See http://crbug.com/584660 and http://crbug.com/582838.
                    continue

                fullpath = self.filesystem.join(root, filename)

                mimetype = mimetypes.guess_type(fullpath)
                if ('html' not in str(mimetype[0]) and
                        'application/xhtml+xml' not in str(mimetype[0]) and
                        'application/xml' not in str(mimetype[0])):
                    copy_list.append({'src': fullpath, 'dest': filename})
                    continue

                if self.filesystem.basename(root) in DIRS_TO_INCLUDE:
                    copy_list.append({'src': fullpath, 'dest': filename})
                    continue

                test_parser = TestParser(fullpath, self.host)
                test_info = test_parser.analyze_test()
                if test_info is None:
                    copy_list.append({'src': fullpath, 'dest': filename})
                    continue

                if self.path_too_long(path_full):
                    _log.warning('%s skipped due to long path. '
                                 'Max length from repo base %d chars; see http://crbug.com/609871.',
                                 path_full, MAX_PATH_LENGTH)
                    continue

                if 'reference' in test_info.keys():
                    test_basename = self.filesystem.basename(test_info['test'])
                    # Add the ref file, following WebKit style.
                    # FIXME: Ideally we'd support reading the metadata
                    # directly rather than relying on a naming convention.
                    # Using a naming convention creates duplicate copies of the
                    # reference files (http://crrev.com/268729).
                    ref_file = self.filesystem.splitext(test_basename)[0] + '-expected'
                    # Make sure to use the extension from the *reference*, not
                    # from the test, because at least flexbox tests use XHTML
                    # references but HTML tests.
                    ref_file += self.filesystem.splitext(test_info['reference'])[1]

                    if not self.filesystem.exists(test_info['reference']):
                        _log.warning('%s skipped because ref file %s was not found.',
                                     path_full, ref_file)
                        continue

                    if self.path_too_long(path_full.replace(filename, ref_file)):
                        _log.warning('%s skipped because path of ref file %s would be too long. '
                                     'Max length from repo base %d chars; see http://crbug.com/609871.',
                                     path_full, ref_file, MAX_PATH_LENGTH)
                        continue

                    reftests += 1
                    total_tests += 1
                    copy_list.append({'src': test_info['reference'], 'dest': ref_file,
                                      'reference_support_info': test_info['reference_support_info']})
                    copy_list.append({'src': test_info['test'], 'dest': filename})

                elif 'jstest' in test_info.keys():
                    jstests += 1
                    total_tests += 1
                    copy_list.append({'src': fullpath, 'dest': filename, 'is_jstest': True})

                elif self.options.all:
                    total_tests += 1
                    copy_list.append({'src': fullpath, 'dest': filename})

            if copy_list:
                # Only add this directory to the list if there's something to import
                self.import_list.append({'dirname': root, 'copy_list': copy_list,
                                         'reftests': reftests, 'jstests': jstests, 'total_tests': total_tests})
Esempio n. 54
0
    def find_importable_tests(self, directory):
        # FIXME: use filesystem
        paths_to_skip = self.find_paths_to_skip()

        for root, dirs, files in os.walk(directory):
            cur_dir = root.replace(self.dir_above_repo + '/', '') + '/'
            _log.info('  scanning ' + cur_dir + '...')
            total_tests = 0
            reftests = 0
            jstests = 0

            DIRS_TO_SKIP = ('.git', '.hg')
            if dirs:
                for d in DIRS_TO_SKIP:
                    if d in dirs:
                        dirs.remove(d)

                for path in paths_to_skip:
                    path_base = path.replace(self.options.destination + '/',
                                             '')
                    path_base = path_base.replace(cur_dir, '')
                    path_full = self.filesystem.join(root, path_base)
                    if path_base in dirs:
                        dirs.remove(path_base)
                        if not self.options.dry_run and self.import_in_place:
                            _log.info("  pruning %s" % path_base)
                            self.filesystem.rmtree(path_full)
                        else:
                            _log.info("  skipping %s" % path_base)

            copy_list = []

            for filename in files:
                path_full = self.filesystem.join(root, filename)
                path_base = path_full.replace(directory + '/', '')
                path_base = self.destination_directory.replace(
                    self.layout_tests_dir + '/', '') + '/' + path_base
                if path_base in paths_to_skip:
                    if not self.options.dry_run and self.import_in_place:
                        _log.info("  pruning %s" % path_base)
                        self.filesystem.remove(path_full)
                        continue
                    else:
                        continue
                # FIXME: This block should really be a separate function, but the early-continues make that difficult.

                if filename.startswith('.') or filename.endswith('.pl'):
                    continue  # For some reason the w3c repo contains random perl scripts we don't care about.

                fullpath = os.path.join(root, filename)

                mimetype = mimetypes.guess_type(fullpath)
                if not 'html' in str(
                        mimetype[0]) and not 'application/xhtml+xml' in str(
                            mimetype[0]) and not 'application/xml' in str(
                                mimetype[0]):
                    copy_list.append({'src': fullpath, 'dest': filename})
                    continue

                if root.endswith('resources'):
                    copy_list.append({'src': fullpath, 'dest': filename})
                    continue

                test_parser = TestParser(vars(self.options), filename=fullpath)
                test_info = test_parser.analyze_test()
                if test_info is None:
                    continue

                if 'reference' in test_info.keys():
                    reftests += 1
                    total_tests += 1
                    test_basename = os.path.basename(test_info['test'])

                    # Add the ref file, following WebKit style.
                    # FIXME: Ideally we'd support reading the metadata
                    # directly rather than relying  on a naming convention.
                    # Using a naming convention creates duplicate copies of the
                    # reference files.
                    ref_file = os.path.splitext(test_basename)[0] + '-expected'
                    ref_file += os.path.splitext(test_basename)[1]

                    copy_list.append({
                        'src':
                        test_info['reference'],
                        'dest':
                        ref_file,
                        'reference_support_info':
                        test_info['reference_support_info']
                    })
                    copy_list.append({
                        'src': test_info['test'],
                        'dest': filename
                    })

                elif 'jstest' in test_info.keys():
                    jstests += 1
                    total_tests += 1
                    copy_list.append({'src': fullpath, 'dest': filename})
                else:
                    total_tests += 1
                    copy_list.append({'src': fullpath, 'dest': filename})

            if copy_list:
                # Only add this directory to the list if there's something to import
                self.import_list.append({
                    'dirname': root,
                    'copy_list': copy_list,
                    'reftests': reftests,
                    'jstests': jstests,
                    'total_tests': total_tests
                })
Esempio n. 55
0
    def find_importable_tests(self, directory):
        # FIXME: use filesystem
        for root, dirs, files in os.walk(directory):
            print 'Scanning ' + root + '...'
            total_tests = 0
            reftests = 0
            jstests = 0

            # Ignore any repo stuff
            if '.git' in dirs:
                dirs.remove('.git')
            if '.hg' in dirs:
                dirs.remove('.hg')

            # archive and data dirs are internal csswg things that live in every approved directory
            if 'data' in dirs:
                dirs.remove('data')
            if 'archive' in dirs:
                dirs.remove('archive')

            copy_list = []

            for filename in files:
                # FIXME: This block should really be a separate function, but the early-continues make that difficult.

                if filename.startswith('.') or filename.endswith('.pl'):
                    continue  # For some reason the w3c repo contains random perl scripts we don't care about.

                fullpath = os.path.join(root, filename)

                mimetype = mimetypes.guess_type(fullpath)
                if not 'html' in str(mimetype[0]) and not 'xml' in str(mimetype[0]):
                    copy_list.append({'src': fullpath, 'dest': filename})
                    continue

                test_parser = TestParser(vars(self.options), filename=fullpath)
                test_info = test_parser.analyze_test()
                if test_info is None:
                    continue

                if 'reference' in test_info.keys():
                    reftests += 1
                    total_tests += 1
                    test_basename = os.path.basename(test_info['test'])

                    # Add the ref file, following WebKit style.
                    # FIXME: Ideally we'd support reading the metadata
                    # directly rather than relying  on a naming convention.
                    # Using a naming convention creates duplicate copies of the
                    # reference files.
                    ref_file = os.path.splitext(test_basename)[0] + '-expected'
                    ref_file += os.path.splitext(test_basename)[1]

                    copy_list.append({'src': test_info['reference'], 'dest': ref_file})
                    copy_list.append({'src': test_info['test'], 'dest': filename})

                    # Update any support files that need to move as well to remain relative to the -expected file.
                    if 'refsupport' in test_info.keys():
                        for support_file in test_info['refsupport']:
                            source_file = os.path.join(os.path.dirname(test_info['reference']), support_file)
                            source_file = os.path.normpath(source_file)

                            # Keep the dest as it was
                            to_copy = {'src': source_file, 'dest': support_file}

                            # Only add it once
                            if not(to_copy in copy_list):
                                copy_list.append(to_copy)
                elif 'jstest' in test_info.keys():
                    jstests += 1
                    total_tests += 1
                    copy_list.append({'src': fullpath, 'dest': filename})
                else:
                    total_tests += 1
                    copy_list.append({'src': fullpath, 'dest': filename})

            if not total_tests:
                # We can skip the support directory if no tests were found.
                if 'support' in dirs:
                    dirs.remove('support')

                if copy_list:
                    # Only add this directory to the list if there's something to import
                    self.import_list.append({'dirname': root, 'copy_list': copy_list,
                        'reftests': reftests, 'jstests': jstests, 'total_tests': total_tests})
Esempio n. 56
0
    def find_importable_tests(self):
        """Walks through the source directory to find what tests should be imported.

        This function sets self.import_list, which contains information about how many
        tests are being imported, and their source and destination paths.
        """
        paths_to_skip = self.find_paths_to_skip()

        for root, dirs, files in self.filesystem.walk(self.source_repo_path):
            cur_dir = root.replace(self.dir_above_repo + '/', '') + '/'
            _log.debug('Scanning %s...', cur_dir)
            total_tests = 0
            reftests = 0
            jstests = 0

            # Files in 'tools' are not for browser testing, so we skip them.
            # See: http://testthewebforward.org/docs/test-format-guidelines.html#tools
            dirs_to_skip = ('.git', 'test-plan', 'tools')

            # We copy all files in 'support', including HTML without metadata.
            # See: http://testthewebforward.org/docs/test-format-guidelines.html#support-files
            dirs_to_include = ('resources', 'support')

            if dirs:
                for name in dirs_to_skip:
                    if name in dirs:
                        dirs.remove(name)

                for path in paths_to_skip:
                    path_base = path.replace(self.dest_dir_name + '/', '')
                    path_base = path_base.replace(cur_dir, '')
                    path_full = self.filesystem.join(root, path_base)
                    if path_base in dirs:
                        _log.info('Skipping: %s', path_full)
                        dirs.remove(path_base)
                        if self.import_in_place:
                            self.filesystem.rmtree(path_full)

            copy_list = []

            for filename in files:
                path_full = self.filesystem.join(root, filename)
                path_base = path_full.replace(self.source_repo_path + '/', '')
                path_base = self.destination_directory.replace(
                    self.layout_tests_dir + '/', '') + '/' + path_base
                if path_base in paths_to_skip:
                    if self.import_in_place:
                        _log.debug('Pruning: %s', path_base)
                        self.filesystem.remove(path_full)
                        continue
                    else:
                        continue
                # FIXME: This block should really be a separate function, but the early-continues make that difficult.

                if filename.startswith('.') or filename.endswith('.pl'):
                    _log.info('Skipping: %s', path_full)
                    _log.info(
                        '  Reason: Hidden files and perl scripts are not necessary.'
                    )
                    continue
                if filename == 'OWNERS' or filename == 'reftest.list':
                    # See http://crbug.com/584660 and http://crbug.com/582838.
                    _log.info('Skipping: %s', path_full)
                    _log.info(
                        '  Reason: This file may cause Chromium presubmit to fail.'
                    )
                    continue
                if self.path_too_long(path_full):
                    _log.warning('Skipping: %s', path_full)
                    _log.warning(
                        '  Reason: Long path. Max length %d; see http://crbug.com/609871.',
                        MAX_PATH_LENGTH)
                    continue

                mimetype = mimetypes.guess_type(path_full)
                if ('html' not in str(mimetype[0])
                        and 'application/xhtml+xml' not in str(mimetype[0])
                        and 'application/xml' not in str(mimetype[0])):
                    copy_list.append({'src': path_full, 'dest': filename})
                    continue

                if self.filesystem.basename(root) in dirs_to_include:
                    copy_list.append({'src': path_full, 'dest': filename})
                    continue

                test_parser = TestParser(path_full, self.host)
                test_info = test_parser.analyze_test()
                if test_info is None:
                    copy_list.append({'src': path_full, 'dest': filename})
                    continue

                if 'reference' in test_info.keys():
                    ref_path_full = test_info['reference']
                    if not self.filesystem.exists(ref_path_full):
                        _log.warning('Skipping: %s', path_full)
                        _log.warning('  Reason: Ref file "%s" was not found.',
                                     ref_path_full)
                        continue

                    if self.is_wpt:
                        if self.path_too_long(ref_path_full):
                            _log.warning('Skipping: %s', path_full)
                            _log.warning(
                                '  Reason: Ref file path length would be too long: %s.',
                                ref_path_full)
                            _log.warning(
                                '  Max length %d; see http://crbug.com/609871.',
                                MAX_PATH_LENGTH)
                            continue
                        # For WPT, we don't need to rename the reference file to
                        # WebKit style name.
                        # We don't ask to copy ref_path_full here because this
                        # filesystem walk will find the reference file, and copy
                        # it as a non-test file.
                    else:
                        test_basename = self.filesystem.basename(
                            test_info['test'])
                        # Add the ref file, following WebKit style.
                        # FIXME: Ideally we'd support reading the metadata
                        # directly rather than relying on a naming convention.
                        # Using a naming convention creates duplicate copies of the
                        # reference files (http://crrev.com/268729).
                        ref_file = self.filesystem.splitext(
                            test_basename)[0] + '-expected'
                        # Make sure to use the extension from the *reference*, not
                        # from the test, because at least flexbox tests use XHTML
                        # references but HTML tests.
                        ref_file += self.filesystem.splitext(ref_path_full)[1]

                        if self.path_too_long(
                                path_full.replace(filename, ref_file)):
                            _log.warning('Skipping: %s', path_full)
                            _log.warning(
                                '  Reason: Ref file path length would be too long: %s.',
                                ref_file)
                            _log.warning(
                                '  Max length %d; see http://crbug.com/609871.',
                                MAX_PATH_LENGTH)
                            continue
                        copy_list.append({
                            'src':
                            test_info['reference'],
                            'dest':
                            ref_file,
                            'reference_support_info':
                            test_info['reference_support_info']
                        })

                    reftests += 1
                    total_tests += 1
                    copy_list.append({
                        'src': test_info['test'],
                        'dest': filename
                    })

                elif 'jstest' in test_info.keys():
                    jstests += 1
                    total_tests += 1
                    copy_list.append({
                        'src': path_full,
                        'dest': filename,
                        'is_jstest': True
                    })

            if copy_list:
                # Only add this directory to the list if there's something to import
                self.import_list.append({
                    'dirname': root,
                    'copy_list': copy_list,
                    'reftests': reftests,
                    'jstests': jstests,
                    'total_tests': total_tests
                })
Esempio n. 57
0
 def test_load_file_with_non_ascii_tags(self):
     host = MockHost()
     host.filesystem.files['/some/path.xml'] = '<d\xc3\x98dd></d\xc3\x98dd>'
     parser = TestParser('/some/path.xml', host)
     self.assertEqual(parser.filename, '/some/path.xml')
     self.assertIsNone(parser.test_doc)