Skip to content

Commit

Permalink
Add unit tests for fixed issues
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroSteiner committed Jul 30, 2023
1 parent f7027d6 commit 8a25ade
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/rule_engine/debug_ast.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# rule_engine/debug_repl.py
# rule_engine/debug_ast.py
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
Expand Down Expand Up @@ -53,8 +53,10 @@ def main():

rule = engine.Rule(rule_text)
digraph = rule.to_graphviz()

digraph.save(arguments.output + '.gv')
_print_written(arguments.output + '.gv')

digraph.render(arguments.output)
_print_written(arguments.output + '.pdf')

Expand Down
18 changes: 18 additions & 0 deletions tests/issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import rule_engine.errors as errors
import rule_engine.types as types

import dateutil.tz

class GitHubIssueTests(unittest.TestCase):
def test_number_10(self):
value = random.randint(1, 10000)
Expand Down Expand Up @@ -95,3 +97,19 @@ def test_number_54(self):
for rule in rules:
with self.assertRaises(errors.FloatSyntaxError):
engine.Rule(rule)

def test_number_66(self):
rule = engine.Rule('$parse_datetime("2020-01-01")')
try:
result = rule.evaluate({})
except Exception:
self.fail('evaluation raised an exception')
self.assertEqual(result, datetime.datetime(2020, 1, 1, tzinfo=dateutil.tz.tzlocal()))

def test_number_68(self):
rule = engine.Rule('$min(items)')
try:
result = rule.evaluate({'items': [1, 2, 3, 4, 5, 6, 7, 8, 9]})
except Exception:
self.fail('evaluation raised an exception')
self.assertEqual(result, 1)

0 comments on commit 8a25ade

Please sign in to comment.