Coverage for nlp_manager/tests/all_processors_tests.py: 95%
21 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/all_processors_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===============================================================================
26**Test all simple regexes and regex-based NLP parsers.**
28"""
30import logging
31import unittest
33from crate_anon.common.constants import JSON_INDENT
34from crate_anon.nlp_manager.all_processors import all_local_parser_classes
35from crate_anon.nlprp.constants import SqlDialects
37log = logging.getLogger(__name__)
40# =============================================================================
41# Unit tests
42# =============================================================================
45class NlpProcessorsTests(unittest.TestCase):
46 @staticmethod
47 def test_all_processors() -> None:
48 """
49 Self-tests all NLP processors.
50 """
51 verbose = True
52 skip_validators: bool = False
54 for cls in all_local_parser_classes():
55 if skip_validators and cls.classname().endswith("Validator"):
56 continue
57 log.info("Testing parser class: {}".format(cls.classname()))
58 instance = cls(None, None)
59 log.info("... instantiated OK")
60 schema_json = instance.nlprp_processor_info_json(
61 indent=JSON_INDENT,
62 sort_keys=True,
63 sql_dialect=SqlDialects.MYSQL,
64 )
65 log.info(f"NLPRP processor information:\n{schema_json}")
66 instance.test(verbose=verbose)
67 log.info("Tests completed successfully.")