]> git.openstreetmap.org Git - nominatim.git/blobdiff - test/python/tokenizer/token_analysis/test_generic_mutation.py
enable flake for Python tests
[nominatim.git] / test / python / tokenizer / token_analysis / test_generic_mutation.py
index ea813bdc7f996e17c42ed1c90ae255d349fa0288..2ce2236a3c490762c965c42a75cdcc4344661c54 100644 (file)
@@ -2,7 +2,7 @@
 #
 # This file is part of Nominatim. (https://nominatim.org)
 #
 #
 # This file is part of Nominatim. (https://nominatim.org)
 #
-# Copyright (C) 2024 by the Nominatim developer community.
+# Copyright (C) 2025 by the Nominatim developer community.
 # For a full list of authors see the git log.
 """
 Tests for generic token analysis, mutation part.
 # For a full list of authors see the git log.
 """
 Tests for generic token analysis, mutation part.
@@ -12,7 +12,7 @@ import pytest
 from icu import Transliterator
 
 import nominatim_db.tokenizer.token_analysis.generic as module
 from icu import Transliterator
 
 import nominatim_db.tokenizer.token_analysis.generic as module
-from nominatim_core.errors import UsageError
+from nominatim_db.errors import UsageError
 
 DEFAULT_NORMALIZATION = """ '🜳' > ' ';
                             [[:Nonspacing Mark:] [:Cf:]] >;
 
 DEFAULT_NORMALIZATION = """ '🜳' > ' ';
                             [[:Nonspacing Mark:] [:Cf:]] >;
@@ -24,37 +24,34 @@ DEFAULT_TRANSLITERATION = """ ::  Latin ();
                               '🜵' > ' ';
                           """
 
                               '🜵' > ' ';
                           """
 
+
 class TestMutationNoVariants:
 
     def make_analyser(self, *mutations):
 class TestMutationNoVariants:
 
     def make_analyser(self, *mutations):
-        rules = { 'analyzer': 'generic',
-                  'mutations': [ {'pattern': m[0], 'replacements': m[1]}
-                                 for m in mutations]
-                }
+        rules = {'analyzer': 'generic',
+                 'mutations': [{'pattern': m[0], 'replacements': m[1]}
+                               for m in mutations]
+                 }
         trans = Transliterator.createFromRules("test_trans", DEFAULT_TRANSLITERATION)
         norm = Transliterator.createFromRules("test_norm", DEFAULT_NORMALIZATION)
         config = module.configure(rules, norm, trans)
 
         self.analysis = module.create(norm, trans, config)
 
         trans = Transliterator.createFromRules("test_trans", DEFAULT_TRANSLITERATION)
         norm = Transliterator.createFromRules("test_norm", DEFAULT_NORMALIZATION)
         config = module.configure(rules, norm, trans)
 
         self.analysis = module.create(norm, trans, config)
 
-
     def variants(self, name):
         norm = Transliterator.createFromRules("test_norm", DEFAULT_NORMALIZATION)
         return set(self.analysis.compute_variants(norm.transliterate(name).strip()))
 
     def variants(self, name):
         norm = Transliterator.createFromRules("test_norm", DEFAULT_NORMALIZATION)
         return set(self.analysis.compute_variants(norm.transliterate(name).strip()))
 
-
     @pytest.mark.parametrize('pattern', ('(capture)', ['a list']))
     def test_bad_pattern(self, pattern):
         with pytest.raises(UsageError):
             self.make_analyser((pattern, ['b']))
 
     @pytest.mark.parametrize('pattern', ('(capture)', ['a list']))
     def test_bad_pattern(self, pattern):
         with pytest.raises(UsageError):
             self.make_analyser((pattern, ['b']))
 
-
     @pytest.mark.parametrize('replacements', (None, 'a string'))
     def test_bad_replacement(self, replacements):
         with pytest.raises(UsageError):
             self.make_analyser(('a', replacements))
 
     @pytest.mark.parametrize('replacements', (None, 'a string'))
     def test_bad_replacement(self, replacements):
         with pytest.raises(UsageError):
             self.make_analyser(('a', replacements))
 
-
     def test_simple_replacement(self):
         self.make_analyser(('a', ['b']))
 
     def test_simple_replacement(self):
         self.make_analyser(('a', ['b']))
 
@@ -62,27 +59,23 @@ class TestMutationNoVariants:
         assert self.variants('abba') == {'bbbb'}
         assert self.variants('2 aar') == {'2 bbr'}
 
         assert self.variants('abba') == {'bbbb'}
         assert self.variants('2 aar') == {'2 bbr'}
 
-
     def test_multichar_replacement(self):
         self.make_analyser(('1 1', ['1 1 1']))
 
         assert self.variants('1 1456') == {'1 1 1456'}
         assert self.variants('1 1 1') == {'1 1 1 1'}
 
     def test_multichar_replacement(self):
         self.make_analyser(('1 1', ['1 1 1']))
 
         assert self.variants('1 1456') == {'1 1 1456'}
         assert self.variants('1 1 1') == {'1 1 1 1'}
 
-
     def test_removement_replacement(self):
         self.make_analyser((' ', [' ', '']))
 
         assert self.variants('A 345') == {'a 345', 'a345'}
         assert self.variants('a g b') == {'a g b', 'ag b', 'a gb', 'agb'}
 
     def test_removement_replacement(self):
         self.make_analyser((' ', [' ', '']))
 
         assert self.variants('A 345') == {'a 345', 'a345'}
         assert self.variants('a g b') == {'a g b', 'ag b', 'a gb', 'agb'}
 
-
     def test_regex_pattern(self):
         self.make_analyser(('[^a-z]+', ['XXX', ' ']))
 
         assert self.variants('a-34n12') == {'aXXXnXXX', 'aXXXn', 'a nXXX', 'a n'}
 
     def test_regex_pattern(self):
         self.make_analyser(('[^a-z]+', ['XXX', ' ']))
 
         assert self.variants('a-34n12') == {'aXXXnXXX', 'aXXXn', 'a nXXX', 'a n'}
 
-
     def test_multiple_mutations(self):
         self.make_analyser(('ä', ['ä', 'ae']), ('ö', ['ö', 'oe']))
 
     def test_multiple_mutations(self):
         self.make_analyser(('ä', ['ä', 'ae']), ('ö', ['ö', 'oe']))