Skip to content

Commit 37a50f1

Browse files
committed
Add tests for issues 98 and 104
1 parent e3d5ba7 commit 37a50f1

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

tests/issues.py

+17
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232

3333
import datetime
3434
import random
35+
import re
3536
import unittest
37+
import warnings
3638

3739
import rule_engine.engine as engine
3840
import rule_engine.errors as errors
@@ -113,3 +115,18 @@ def test_number_68(self):
113115
except Exception:
114116
self.fail('evaluation raised an exception')
115117
self.assertEqual(result, 1)
118+
119+
def test_number_98(self):
120+
value = re.escape("joe.blogs")
121+
122+
# Check if the some_attribute key in the dictionary matches 'joe.blogs' exactly
123+
with warnings.catch_warnings(record=True) as w:
124+
warnings.simplefilter('always', SyntaxWarning)
125+
engine.Rule(rf'some_attribute =~ "^{value}$"')
126+
for warning in w:
127+
if issubclass(warning.category, SyntaxWarning):
128+
self.fail('SyntaxWarning was raised')
129+
130+
def test_number_104(self):
131+
rule = engine.Rule(r"'André' in name")
132+
self.assertTrue(rule.matches({'name': 'André the Giant'}))

tests/parser.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def assertLiteralStatementEqual(self, string, ast_expression, python_value, msg=
282282
statement = self._parse(string, self.context)
283283
self.assertIsInstance(statement, ast.Statement, msg='the parser did not return a statement')
284284
self.assertIsInstance(statement.expression, ast_expression, msg='the statement expression is not the correct literal type')
285-
self.assertEqual(statement.expression.value, python_value, msg=msg or "{0!r} does not evaluate to {1!r}".format(string, python_value))
285+
self.assertEqual(python_value, statement.expression.value, msg=msg or "{0!r} does not evaluate to {1!r}".format(string, python_value))
286286

287287
def test_parse_array(self):
288288
self.assertLiteralStatementEvalEqual('[ ]', tuple())

0 commit comments

Comments
 (0)