Skip to content

Commit bb14f7c

Browse files
author
Steve Ayers
committed
Use find_spec
1 parent 8e40f7d commit bb14f7c

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ dependencies = [
2626
]
2727
[project.optional-dependencies]
2828
re2 = [
29-
"google-re2",
29+
"google-re2==1.*",
3030
]
3131

3232
[project.urls]

test/test_matches.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,33 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import importlib.util
1516
import unittest
1617

1718
import celpy
1819
from celpy import celtypes
1920

20-
from protovalidate.internal.extra_func import cel_matches_re2, cel_matches_re
21+
from protovalidate.internal.extra_func import cel_matches_re, cel_matches_re2
2122

2223
_USE_RE2 = True
23-
try:
24-
import re2 # type: ignore
25-
except ImportError:
24+
spec = importlib.util.find_spec("re2")
25+
if spec is None:
2626
_USE_RE2 = False
2727

28-
class TestCollectViolations(unittest.TestCase):
2928

29+
class TestCollectViolations(unittest.TestCase):
3030
@unittest.skipUnless(_USE_RE2, "Requires 're2'")
3131
def test_function_matches_re2(self):
3232
empty_string = celtypes.StringType("")
3333
# \z is valid re2 syntax for end of text
34-
assert cel_matches_re2(empty_string, "^\\z")
34+
self.assertTrue(cel_matches_re2(empty_string, "^\\z"))
3535
# \Z is invalid re2 syntax
36-
assert isinstance(cel_matches_re2(empty_string, "^\\Z"), celpy.CELEvalError)
36+
self.assertIsInstance(cel_matches_re2(empty_string, "^\\Z"), celpy.CELEvalError)
3737

3838
@unittest.skipUnless(_USE_RE2 is False, "Requires 're'")
3939
def test_function_matches_re(self):
4040
empty_string = celtypes.StringType("")
4141
# \z is invalid re syntax
42-
assert isinstance(cel_matches_re(empty_string, "^\\z"), celpy.CELEvalError)
42+
self.assertIsInstance(cel_matches_re(empty_string, "^\\z"), celpy.CELEvalError)
4343
# \Z is valid re syntax for end of text
44-
assert cel_matches_re(empty_string, "^\\Z")
44+
self.assertTrue(cel_matches_re(empty_string, "^\\Z"))

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)