Commit 64fdfb8e authored by Luke Zielinski's avatar Luke Zielinski Committed by Commit Bot

Make wpt_common_unittests.py use the correct path separator.

This avoids path errors on windows.

Tested locally on a Windows checkout to confirm the tests pass.

Bug: 11334758
Change-Id: I28ffbebcb06984cd2a5aee252a52947d7c848a20
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2439013Reviewed-by: default avatarStephen McGruer <smcgruer@chromium.org>
Commit-Queue: Stephen McGruer <smcgruer@chromium.org>
Commit-Queue: Luke Z <lpz@chromium.org>
Auto-Submit: Luke Z <lpz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#812229}
parent 8912e35e
...@@ -20,7 +20,7 @@ from blinkpy.w3c.wpt_manifest import BASE_MANIFEST_NAME ...@@ -20,7 +20,7 @@ from blinkpy.w3c.wpt_manifest import BASE_MANIFEST_NAME
# The path where the output of a wpt run was written. This is the file that # The path where the output of a wpt run was written. This is the file that
# gets processed by BaseWptScriptAdapter. # gets processed by BaseWptScriptAdapter.
OUTPUT_JSON_FILENAME = "/out.json" OUTPUT_JSON_FILENAME = "out.json"
class BaseWptScriptAdapterTest(unittest.TestCase): class BaseWptScriptAdapterTest(unittest.TestCase):
...@@ -99,31 +99,30 @@ class BaseWptScriptAdapterTest(unittest.TestCase): ...@@ -99,31 +99,30 @@ class BaseWptScriptAdapterTest(unittest.TestCase):
self._create_json_output(json_dict) self._create_json_output(json_dict)
self.wpt_adapter.do_post_test_run_tasks() self.wpt_adapter.do_post_test_run_tasks()
written_files = self.wpt_adapter.fs.written_files written_files = self.wpt_adapter.fs.written_files
self.assertEqual( actual_path = os.path.join("layout-test-results", "test-actual.txt")
"test.html actual text", self.assertEqual("test.html actual text", written_files[actual_path])
written_files["/layout-test-results/test-actual.txt"])
# Ensure the artifact in the json was replaced with the location of # Ensure the artifact in the json was replaced with the location of
# the newly-created file. # the newly-created file.
updated_json = self._load_json_output() updated_json = self._load_json_output()
self.assertFalse( self.assertFalse(
"log" in updated_json["tests"]["test.html"]["artifacts"]) "log" in updated_json["tests"]["test.html"]["artifacts"])
self.assertEqual( self.assertEqual(
["layout-test-results/test-actual.txt"], [actual_path],
updated_json["tests"]["test.html"]["artifacts"]["actual_text"]) updated_json["tests"]["test.html"]["artifacts"]["actual_text"])
# Ensure that a diff was also generated. Since there's no expected # Ensure that a diff was also generated. Since there's no expected
# output, the actual text is all new. We don't validate the entire diff # output, the actual text is all new. We don't validate the entire diff
# files to avoid checking line numbers/markup. # files to avoid checking line numbers/markup.
self.assertIn("+test.html actual text", diff_path = os.path.join("layout-test-results", "test-diff.txt")
written_files["/layout-test-results/test-diff.txt"]) self.assertIn("+test.html actual text", written_files[diff_path])
self.assertEqual( self.assertEqual(
["layout-test-results/test-diff.txt"], [diff_path],
updated_json["tests"]["test.html"]["artifacts"]["text_diff"]) updated_json["tests"]["test.html"]["artifacts"]["text_diff"])
self.assertIn( pretty_diff_path = os.path.join("layout-test-results",
"test.html actual text", "test-pretty-diff.html")
written_files["/layout-test-results/test-pretty-diff.html"]) self.assertIn("test.html actual text", written_files[pretty_diff_path])
self.assertEqual( self.assertEqual(
["layout-test-results/test-pretty-diff.html"], [pretty_diff_path],
updated_json["tests"]["test.html"]["artifacts"]["pretty_text_diff"]) updated_json["tests"]["test.html"]["artifacts"]["pretty_text_diff"])
def test_write_crashlog_artifact(self): def test_write_crashlog_artifact(self):
...@@ -144,16 +143,16 @@ class BaseWptScriptAdapterTest(unittest.TestCase): ...@@ -144,16 +143,16 @@ class BaseWptScriptAdapterTest(unittest.TestCase):
self._create_json_output(json_dict) self._create_json_output(json_dict)
self.wpt_adapter.do_post_test_run_tasks() self.wpt_adapter.do_post_test_run_tasks()
written_files = self.wpt_adapter.fs.written_files written_files = self.wpt_adapter.fs.written_files
self.assertEqual( crash_log_path = os.path.join("layout-test-results",
"test.html crashed!", "test-crash-log.txt")
written_files["/layout-test-results/test-crash-log.txt"]) self.assertEqual("test.html crashed!", written_files[crash_log_path])
# Ensure the artifact in the json was replaced with the location of # Ensure the artifact in the json was replaced with the location of
# the newly-created file. # the newly-created file.
updated_json = self._load_json_output() updated_json = self._load_json_output()
self.assertFalse( self.assertFalse(
"wpt_crash_log" in updated_json["tests"]["test.html"]["artifacts"]) "wpt_crash_log" in updated_json["tests"]["test.html"]["artifacts"])
self.assertEqual( self.assertEqual(
["layout-test-results/test-crash-log.txt"], [crash_log_path],
updated_json["tests"]["test.html"]["artifacts"]["crash_log"]) updated_json["tests"]["test.html"]["artifacts"]["crash_log"])
def test_write_screenshot_artifacts(self): def test_write_screenshot_artifacts(self):
...@@ -178,22 +177,24 @@ class BaseWptScriptAdapterTest(unittest.TestCase): ...@@ -178,22 +177,24 @@ class BaseWptScriptAdapterTest(unittest.TestCase):
self._create_json_output(json_dict) self._create_json_output(json_dict)
self.wpt_adapter.do_post_test_run_tasks() self.wpt_adapter.do_post_test_run_tasks()
written_files = self.wpt_adapter.fs.written_files written_files = self.wpt_adapter.fs.written_files
self.assertEqual( actual_image_path = os.path.join("layout-test-results",
base64.b64decode('abcd'), "reftest-actual.png")
written_files["/layout-test-results/reftest-actual.png"]) self.assertEqual(base64.b64decode('abcd'),
self.assertEqual( written_files[actual_image_path])
base64.b64decode('bcde'), expected_image_path = os.path.join("layout-test-results",
written_files["/layout-test-results/reftest-expected.png"]) "reftest-expected.png")
self.assertEqual(base64.b64decode('bcde'),
written_files[expected_image_path])
# Ensure the artifacts in the json were replaced with the location of # Ensure the artifacts in the json were replaced with the location of
# the newly-created files. # the newly-created files.
updated_json = self._load_json_output() updated_json = self._load_json_output()
self.assertFalse( self.assertFalse(
"screenshots" in updated_json["tests"]["reftest.html"]["artifacts"]) "screenshots" in updated_json["tests"]["reftest.html"]["artifacts"])
self.assertEqual( self.assertEqual(
["layout-test-results/reftest-actual.png"], [actual_image_path],
updated_json["tests"]["reftest.html"]["artifacts"]["actual_image"]) updated_json["tests"]["reftest.html"]["artifacts"]["actual_image"])
self.assertEqual( self.assertEqual(
["layout-test-results/reftest-expected.png"], [expected_image_path],
updated_json["tests"]["reftest.html"]["artifacts"] updated_json["tests"]["reftest.html"]["artifacts"]
["expected_image"]) ["expected_image"])
...@@ -220,43 +221,41 @@ class BaseWptScriptAdapterTest(unittest.TestCase): ...@@ -220,43 +221,41 @@ class BaseWptScriptAdapterTest(unittest.TestCase):
"test.html checked-in metadata") "test.html checked-in metadata")
self.wpt_adapter.do_post_test_run_tasks() self.wpt_adapter.do_post_test_run_tasks()
written_files = self.wpt_adapter.fs.written_files written_files = self.wpt_adapter.fs.written_files
self.assertEqual( actual_path = os.path.join("layout-test-results", "test-actual.txt")
"test.html actual text", self.assertEqual("test.html actual text", written_files[actual_path])
written_files["/layout-test-results/test-actual.txt"])
# The checked-in metadata file gets renamed from .ini to -expected.txt # The checked-in metadata file gets renamed from .ini to -expected.txt
self.assertEqual( expected_path = os.path.join("layout-test-results", "test-expected.txt")
"test.html checked-in metadata", self.assertEqual("test.html checked-in metadata",
written_files["/layout-test-results/test-expected.txt"]) written_files[expected_path])
# Ensure the artifacts in the json were replaced with the locations of # Ensure the artifacts in the json were replaced with the locations of
# the newly-created files. # the newly-created files.
updated_json = self._load_json_output() updated_json = self._load_json_output()
self.assertFalse( self.assertFalse(
"log" in updated_json["tests"]["test.html"]["artifacts"]) "log" in updated_json["tests"]["test.html"]["artifacts"])
self.assertEqual( self.assertEqual(
["layout-test-results/test-actual.txt"], [actual_path],
updated_json["tests"]["test.html"]["artifacts"]["actual_text"]) updated_json["tests"]["test.html"]["artifacts"]["actual_text"])
self.assertEqual( self.assertEqual(
["layout-test-results/test-expected.txt"], [expected_path],
updated_json["tests"]["test.html"]["artifacts"]["expected_text"]) updated_json["tests"]["test.html"]["artifacts"]["expected_text"])
# Ensure that a diff was also generated. There should be both additions # Ensure that a diff was also generated. There should be both additions
# and deletions for this test since we have expected output. We don't # and deletions for this test since we have expected output. We don't
# validate the entire diff files to avoid checking line numbers/markup. # validate the entire diff files to avoid checking line numbers/markup.
diff_path = os.path.join("layout-test-results", "test-diff.txt")
self.assertIn("-test.html checked-in metadata", self.assertIn("-test.html checked-in metadata",
written_files["/layout-test-results/test-diff.txt"]) written_files[diff_path])
self.assertIn("+test.html actual text", self.assertIn("+test.html actual text", written_files[diff_path])
written_files["/layout-test-results/test-diff.txt"])
self.assertEqual( self.assertEqual(
["layout-test-results/test-diff.txt"], [diff_path],
updated_json["tests"]["test.html"]["artifacts"]["text_diff"]) updated_json["tests"]["test.html"]["artifacts"]["text_diff"])
self.assertIn( pretty_diff_path = os.path.join("layout-test-results",
"test.html checked-in metadata", "test-pretty-diff.html")
written_files["/layout-test-results/test-pretty-diff.html"]) self.assertIn("test.html checked-in metadata",
self.assertIn( written_files[pretty_diff_path])
"test.html actual text", self.assertIn("test.html actual text", written_files[pretty_diff_path])
written_files["/layout-test-results/test-pretty-diff.html"])
self.assertEqual( self.assertEqual(
["layout-test-results/test-pretty-diff.html"], [pretty_diff_path],
updated_json["tests"]["test.html"]["artifacts"]["pretty_text_diff"]) updated_json["tests"]["test.html"]["artifacts"]["pretty_text_diff"])
def test_expected_output_for_variant(self): def test_expected_output_for_variant(self):
...@@ -288,26 +287,26 @@ class BaseWptScriptAdapterTest(unittest.TestCase): ...@@ -288,26 +287,26 @@ class BaseWptScriptAdapterTest(unittest.TestCase):
"variant.html checked-in metadata") "variant.html checked-in metadata")
self.wpt_adapter.do_post_test_run_tasks() self.wpt_adapter.do_post_test_run_tasks()
written_files = self.wpt_adapter.fs.written_files written_files = self.wpt_adapter.fs.written_files
self.assertEqual( actual_path = os.path.join("layout-test-results",
"variant bar/abc actual text", "variant_foo=bar_abc-actual.txt")
written_files[ self.assertEqual("variant bar/abc actual text",
"/layout-test-results/variant_foo=bar_abc-actual.txt"]) written_files[actual_path])
# The checked-in metadata file gets renamed from .ini to -expected.txt # The checked-in metadata file gets renamed from .ini to -expected.txt
self.assertEqual( expected_path = os.path.join("layout-test-results",
"variant.html checked-in metadata", "variant_foo=bar_abc-expected.txt")
written_files[ self.assertEqual("variant.html checked-in metadata",
"/layout-test-results/variant_foo=bar_abc-expected.txt"]) written_files[expected_path])
# Ensure the artifacts in the json were replaced with the locations of # Ensure the artifacts in the json were replaced with the locations of
# the newly-created files. # the newly-created files.
updated_json = self._load_json_output() updated_json = self._load_json_output()
self.assertFalse("log" in updated_json["tests"] self.assertFalse("log" in updated_json["tests"]
["variant.html?foo=bar/abc"]["artifacts"]) ["variant.html?foo=bar/abc"]["artifacts"])
self.assertEqual( self.assertEqual(
["layout-test-results/variant_foo=bar_abc-actual.txt"], [actual_path],
updated_json["tests"]["variant.html?foo=bar/abc"]["artifacts"] updated_json["tests"]["variant.html?foo=bar/abc"]["artifacts"]
["actual_text"]) ["actual_text"])
self.assertEqual( self.assertEqual(
["layout-test-results/variant_foo=bar_abc-expected.txt"], [expected_path],
updated_json["tests"]["variant.html?foo=bar/abc"]["artifacts"] updated_json["tests"]["variant.html?foo=bar/abc"]["artifacts"]
["expected_text"]) ["expected_text"])
...@@ -316,6 +315,10 @@ class BaseWptScriptAdapterTest(unittest.TestCase): ...@@ -316,6 +315,10 @@ class BaseWptScriptAdapterTest(unittest.TestCase):
# ini file for a multiglobal test. Multi-globals are a little different # ini file for a multiglobal test. Multi-globals are a little different
# because we have to use the manifest to map a test name to the test # because we have to use the manifest to map a test name to the test
# file, and determine the associated metadata from the test file. # file, and determine the associated metadata from the test file.
#
# Also note that the "dir" is both a directory and a part of the test
# name, so the path delimiter remains a / (ie: dir/multiglob) even on
# Windows.
json_dict = { json_dict = {
'tests': { 'tests': {
'dir/multiglob.https.any.worker.html': { 'dir/multiglob.https.any.worker.html': {
...@@ -339,30 +342,29 @@ class BaseWptScriptAdapterTest(unittest.TestCase): ...@@ -339,30 +342,29 @@ class BaseWptScriptAdapterTest(unittest.TestCase):
"dir/multiglob checked-in metadata") "dir/multiglob checked-in metadata")
self.wpt_adapter.do_post_test_run_tasks() self.wpt_adapter.do_post_test_run_tasks()
written_files = self.wpt_adapter.fs.written_files written_files = self.wpt_adapter.fs.written_files
self.assertEqual( actual_path = os.path.join("layout-test-results",
"dir/multiglob worker actual text", "dir/multiglob.https.any.worker-actual.txt")
written_files[ self.assertEqual("dir/multiglob worker actual text",
"/layout-test-results/dir/" written_files[actual_path])
"multiglob.https.any.worker-actual.txt"])
# The checked-in metadata file gets renamed from .ini to -expected.txt # The checked-in metadata file gets renamed from .ini to -expected.txt
self.assertEqual( expected_path = os.path.join(
"dir/multiglob checked-in metadata", "layout-test-results",
written_files[ "dir/multiglob.https.any.worker-expected.txt")
"/layout-test-results/dir/" self.assertEqual("dir/multiglob checked-in metadata",
"multiglob.https.any.worker-expected.txt"]) written_files[expected_path])
# Ensure the artifacts in the json were replaced with the locations of # Ensure the artifacts in the json were replaced with the locations of
# the newly-created files. # the newly-created files.
updated_json = self._load_json_output() updated_json = self._load_json_output()
self.assertFalse("log" in updated_json["tests"] self.assertFalse("log" in updated_json["tests"]
["dir/multiglob.https.any.worker.html"]["artifacts"]) ["dir/multiglob.https.any.worker.html"]["artifacts"])
self.assertEqual( self.assertEqual(
["layout-test-results/dir/multiglob.https.any.worker-actual.txt"], [actual_path],
updated_json["tests"]["dir/multiglob.https.any.worker.html"] updated_json["tests"]["dir/multiglob.https.any.worker.html"]
["artifacts"]["actual_text"]) ["artifacts"]["actual_text"])
self.assertEqual( self.assertEqual(
["layout-test-results/dir/multiglob.https.any.worker-expected.txt"], [expected_path],
updated_json["tests"]["dir/multiglob.https.any.worker.html"] updated_json["tests"]["dir/multiglob.https.any.worker.html"]
["artifacts"]["expected_text"]) ["artifacts"]["expected_text"])
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment