Coverage for nlp_manager/tests/regex_read_codes_tests.py: 100%
16 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-08-27 10:34 -0500
« prev ^ index » next coverage.py v7.8.0, created at 2025-08-27 10:34 -0500
1"""
2crate_anon/nlp_manager/tests/regex_read_codes_tests.py
4===============================================================================
6 Copyright (C) 2015, University of Cambridge, Department of Psychiatry.
7 Created by Rudolf Cardinal (rnc1001@cam.ac.uk).
9 This file is part of CRATE.
11 CRATE is free software: you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 CRATE is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with CRATE. If not, see <https://www.gnu.org/licenses/>.
24===============================================================================
26Unit tests.
28"""
30# =============================================================================
31# Imports
32# =============================================================================
34import logging
35import unittest
37from crate_anon.nlp_manager.regex_read_codes import ReadCode, ReadCodes
39log = logging.getLogger(__name__)
42# =============================================================================
43# Unit tests
44# =============================================================================
47class ReadCodeRegexesTests(unittest.TestCase):
48 def test_read_code_regexes(self) -> None:
49 spacer = " "
50 for name, rc in ReadCodes.__dict__.items():
51 if name.startswith("_"):
52 continue
53 assert isinstance(rc, ReadCode)
54 phrases = "\n".join(f"{spacer}{x}" for x in rc.phrases)
55 regexes = "\n".join(
56 f"{spacer}{x}" for x in rc.component_regex_strings()
57 )
58 regex_str = rc.regex_str()
59 log.info(
60 f"Name: {name!r}.\n"
61 f"- Read code:\n{spacer}{rc.read_code}\n"
62 f"- Phrases:\n{phrases}\n"
63 f"- Regular expressions:\n{regexes}\n"
64 f"- Single regex string:\n{spacer}{regex_str}"
65 )
66 log.warning("No testing performed; just printed.")