import copy import itertools import unittest from run import APIS, OPTIONS, REPEATS, validate def fixture(): rows = [] for option, repeat, holder, contender in itertools.product(OPTIONS, range(REPEATS), APIS, APIS): success = (holder == "flock") != (contender == "flock") rows.append({"optimization": option, "repeat": repeat, "holder": holder, "contender": contender, "probes": [ {"phase": "held", "same_file": True, "acquired": success, "errno": 0 if success else 11}, {"phase": "released", "same_file": True, "acquired": True, "errno": 0}]}) return {"rows": rows} class MatrixValidation(unittest.TestCase): def test_complete_matrix(self): self.assertTrue(validate(fixture())) def test_rejects_missing_or_duplicate_pair(self): value = fixture() value["rows"][-1] = copy.deepcopy(value["rows"][0]) with self.assertRaises(AssertionError): validate(value) with self.assertRaises(AssertionError): validate({"rows": fixture()["rows"][:-1]}) def test_rejects_false_exclusion(self): value = fixture() value["rows"][1]["probes"][0].update(acquired=False, errno=11) with self.assertRaises(AssertionError): validate(value) def test_rejects_unsupported_api_as_conflict(self): value = fixture() value["rows"][0]["probes"][0]["errno"] = 22 with self.assertRaises(AssertionError): validate(value) def test_rejects_failed_release_control(self): value = fixture() value["rows"][0]["probes"][1].update(acquired=False, errno=11) with self.assertRaises(AssertionError): validate(value) def test_rejects_changed_identity_or_phase(self): for field, wrong in (("same_file", False), ("phase", "released")): value = fixture() value["rows"][0]["probes"][0][field] = wrong with self.assertRaises(AssertionError): validate(value) if __name__ == "__main__": unittest.main()