136 lines
4.6 KiB
Python
136 lines
4.6 KiB
Python
import argparse
|
|
import importlib.util
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
|
|
def load_module():
|
|
script_path = Path(__file__).resolve().parent / "wpt_status.py"
|
|
spec = importlib.util.spec_from_file_location("wpt_status", script_path)
|
|
assert spec is not None
|
|
assert spec.loader is not None
|
|
module = importlib.util.module_from_spec(spec)
|
|
sys.modules[spec.name] = module
|
|
spec.loader.exec_module(module)
|
|
return module
|
|
|
|
|
|
class WptStatusScriptTests(unittest.TestCase):
|
|
def setUp(self):
|
|
self.mod = load_module()
|
|
self.tmpdir = tempfile.TemporaryDirectory()
|
|
self.manifest_path = Path(self.tmpdir.name) / "wpt_manifest.toml"
|
|
self.manifest_path.write_text(
|
|
(
|
|
'[[case]]\n'
|
|
'id = "case-pass"\n'
|
|
'input = "fixtures/a-test.html"\n'
|
|
'mode = "reftest"\n'
|
|
'reference = "fixtures/a-ref.html"\n'
|
|
'status = "pass"\n'
|
|
'flags = []\n'
|
|
'\n'
|
|
'[[case]]\n'
|
|
'id = "case-known-fail"\n'
|
|
'input = "fixtures/b-test.html"\n'
|
|
'mode = "reftest"\n'
|
|
'reference = "fixtures/b-ref.html"\n'
|
|
'status = "known_fail"\n'
|
|
'reason = "initial reason"\n'
|
|
'flags = []\n'
|
|
'\n'
|
|
'[[case]]\n'
|
|
'id = "case-skip"\n'
|
|
'input = "fixtures/c-test.html"\n'
|
|
'mode = "reftest"\n'
|
|
'reference = "fixtures/c-ref.html"\n'
|
|
'status = "skip"\n'
|
|
'reason = "skip reason"\n'
|
|
'flags = []\n'
|
|
),
|
|
encoding="utf-8",
|
|
)
|
|
|
|
def tearDown(self):
|
|
self.tmpdir.cleanup()
|
|
|
|
def mutating_args(self, cmd, ids, **kwargs):
|
|
data = {
|
|
"cmd": cmd,
|
|
"manifest": self.manifest_path,
|
|
"ids": ids,
|
|
"dry_run": kwargs.pop("dry_run", False),
|
|
}
|
|
if cmd == "demote":
|
|
data["reason"] = kwargs.pop("reason")
|
|
data["allow_skip_to_known_fail"] = kwargs.pop(
|
|
"allow_skip_to_known_fail", False
|
|
)
|
|
return argparse.Namespace(**data)
|
|
|
|
def test_promote_removes_reason(self):
|
|
code = self.mod.run_mutating_command(
|
|
self.mutating_args("promote", ["case-known-fail"])
|
|
)
|
|
self.assertEqual(code, 0)
|
|
text = self.manifest_path.read_text(encoding="utf-8")
|
|
self.assertIn('id = "case-known-fail"', text)
|
|
self.assertIn('status = "pass"', text)
|
|
self.assertNotIn('reason = "initial reason"', text)
|
|
|
|
def test_demote_requires_reason_and_adds_known_fail_reason(self):
|
|
code = self.mod.run_mutating_command(
|
|
self.mutating_args("demote", ["case-pass"], reason="new regression")
|
|
)
|
|
self.assertEqual(code, 0)
|
|
text = self.manifest_path.read_text(encoding="utf-8")
|
|
self.assertIn('id = "case-pass"', text)
|
|
self.assertIn('status = "known_fail"', text)
|
|
self.assertIn('reason = "new regression"', text)
|
|
|
|
def test_demote_updates_existing_known_fail_reason(self):
|
|
code = self.mod.run_mutating_command(
|
|
self.mutating_args("demote", ["case-known-fail"], reason="updated reason")
|
|
)
|
|
self.assertEqual(code, 0)
|
|
text = self.manifest_path.read_text(encoding="utf-8")
|
|
self.assertIn('reason = "updated reason"', text)
|
|
self.assertNotIn('reason = "initial reason"', text)
|
|
|
|
def test_missing_id_returns_error(self):
|
|
code = self.mod.run_mutating_command(
|
|
self.mutating_args("promote", ["does-not-exist"])
|
|
)
|
|
self.assertEqual(code, 1)
|
|
|
|
def test_promote_already_pass_is_noop(self):
|
|
before = self.manifest_path.read_text(encoding="utf-8")
|
|
code = self.mod.run_mutating_command(
|
|
self.mutating_args("promote", ["case-pass"])
|
|
)
|
|
self.assertEqual(code, 0)
|
|
after = self.manifest_path.read_text(encoding="utf-8")
|
|
self.assertEqual(before, after)
|
|
|
|
def test_demote_skip_requires_override(self):
|
|
code = self.mod.run_mutating_command(
|
|
self.mutating_args("demote", ["case-skip"], reason="x")
|
|
)
|
|
self.assertEqual(code, 1)
|
|
|
|
code = self.mod.run_mutating_command(
|
|
self.mutating_args(
|
|
"demote",
|
|
["case-skip"],
|
|
reason="x",
|
|
allow_skip_to_known_fail=True,
|
|
)
|
|
)
|
|
self.assertEqual(code, 0)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|