def test_delete_entries(self): fs = MockFileSystem() fs.write_text_file(self._changelog_path, self._example_changelog) ChangeLog(self._changelog_path, fs).delete_entries(8) actual_contents = fs.read_text_file(self._changelog_path) expected_contents = """2011-10-11 Antti Koivisto <*****@*****.**> Resolve regular and visited link style in a single pass https://bugs.webkit.org/show_bug.cgi?id=69838 Reviewed by Darin Adler We can simplify and speed up selector matching by removing the recursive matching done to generate the style for the :visited pseudo selector. Both regular and visited link style can be generated in a single pass through the style selector. == Rolled over to ChangeLog-2009-06-16 == """ self.assertEqual(actual_contents.splitlines(), expected_contents.splitlines()) ChangeLog(self._changelog_path, fs).delete_entries(2) actual_contents = fs.read_text_file(self._changelog_path) expected_contents = "== Rolled over to ChangeLog-2009-06-16 ==\n" self.assertEqual(actual_contents.splitlines(), expected_contents.splitlines())
def test_prepend_text(self): fs = MockFileSystem() fs.write_text_file(self._changelog_path, self._example_changelog) ChangeLog(self._changelog_path, fs).prepend_text(self._example_entry + "\n") actual_contents = fs.read_text_file(self._changelog_path) expected_contents = self._example_entry + "\n" + self._example_changelog self.assertEqual(actual_contents.splitlines(), expected_contents.splitlines())
def test_set_short_description_and_bug_url(self): fs = MockFileSystem() changelog_contents = u"%s\n%s" % ( self._new_entry_boilerplate_with_bugurl, self._example_changelog) fs.write_text_file(self._changelog_path, changelog_contents) short_description = "A short description" bug_url = "http://example.com/b/2344" ChangeLog(self._changelog_path, fs).set_short_description_and_bug_url( short_description, bug_url) actual_contents = fs.read_text_file(self._changelog_path) expected_contents = changelog_contents.replace( "Need a short description (OOPS!).", short_description) self.assertEqual(actual_contents.splitlines(), expected_contents.splitlines()) changelog_contents = u"%s\n%s" % (self._new_entry_boilerplate, self._example_changelog) fs.write_text_file(self._changelog_path, changelog_contents) short_description = "A short description 2" bug_url = "http://example.com/b/2345" ChangeLog(self._changelog_path, fs).set_short_description_and_bug_url( short_description, bug_url) actual_contents = fs.read_text_file(self._changelog_path) expected_message = "%s\n %s" % (short_description, bug_url) expected_contents = changelog_contents.replace( "Need a short description (OOPS!).\n Need the bug URL (OOPS!).", expected_message) self.assertEqual(actual_contents.splitlines(), expected_contents.splitlines())
def test_expected_touched_test(self): paths = [ 'LayoutTests/test-expected.txt', 'LayoutTests/no-test-expected.txt' ] fs = MockFileSystem() fs.write_text_file('/test.checkout/LayoutTests/test.html', 'This is a test') fs, touched_tests = self.touched_files(paths, fs) self.assertItemsEqual(touched_tests, ['test.html'])
def test_platform_duplicate_touched_test(self): paths = [ 'LayoutTests/test1.html', 'LayoutTests/test1.html', 'LayoutTests/platform/mock1/test2-expected.txt', 'LayoutTests/platform/mock2/test2-expected.txt' ] fs = MockFileSystem() fs.write_text_file('/test.checkout/LayoutTests/test2.html', 'This is a test') fs, touched_tests = self.touched_files(paths, fs) self.assertItemsEqual(touched_tests, ['test1.html', 'test2.html'])
def test_set_reviewer(self): fs = MockFileSystem() changelog_contents = u"%s\n%s" % (self._new_entry_boilerplate_with_bugurl, self._example_changelog) reviewer_name = 'Test Reviewer' fs.write_text_file(self._changelog_path, changelog_contents) ChangeLog(self._changelog_path, fs).set_reviewer(reviewer_name) actual_contents = fs.read_text_file(self._changelog_path) expected_contents = changelog_contents.replace('NOBODY (OOPS!)', reviewer_name) self.assertEqual(actual_contents.splitlines(), expected_contents.splitlines()) changelog_contents = u"%s\n%s" % (self._new_entry_boilerplate_with_unreviewed, self._example_changelog) fs.write_text_file(self._changelog_path, changelog_contents) ChangeLog(self._changelog_path, fs).set_reviewer(reviewer_name) actual_contents = fs.read_text_file(self._changelog_path) self.assertEqual(actual_contents.splitlines(), changelog_contents.splitlines()) changelog_contents_without_reviewer_line = u"%s\n%s" % (self._new_entry_boilerplate_without_reviewer_line, self._example_changelog) fs.write_text_file(self._changelog_path, changelog_contents_without_reviewer_line) ChangeLog(self._changelog_path, fs).set_reviewer(reviewer_name) actual_contents = fs.read_text_file(self._changelog_path) self.assertEqual(actual_contents.splitlines(), expected_contents.splitlines()) changelog_contents_without_reviewer_line = u"%s\n%s" % (self._new_entry_boilerplate_without_reviewer_multiple_bugurl, self._example_changelog) fs.write_text_file(self._changelog_path, changelog_contents_without_reviewer_line) ChangeLog(self._changelog_path, fs).set_reviewer(reviewer_name) actual_contents = fs.read_text_file(self._changelog_path) changelog_contents = u"%s\n%s" % (self._new_entry_boilerplate_with_multiple_bugurl, self._example_changelog) expected_contents = changelog_contents.replace('NOBODY (OOPS!)', reviewer_name) self.assertEqual(actual_contents.splitlines(), expected_contents.splitlines())
def test_set_short_description_and_bug_url(self): fs = MockFileSystem() changelog_contents = u"%s\n%s" % (self._new_entry_boilerplate_with_bugurl, self._example_changelog) fs.write_text_file(self._changelog_path, changelog_contents) short_description = "A short description" bug_url = "http://example.com/b/2344" ChangeLog(self._changelog_path, fs).set_short_description_and_bug_url(short_description, bug_url) actual_contents = fs.read_text_file(self._changelog_path) expected_message = "%s\n %s" % (short_description, bug_url) expected_contents = changelog_contents.replace("Need a short description (OOPS!).", expected_message) self.assertEqual(actual_contents.splitlines(), expected_contents.splitlines()) changelog_contents = u"%s\n%s" % (self._new_entry_boilerplate, self._example_changelog) fs.write_text_file(self._changelog_path, changelog_contents) short_description = "A short description 2" bug_url = "http://example.com/b/2345" ChangeLog(self._changelog_path, fs).set_short_description_and_bug_url(short_description, bug_url) actual_contents = fs.read_text_file(self._changelog_path) expected_message = "%s\n %s" % (short_description, bug_url) expected_contents = changelog_contents.replace("Need a short description (OOPS!).\n Need the bug URL (OOPS!).", expected_message) self.assertEqual(actual_contents.splitlines(), expected_contents.splitlines())
def test_overrides_and_builder_names(self): port = self.make_port() filesystem = MockFileSystem() port._filesystem = filesystem port.path_from_chromium_base = lambda *comps: '/' + '/'.join(comps) chromium_overrides_path = port.path_from_chromium_base( 'webkit', 'tools', 'layout_tests', 'test_expectations.txt') CHROMIUM_OVERRIDES = 'contents of %s\n' % chromium_overrides_path filesystem.write_text_file(chromium_overrides_path, CHROMIUM_OVERRIDES) skia_overrides_path = port.path_from_chromium_base( 'skia', 'skia_test_expectations.txt') SKIA_OVERRIDES = 'contents of %s\n' % skia_overrides_path filesystem.write_text_file(skia_overrides_path, SKIA_OVERRIDES) additional_expectations_path = port.path_from_chromium_base( 'additional_expectations.txt') ADDITIONAL_EXPECTATIONS = 'contents of %s\n' % additional_expectations_path filesystem.write_text_file(additional_expectations_path, ADDITIONAL_EXPECTATIONS) port._options.builder_name = 'DUMMY_BUILDER_NAME' port._options.additional_expectations = [] self.assertEquals(port.test_expectations_overrides(), SKIA_OVERRIDES + CHROMIUM_OVERRIDES) port._options.additional_expectations = [additional_expectations_path] self.assertEquals(port.test_expectations_overrides(), SKIA_OVERRIDES + CHROMIUM_OVERRIDES + ADDITIONAL_EXPECTATIONS) port._options.builder_name = 'builder (deps)' port._options.additional_expectations = [] self.assertEquals(port.test_expectations_overrides(), SKIA_OVERRIDES + CHROMIUM_OVERRIDES) port._options.additional_expectations = [additional_expectations_path] self.assertEquals(port.test_expectations_overrides(), SKIA_OVERRIDES + CHROMIUM_OVERRIDES + ADDITIONAL_EXPECTATIONS) # A builder which does NOT observe the Chromium test_expectations, # but still observes the Skia test_expectations... port._options.builder_name = 'builder' port._options.additional_expectations = [] self.assertEquals(port.test_expectations_overrides(), SKIA_OVERRIDES) port._options.additional_expectations = [additional_expectations_path] self.assertEquals(port.test_expectations_overrides(), SKIA_OVERRIDES + ADDITIONAL_EXPECTATIONS)
class BaselineOptimizerTest(unittest.TestCase): def setUp(self): self.host = MockHost() self.fs = MockFileSystem() self.host.filesystem = self.fs # TODO(robertma): Even though we have mocked the builder list (and hence # all_port_names), we are still relying on the knowledge of currently # configured ports and their fallback order. Ideally, we should improve # MockPortFactory and use it. self.host.builders = BuilderList({ 'Fake Test Win10': { 'port_name': 'win-win10', 'specifiers': ['Win10', 'Release'] }, 'Fake Test Linux': { 'port_name': 'linux-trusty', 'specifiers': ['Trusty', 'Release'] }, 'Fake Test Mac10.13': { 'port_name': 'mac-mac10.13', 'specifiers': ['Mac10.13', 'Release'] }, 'Fake Test Mac10.12': { 'port_name': 'mac-mac10.12', 'specifiers': ['Mac10.12', 'Release'] }, 'Fake Test Mac10.11': { 'port_name': 'mac-mac10.11', 'specifiers': ['Mac10.11', 'Release'] }, 'Fake Test Mac10.10': { 'port_name': 'mac-mac10.10', 'specifiers': ['Mac10.10', 'Release'] }, }) # Note: this is a pre-assumption of the tests in this file. If this # assertion fails, port configurations are likely changed, and the # tests need to be adjusted accordingly. self.assertEqual(sorted(self.host.port_factory.all_port_names()), [ 'linux-trusty', 'mac-mac10.10', 'mac-mac10.11', 'mac-mac10.12', 'mac-mac10.13', 'win-win10' ]) def _assert_optimization(self, results_by_directory, directory_to_new_results, baseline_dirname=''): layout_tests_dir = PathFinder(self.fs).layout_tests_dir() test_name = 'mock-test.html' baseline_name = 'mock-test-expected.txt' self.fs.write_text_file( self.fs.join(layout_tests_dir, 'VirtualTestSuites'), '[{"prefix": "gpu", "base": "fast/canvas", "args": ["--foo"]}]') for dirname, contents in results_by_directory.items(): self.fs.write_binary_file( self.fs.join(layout_tests_dir, dirname, baseline_name), contents) baseline_optimizer = BaselineOptimizer( self.host, self.host.port_factory.get(), self.host.port_factory.all_port_names()) self.assertTrue( baseline_optimizer.optimize( self.fs.join(baseline_dirname, test_name), 'txt')) for dirname, contents in directory_to_new_results.items(): path = self.fs.join(layout_tests_dir, dirname, baseline_name) if contents is None: # Check files that are explicitly marked as absent. self.assertFalse( self.fs.exists(path), '%s should not exist after optimization' % path) else: self.assertEqual(self.fs.read_binary_file(path), contents, 'Content of %s != "%s"' % (path, contents)) for dirname in results_by_directory: path = self.fs.join(layout_tests_dir, dirname, baseline_name) if dirname not in directory_to_new_results or directory_to_new_results[ dirname] is None: self.assertFalse( self.fs.exists(path), '%s should not exist after optimization' % path) def test_linux_redundant_with_win(self): self._assert_optimization( { 'platform/win': '1', 'platform/linux': '1', }, { 'platform/win': '1', }) def test_covers_mac_win_linux(self): self._assert_optimization( { 'platform/mac': '1', 'platform/win': '1', 'platform/linux': '1', }, { '': '1', }) def test_overwrites_root(self): self._assert_optimization( { 'platform/mac': '1', 'platform/win': '1', 'platform/linux': '1', '': '2', }, { '': '1', }) def test_no_new_common_directory(self): self._assert_optimization( { 'platform/mac': '1', 'platform/linux': '1', '': '2', }, { 'platform/mac': '1', 'platform/linux': '1', '': '2', }) def test_local_optimization(self): self._assert_optimization( { 'platform/mac': '1', 'platform/linux': '1', 'platform/mac-mac10.11': '1', }, { 'platform/mac': '1', 'platform/linux': '1', }) def test_local_optimization_skipping_a_port_in_the_middle(self): # mac-mac10.10 -> mac-mac10.11 -> mac self._assert_optimization( { 'platform/mac': '1', 'platform/linux': '1', 'platform/mac-mac10.10': '1', }, { 'platform/mac': '1', 'platform/linux': '1', }) def test_baseline_redundant_with_root(self): self._assert_optimization( { 'platform/mac': '1', 'platform/win': '2', '': '2', }, { 'platform/mac': '1', '': '2', }) def test_root_baseline_unused(self): self._assert_optimization( { 'platform/mac': '1', 'platform/win': '2', '': '3', }, { 'platform/mac': '1', 'platform/win': '2', }) def test_root_baseline_unused_and_non_existant(self): self._assert_optimization({ 'platform/mac': '1', 'platform/win': '2', }, { 'platform/mac': '1', 'platform/win': '2', }) def test_virtual_baseline_redundant_with_non_virtual(self): self._assert_optimization( { 'platform/win/virtual/gpu/fast/canvas': '2', 'platform/win/fast/canvas': '2', }, { 'platform/win/fast/canvas': '2', }, baseline_dirname='virtual/gpu/fast/canvas') def test_virtual_baseline_redundant_with_non_virtual_fallback(self): # virtual linux -> virtual win -> virtual root -> linux -> win self._assert_optimization( { 'platform/linux/virtual/gpu/fast/canvas': '2', 'platform/win/fast/canvas': '2', }, { 'platform/win/virtual/gpu/fast/canvas': None, 'platform/win/fast/canvas': '2', }, baseline_dirname='virtual/gpu/fast/canvas') def test_virtual_baseline_redundant_with_actual_root(self): self._assert_optimization( { 'platform/win/virtual/gpu/fast/canvas': '2', 'fast/canvas': '2', }, { 'fast/canvas': '2', }, baseline_dirname='virtual/gpu/fast/canvas') def test_virtual_root_redundant_with_actual_root(self): self._assert_optimization( { 'virtual/gpu/fast/canvas': '2', 'fast/canvas': '2', }, { 'fast/canvas': '2', }, baseline_dirname='virtual/gpu/fast/canvas') def test_virtual_root_redundant_with_ancestors(self): self._assert_optimization( { 'virtual/gpu/fast/canvas': '2', 'platform/mac/fast/canvas': '2', 'platform/win/fast/canvas': '2', }, { 'fast/canvas': '2', }, baseline_dirname='virtual/gpu/fast/canvas') def test_virtual_root_not_redundant_with_ancestors(self): self._assert_optimization( { 'virtual/gpu/fast/canvas': '2', 'platform/mac/fast/canvas': '1', }, { 'virtual/gpu/fast/canvas': '2', 'platform/mac/fast/canvas': '1', }, baseline_dirname='virtual/gpu/fast/canvas') def test_virtual_covers_mac_win_linux(self): self._assert_optimization( { 'platform/mac/virtual/gpu/fast/canvas': '1', 'platform/win/virtual/gpu/fast/canvas': '1', 'platform/linux/virtual/gpu/fast/canvas': '1', }, { 'virtual/gpu/fast/canvas': '1', }, baseline_dirname='virtual/gpu/fast/canvas') def test_all_pass_testharness_at_root(self): self._assert_optimization({'': ALL_PASS_TESTHARNESS_RESULT}, {'': None}) def test_all_pass_testharness_at_linux(self): self._assert_optimization( {'platform/linux': ALL_PASS_TESTHARNESS_RESULT}, {'platform/linux': None}) def test_all_pass_testharness_at_linux_and_win(self): # https://crbug.com/805008 self._assert_optimization( { 'platform/linux': ALL_PASS_TESTHARNESS_RESULT, 'platform/win': ALL_PASS_TESTHARNESS_RESULT }, { 'platform/linux': None, 'platform/win': None }) def test_all_pass_testharness_at_virtual_root(self): self._assert_optimization( {'virtual/gpu/fast/canvas': ALL_PASS_TESTHARNESS_RESULT}, {'virtual/gpu/fast/canvas': None}, baseline_dirname='virtual/gpu/fast/canvas') def test_all_pass_testharness_at_virtual_linux(self): self._assert_optimization( { 'platform/linux/virtual/gpu/fast/canvas': ALL_PASS_TESTHARNESS_RESULT }, {'platform/linux/virtual/gpu/fast/canvas': None}, baseline_dirname='virtual/gpu/fast/canvas') def test_all_pass_testharness_falls_back_to_non_pass(self): # The all-PASS baseline needs to be preserved in this case. self._assert_optimization( { 'platform/linux': ALL_PASS_TESTHARNESS_RESULT, '': '1' }, { 'platform/linux': ALL_PASS_TESTHARNESS_RESULT, '': '1' }) def test_virtual_all_pass_testharness_falls_back_to_base(self): # The all-PASS baseline needs to be preserved in this case. self._assert_optimization( { 'virtual/gpu/fast/canvas': ALL_PASS_TESTHARNESS_RESULT, 'platform/linux/fast/canvas': '1', }, { 'virtual/gpu/fast/canvas': ALL_PASS_TESTHARNESS_RESULT, 'platform/linux/fast/canvas': '1', }, baseline_dirname='virtual/gpu/fast/canvas') # Tests for protected methods - pylint: disable=protected-access def test_move_baselines(self): self.fs.write_text_file( '/mock-checkout/third_party/WebKit/LayoutTests/VirtualTestSuites', '[]') self.fs.write_binary_file( '/mock-checkout/third_party/WebKit/LayoutTests/platform/win/another/test-expected.txt', 'result A') self.fs.write_binary_file( '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac/another/test-expected.txt', 'result A') self.fs.write_binary_file( '/mock-checkout/third_party/WebKit/LayoutTests/another/test-expected.txt', 'result B') baseline_optimizer = BaselineOptimizer( self.host, self.host.port_factory.get(), self.host.port_factory.all_port_names()) baseline_optimizer._move_baselines( 'another/test-expected.txt', { '/mock-checkout/third_party/WebKit/LayoutTests/platform/win': 'aaa', '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac': 'aaa', '/mock-checkout/third_party/WebKit/LayoutTests': 'bbb', }, { '/mock-checkout/third_party/WebKit/LayoutTests': 'aaa', }) self.assertEqual( self.fs.read_binary_file( '/mock-checkout/third_party/WebKit/LayoutTests/another/test-expected.txt' ), 'result A') def test_move_baselines_skip_git_commands(self): self.fs.write_text_file( '/mock-checkout/third_party/WebKit/LayoutTests/VirtualTestSuites', '[]') self.fs.write_binary_file( '/mock-checkout/third_party/WebKit/LayoutTests/platform/win/another/test-expected.txt', 'result A') self.fs.write_binary_file( '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac/another/test-expected.txt', 'result A') self.fs.write_binary_file( '/mock-checkout/third_party/WebKit/LayoutTests/another/test-expected.txt', 'result B') baseline_optimizer = BaselineOptimizer( self.host, self.host.port_factory.get(), self.host.port_factory.all_port_names()) baseline_optimizer._move_baselines( 'another/test-expected.txt', { '/mock-checkout/third_party/WebKit/LayoutTests/platform/win': 'aaa', '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac': 'aaa', '/mock-checkout/third_party/WebKit/LayoutTests': 'bbb', }, { '/mock-checkout/third_party/WebKit/LayoutTests/platform/linux': 'bbb', '/mock-checkout/third_party/WebKit/LayoutTests': 'aaa', }) self.assertEqual( self.fs.read_binary_file( '/mock-checkout/third_party/WebKit/LayoutTests/another/test-expected.txt' ), 'result A')
def test_platform_duplicate_touched_test(self): paths = ['LayoutTests/test1.html', 'LayoutTests/test1.html', 'LayoutTests/platform/mock1/test2-expected.txt', 'LayoutTests/platform/mock2/test2-expected.txt'] fs = MockFileSystem() fs.write_text_file('/test.checkout/LayoutTests/test2.html', 'This is a test') fs, touched_tests = self.touched_files(paths, fs) self.assertItemsEqual(touched_tests, ['test1.html', 'test2.html'])
def test_expected_touched_test(self): paths = ['LayoutTests/test-expected.txt', 'LayoutTests/no-test-expected.txt'] fs = MockFileSystem() fs.write_text_file('/test.checkout/LayoutTests/test.html', 'This is a test') fs, touched_tests = self.touched_files(paths, fs) self.assertItemsEqual(touched_tests, ['test.html'])
class DirectoryOwnersExtractorTest(unittest.TestCase): def setUp(self): # We always have an OWNERS file at LayoutTests/external. self.filesystem = MockFileSystem( files={ '/mock-checkout/third_party/WebKit/LayoutTests/external/OWNERS': '*****@*****.**' }) self.extractor = DirectoryOwnersExtractor(self.filesystem) def _write_files(self, files): # Use write_text_file instead of directly assigning to filesystem.files # so that intermediary directories are correctly created, too. for path, contents in files.iteritems(): self.filesystem.write_text_file(path, contents) def test_list_owners_combines_same_owners(self): self._write_files({ ABS_WPT_BASE + '/foo/x.html': '', ABS_WPT_BASE + '/foo/OWNERS': '[email protected]\[email protected]\n', ABS_WPT_BASE + '/bar/x/y.html': '', ABS_WPT_BASE + '/bar/OWNERS': '[email protected]\[email protected]\n', }) changed_files = [ REL_WPT_BASE + '/foo/x.html', REL_WPT_BASE + '/bar/x/y.html', ] self.assertEqual( self.extractor.list_owners(changed_files), { ('*****@*****.**', '*****@*****.**'): ['external/wpt/bar', 'external/wpt/foo'] }) def test_list_owners_combines_same_directory(self): self._write_files({ ABS_WPT_BASE + '/baz/x/y.html': '', ABS_WPT_BASE + '/baz/x/y/z.html': '', ABS_WPT_BASE + '/baz/x/OWNERS': '[email protected]\n', }) changed_files = [ REL_WPT_BASE + '/baz/x/y.html', REL_WPT_BASE + '/baz/x/y/z.html', ] self.assertEqual(self.extractor.list_owners(changed_files), {('*****@*****.**', ): ['external/wpt/baz/x']}) def test_list_owners_skips_empty_owners(self): self._write_files({ ABS_WPT_BASE + '/baz/x/y/z.html': '', ABS_WPT_BASE + '/baz/x/y/OWNERS': '# Some comments\n', ABS_WPT_BASE + '/baz/x/OWNERS': '[email protected]\n', }) changed_files = [ REL_WPT_BASE + '/baz/x/y/z.html', ] self.assertEqual(self.extractor.list_owners(changed_files), {('*****@*****.**', ): ['external/wpt/baz/x']}) def test_list_owners_not_found(self): self._write_files({ # Although LayoutTests/external/OWNERS exists, it should not be listed. ABS_WPT_BASE + '/foo/bar.html': '', # Files out of external. '/mock-checkout/third_party/WebKit/LayoutTests/TestExpectations': '', '/mock-checkout/third_party/WebKit/LayoutTests/OWNERS': '*****@*****.**', }) changed_files = [ REL_WPT_BASE + '/foo/bar.html', 'third_party/WebKit/LayoutTests/TestExpectations', ] self.assertEqual(self.extractor.list_owners(changed_files), {}) def test_find_owners_file_at_current_dir(self): self._write_files({ABS_WPT_BASE + '/foo/OWNERS': '*****@*****.**'}) self.assertEqual( self.extractor.find_owners_file(REL_WPT_BASE + '/foo'), ABS_WPT_BASE + '/foo/OWNERS') def test_find_owners_file_at_ancestor(self): self._write_files({ ABS_WPT_BASE + '/x/OWNERS': '*****@*****.**', ABS_WPT_BASE + '/x/y/z.html': '', }) self.assertEqual( self.extractor.find_owners_file(REL_WPT_BASE + '/x/y'), ABS_WPT_BASE + '/x/OWNERS') def test_find_owners_file_stops_at_external_root(self): self._write_files({ ABS_WPT_BASE + '/x/y/z.html': '', }) self.assertEqual( self.extractor.find_owners_file(REL_WPT_BASE + '/x/y'), '/mock-checkout/third_party/WebKit/LayoutTests/external/OWNERS') def test_find_owners_file_takes_four_kinds_of_paths(self): owners_path = ABS_WPT_BASE + '/foo/OWNERS' self._write_files({ owners_path: '*****@*****.**', ABS_WPT_BASE + '/foo/bar.html': '', }) # Absolute paths of directories. self.assertEqual( self.extractor.find_owners_file(ABS_WPT_BASE + '/foo'), owners_path) # Relative paths of directories. self.assertEqual( self.extractor.find_owners_file(REL_WPT_BASE + '/foo'), owners_path) # Absolute paths of files. self.assertEqual( self.extractor.find_owners_file(ABS_WPT_BASE + '/foo/bar.html'), owners_path) # Relative paths of files. self.assertEqual( self.extractor.find_owners_file(REL_WPT_BASE + '/foo/bar.html'), owners_path) def test_find_owners_file_out_of_external(self): self._write_files({ '/mock-checkout/third_party/WebKit/LayoutTests/OWNERS': '*****@*****.**', '/mock-checkout/third_party/WebKit/LayoutTests/other/some_file': '', }) self.assertIsNone( self.extractor.find_owners_file('third_party/WebKit/LayoutTests')) self.assertIsNone( self.extractor.find_owners_file( 'third_party/WebKit/LayoutTests/other')) self.assertIsNone(self.extractor.find_owners_file('third_party')) def test_extract_owners(self): self.filesystem.files = { ABS_WPT_BASE + '/foo/OWNERS': '#This is a comment\n' '*\n' '[email protected]\n' '[email protected]\n' 'foobar\n' '#[email protected]\n' '# TEAM: [email protected]\n' '# COMPONENT: Blink>Layout\n' } self.assertEqual( self.extractor.extract_owners(ABS_WPT_BASE + '/foo/OWNERS'), ['*****@*****.**', '*****@*****.**']) def test_extract_component(self): self.filesystem.files = { ABS_WPT_BASE + '/foo/OWNERS': '# TEAM: [email protected]\n' '# COMPONENT: Blink>Layout\n' } self.assertEqual( self.extractor.extract_component(ABS_WPT_BASE + '/foo/OWNERS'), 'Blink>Layout') def test_is_wpt_notify_enabled_true(self): self.filesystem.files = { ABS_WPT_BASE + '/foo/OWNERS': '# COMPONENT: Blink>Layout\n' '# WPT-NOTIFY: true\n' } self.assertTrue( self.extractor.is_wpt_notify_enabled(ABS_WPT_BASE + '/foo/OWNERS')) def test_is_wpt_notify_enabled_false(self): self.filesystem.files = { ABS_WPT_BASE + '/foo/OWNERS': '# COMPONENT: Blink>Layout\n' '# WPT-NOTIFY: false\n' } self.assertFalse( self.extractor.is_wpt_notify_enabled(ABS_WPT_BASE + '/foo/OWNERS')) def test_is_wpt_notify_enabled_absence_is_false(self): self.filesystem.files = { ABS_WPT_BASE + '/foo/OWNERS': '# TEAM: [email protected]\n' '# COMPONENT: Blink>Layout\n' } self.assertFalse( self.extractor.is_wpt_notify_enabled(ABS_WPT_BASE + '/foo/OWNERS'))