Creates a registry for tracking which operators have been tested. Returns a SignOff instance that can be used in two ways: 1. As a decorator to mark tests: @sign_off("operator_name") 2. As a direct registration call inside tests: sign_off.register_test("operator_name") Both pa
()
| 977 | |
| 978 | |
| 979 | def create_sign_off_registry(): |
| 980 | """ |
| 981 | Creates a registry for tracking which operators have been tested. |
| 982 | |
| 983 | Returns a SignOff instance that can be used in two ways: |
| 984 | 1. As a decorator to mark tests: @sign_off("operator_name") |
| 985 | 2. As a direct registration call inside tests: sign_off.register_test("operator_name") |
| 986 | |
| 987 | Both patterns add operators to the same registry, which can be queried |
| 988 | via the `tested_ops` property. |
| 989 | |
| 990 | Returns: |
| 991 | SignOff: An instance with methods for registering tested operators. |
| 992 | |
| 993 | Example usage: |
| 994 | # Create a registry instance |
| 995 | sign_off = create_sign_off_registry() |
| 996 | |
| 997 | # Pattern 1: Decorator style |
| 998 | @sign_off("operators.add", "operators.subtract") |
| 999 | def test_arithmetic_ops(): |
| 1000 | # Test implementation |
| 1001 | |
| 1002 | # Pattern 2: Direct registration inside test |
| 1003 | def test_conditional_ops(): |
| 1004 | sign_off.register_test("operators.multiply") |
| 1005 | # Test implementation |
| 1006 | |
| 1007 | # Check which operators were tested |
| 1008 | print(sign_off.tested_ops) |
| 1009 | # Output: {'operators.add', 'operators.subtract', 'operators.multiply'} |
| 1010 | |
| 1011 | Note: |
| 1012 | Each call to create_sign_off_registry() creates an independent registry |
| 1013 | with its own operator tracking. Multiple references to the same instance |
| 1014 | share the same registry. |
| 1015 | """ |
| 1016 | _tested_ops = set() |
| 1017 | |
| 1018 | class SignOff: |
| 1019 | def __call__(self, *op_names): |
| 1020 | """Use as decorator: @sign_off("operator_name")""" |
| 1021 | self.register_test(*op_names) |
| 1022 | |
| 1023 | def dummy(fn): |
| 1024 | return fn |
| 1025 | |
| 1026 | return dummy |
| 1027 | |
| 1028 | def register_test(self, *op_names): |
| 1029 | """Use directly in test: sign_off.register_test("operator_name")""" |
| 1030 | assert all(isinstance(op_name, str) for op_name in op_names) |
| 1031 | assert len(op_names) |
| 1032 | _tested_ops.update(op_names) |
| 1033 | |
| 1034 | @property |
| 1035 | def tested_ops(self): |
| 1036 | return _tested_ops |
no test coverage detected