Debian Codegraph @

tests/res_test.py

raw
1 #!/usr/bin/env python3
2 # Copyright: 2026, Maximiliano Curia <[email protected]>
3 #
4 # License: ISC
5 # Permission to use, copy, modify, and/or distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 # .
9 # THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 # REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 # AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 # PERFORMANCE OF THIS SOFTWARE.
16
17 """Structural guards for the LICENSES_RES rule table wiring."""
18
19 import unittest
20
21 from decopy.licensing import res
22
23
24 class TestLicensesResWiring(unittest.TestCase):
25 """LICENSES_RES is the single, fully-wired public rule table.
26
27 Guards the two-pass wiring (exception_subs, then get_detail) that builds the
28 public tuple from the raw table: every rule of a family that declares a
29 family-level callback must end up carrying it.
30 """
31
32 def test_compiled_res_aligns_with_rule_table(self):
33 self.assertEqual(len(res.COMPILED_RES), len(res.LICENSES_RES))
34
35 def test_family_detail_is_wired_onto_every_family_rule(self):
36 for rule in res.LICENSES_RES:
37 if rule.license in res._FAMILY_DETAIL:
38 self.assertIsNotNone(
39 rule.get_detail,
40 f"{rule.license} rule missing wired get_detail",
41 )
42
43 def test_family_exception_subs_is_wired_onto_every_family_rule(self):
44 for rule in res.LICENSES_RES:
45 if rule.license in res._FAMILY_EXCEPTION_SUBS:
46 self.assertIsNotNone(
47 rule.exception_subs,
48 f"{rule.license} rule missing wired exception_subs",
49 )
50
51 def test_public_table_is_not_the_raw_table(self):
52 # The public tuple is the wired result, distinct from the raw literal.
53 self.assertIsNot(res.LICENSES_RES, res._RAW_LICENSES_RES)
54 self.assertEqual(len(res.LICENSES_RES), len(res._RAW_LICENSES_RES))
55
56
57 if __name__ == "__main__":
58 unittest.main()