Skip to content

Commit

Permalink
Add tests for issues 98 and 104
Browse files Browse the repository at this point in the history
zeroSteiner committed Jan 30, 2025
1 parent e3d5ba7 commit 37a50f1
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions tests/issues.py
Original file line number Diff line number Diff line change
@@ -32,7 +32,9 @@

import datetime
import random
import re
import unittest
import warnings

import rule_engine.engine as engine
import rule_engine.errors as errors
@@ -113,3 +115,18 @@ def test_number_68(self):
except Exception:
self.fail('evaluation raised an exception')
self.assertEqual(result, 1)

def test_number_98(self):
value = re.escape("joe.blogs")

# Check if the some_attribute key in the dictionary matches 'joe.blogs' exactly
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always', SyntaxWarning)
engine.Rule(rf'some_attribute =~ "^{value}$"')
for warning in w:
if issubclass(warning.category, SyntaxWarning):
self.fail('SyntaxWarning was raised')

def test_number_104(self):
rule = engine.Rule(r"'André' in name")
self.assertTrue(rule.matches({'name': 'André the Giant'}))
2 changes: 1 addition & 1 deletion tests/parser.py
Original file line number Diff line number Diff line change
@@ -282,7 +282,7 @@ def assertLiteralStatementEqual(self, string, ast_expression, python_value, msg=
statement = self._parse(string, self.context)
self.assertIsInstance(statement, ast.Statement, msg='the parser did not return a statement')
self.assertIsInstance(statement.expression, ast_expression, msg='the statement expression is not the correct literal type')
self.assertEqual(statement.expression.value, python_value, msg=msg or "{0!r} does not evaluate to {1!r}".format(string, python_value))
self.assertEqual(python_value, statement.expression.value, msg=msg or "{0!r} does not evaluate to {1!r}".format(string, python_value))

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

0 comments on commit 37a50f1

Please sign in to comment.