|
| 1 | +# |
| 2 | +# Copyright (c) nexB Inc. and others. |
| 3 | +# SPDX-License-Identifier: Apache-2.0 |
| 4 | +# |
| 5 | +# Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download. |
| 6 | + |
| 7 | +from typing import NamedTuple |
| 8 | +from typing import Union |
| 9 | + |
| 10 | + |
| 11 | +class SchemaDrivenVersTest(NamedTuple): |
| 12 | + test_type: str |
| 13 | + test_group: str |
| 14 | + input: dict |
| 15 | + expected_output: Union[list, bool] |
| 16 | + |
| 17 | + @classmethod |
| 18 | + def from_data(cls, data: dict): |
| 19 | + return cls(**data) |
| 20 | + |
| 21 | + def assert_result(self): |
| 22 | + assert self.result == self.expected_output |
| 23 | + |
| 24 | + @property |
| 25 | + def result(self): |
| 26 | + if self.test_type == "equality": |
| 27 | + return self.equality() |
| 28 | + elif self.test_type == "comparison": |
| 29 | + return self.comparison() |
| 30 | + |
| 31 | + raise Exception(f"Unknown test_type: {self.test_type}") |
| 32 | + |
| 33 | + def equality(self): |
| 34 | + raise NotImplementedError |
| 35 | + |
| 36 | + def comparison(self): |
| 37 | + raise NotImplementedError |
| 38 | + |
| 39 | + @property |
| 40 | + def input_scheme(self): |
| 41 | + return self.input["input_scheme"] |
| 42 | + |
| 43 | + @property |
| 44 | + def input_native_range(self): |
| 45 | + return self.input["native_range"] |
| 46 | + |
| 47 | + @property |
| 48 | + def input_version1(self): |
| 49 | + return self.input["versions"][0] |
| 50 | + |
| 51 | + @property |
| 52 | + def input_version2(self): |
| 53 | + return self.input["versions"][1] |
| 54 | + |
| 55 | + |
| 56 | +def get_test_data_comp(scheme, versions, output): |
| 57 | + return { |
| 58 | + "test_group": "advanced", |
| 59 | + "test_type": "comparison", |
| 60 | + "input": { |
| 61 | + "input_scheme": scheme, |
| 62 | + "versions": versions, |
| 63 | + }, |
| 64 | + "expected_output": output, |
| 65 | + } |
| 66 | + |
| 67 | + |
| 68 | +def get_test_data_eq(scheme, versions, output): |
| 69 | + return { |
| 70 | + "test_group": "advanced", |
| 71 | + "test_type": "equality", |
| 72 | + "input": { |
| 73 | + "input_scheme": scheme, |
| 74 | + "versions": versions, |
| 75 | + }, |
| 76 | + "expected_output": output, |
| 77 | + } |
0 commit comments