def test_expectation_overwrites_checked_in_metadata(self): """Test an entry in an expectation overwriting checked-in metadata. When an expectation has no annotation to use checked-in metadata then the expectation will overwrite any checked-in metadata.""" test_name = "external/wpt/test.html" expectations = _make_expectation(self.port, test_name, "TIMEOUT") mb = WPTMetadataBuilder(expectations, self.port) # Set the metadata builder to use mock filesystem populated with some # test data mb.checked_in_metadata_dir = "src" mb.metadata_output_dir = "out" mock_checked_in_files = { "src/external/wpt/test.html": "", "src/external/wpt/test.html.ini": "checked-in metadata", } mb.fs = MockFileSystem(files=mock_checked_in_files) mb._build_metadata_and_write() # Ensure that the data written to the metadata file is the translated # status, not the checked-in contents. resulting_ini_file = os.path.join("out", "test.html.ini") self.assertEqual( "[test.html]\n blink_expect_any_subtest_status: True # wpt_metadata_builder.py\n expected: [TIMEOUT]\n", mb.fs.read_text_file(resulting_ini_file))
def test_same_metadata_file_for_variants(self): """Variants of a test all go in the same metadata file.""" test_name1 = "external/wpt/variant.html?foo=bar/abc" test_name2 = "external/wpt/variant.html?foo=baz" expectation_dict = OrderedDict() _append_to_expectation_dict(expectation_dict, "TestExpectations", test_name1, "FAILURE") _append_to_expectation_dict(expectation_dict, "TestExpectations", test_name2, "TIMEOUT") expectations = _make_expectation_with_dict(self.port, expectation_dict) metadata_builder = WPTMetadataBuilder(expectations, self.port) metadata_builder.metadata_output_dir = "out" metadata_builder.fs = MockFileSystem() metadata_builder._build_metadata_and_write() # Both the tests go into the same metadata file, named without any # variants. metadata_file = os.path.join("out", "variant.html.ini") # Inside the metadata file, we have separate entries for each variant self.assertEqual( "[variant.html?foo=baz]\n blink_expect_any_subtest_status: True # wpt_metadata_builder.py\n" " expected: [TIMEOUT]\n" "[variant.html?foo=bar/abc]\n blink_expect_any_subtest_status: True # wpt_metadata_builder.py\n" " expected: [FAIL, ERROR]\n", metadata_builder.fs.read_text_file(metadata_file))
def test_copy_checked_in_metadata(self): # Ensure that ini metadata files are copied from the checked-in dir to # the output dir as expected. expectations = TestExpectations(self.port) mb = WPTMetadataBuilder(expectations, self.port) # Set the metadata builder to use mock filesystem populated with some # test data mb.checked_in_metadata_dir = "src" mb.metadata_output_dir = "out" mock_checked_in_files = { "src/a/b/c.html": "", "src/a/b/c.html.ini": "", "src/a/d/e.html": "", "src/a/d/e.html.ini": "checked-in", "src/a/tox.ini": "", # Put one duplicate file in the output directory to simulate a test # with both legacy expectations and checked-in metadata "out/a/d/e.html.ini": "legacy", } mb.fs = MockFileSystem(files=mock_checked_in_files) # Ensure that the duplicate file starts out with the legacy content. duplicate_ini_file = "out/a/d/e.html.ini" self.assertEqual("legacy", mb.fs.read_text_file(duplicate_ini_file)) mb._copy_checked_in_metadata() # Ensure only the ini files are copied, not the tests self.assertEqual(3, len(mb.fs.written_files)) self.assertTrue("out/a/b/c.html.ini" in mb.fs.written_files) self.assertTrue("out/a/d/e.html.ini" in mb.fs.written_files) self.assertTrue("out/a/tox.ini" in mb.fs.written_files) # Also ensure that the content of the duplicate file was overwritten # with the checked-in contents. self.assertEqual("checked-in", mb.fs.read_text_file(duplicate_ini_file))