Coverage for common/tests/stringfunc_tests.py: 100%
10 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/common/tests/stringfunc_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 testing.
28"""
30from unittest import TestCase
32from crate_anon.common.stringfunc import relevant_for_nlp
35# =============================================================================
36# Unit tests
37# =============================================================================
40class StringFuncTests(TestCase):
41 def test_relevant_for_nlp(self) -> None:
42 # fmt: off
43 relevant = [
44 "a",
45 "hello",
46 ".. .. // hello ..",
47 "Å, Ä + Ö", # not just English...
48 "Ä",
49 "ä",
50 "Å",
51 "å",
52 "É",
53 "é",
54 "Ö",
55 "ö",
56 ]
57 irrelevant = [
58 None,
59 "",
60 " ",
61 ".. .. // ..",
62 ]
63 # fmt: on
65 for r in relevant:
66 self.assertTrue(
67 relevant_for_nlp(r),
68 f"Should be relevant for NLP but being marked as "
69 f"irrelevant: {r!r}",
70 )
71 for i in irrelevant:
72 self.assertFalse(
73 relevant_for_nlp(i),
74 f"Should be irrelevant for NLP but being marked as "
75 f"relevant: {i!r}",
76 )