From 8619f9f1afb2b949e853a8144a9f3d6a219352d0 Mon Sep 17 00:00:00 2001 From: Copeland Carter Date: Fri, 19 Apr 2024 00:52:21 -0600 Subject: [PATCH] Added, fixed some tests --- tests/data/regexs.jsonc | 7 +----- tests/test_invert.py | 14 ++---------- tests/test_python.py | 48 ++++++++++++++++++++++++++--------------- 3 files changed, 34 insertions(+), 35 deletions(-) diff --git a/tests/data/regexs.jsonc b/tests/data/regexs.jsonc index 5ebf1c9..c382971 100644 --- a/tests/data/regexs.jsonc +++ b/tests/data/regexs.jsonc @@ -350,7 +350,7 @@ ], [ "literal('test')", - ["test", " sdfstestsdfs",], + ["test", " sdfstestsdfs"], ["te st",] ], [ @@ -598,11 +598,6 @@ [], [] ], - [ - "group('', name='i') + optional(digit) + match_max(group('')) + amt(2, '')", - [], - [] - ], // ('foo' + ((chunk + 'here' + chunk) & (chunk + anyOf('this', 'that') + chunk)) + 'bar', ('fooum here there that bar', 'foo that there here bar'), None), // ('foo' + ((chunk + 'here' + chunk) & (chunk + anyOf('this', 'that') + chunk) & (chunk + 'the' + chunk)) + 'bar', ('fooum the here there that bar', 'foo that there thehere bar'), ('fooum here there that bar', 'foo that there here bar')), // (, (,), (,)), diff --git a/tests/test_invert.py b/tests/test_invert.py index f831731..1de8699 100644 --- a/tests/test_invert.py +++ b/tests/test_invert.py @@ -9,7 +9,7 @@ strictness=20 dontIncludePassed=True -invertBackend='re_parser' +invertBackend=... invert_tries=5 import jstyleson @@ -51,7 +51,7 @@ def do_test(): raise ValueError(f'Error @ approx. {__file__}, line {offset+(cnt*4)}: \nregex = `{r[0]}`') #from err#, inv = `{inv}`') thread = threading.Thread(target=do_test) thread.start() - limit = 15 + limit = 5 thread.join(timeout=limit) assert not thread.is_alive(), f"Invert took too long (>{limit} seconds): `{r[0]}`'" @@ -59,13 +59,3 @@ def do_test(): with open('summary.txt', 'w') as f: rprint(table, file=f) assert not len(table.rows) - - -def test_function(): - start_time = time.time() - for i in range(10): # Change 10 to whatever your loop range is - if time.time() - start_time > 5: - raise AssertionError("Iteration took too long!") - # Your loop code here - -test_function() diff --git a/tests/test_python.py b/tests/test_python.py index aa1623d..f2dfa1c 100644 --- a/tests/test_python.py +++ b/tests/test_python.py @@ -1,3 +1,4 @@ +import pytest from ezregex import python import jstyleson import ezregex as er @@ -5,23 +6,36 @@ from ezregex import * def test_python(): - offset = 2 - - with open('tests/data/regexs.jsonc') as f: - regexs = jstyleson.load(f) - - for cnt, r in enumerate(regexs): - regex_str, match, dontMatch = r - regex = eval(regex_str, python.__dict__) - # try: - if match: - for m in match: - assert m in regex, f"{r[0]} does not match '{m}'" - if dontMatch: - for m in dontMatch: - assert m not in regex, f"{r[0]} DOES match '{m}'" - # except Exception as err: - # raise ValueError(f'pattern = `{r[0]}`, match = `{match}`, dontMatch = `{dontMatch}`') from err + try: + with open('tests/data/regexs.jsonc') as f: + regexs = jstyleson.load(f) + + for cnt, r in enumerate(regexs): + regex_str, match, dontMatch = r + regex = eval(regex_str, python.__dict__) + # try: + if match: + for m in match: + assert m in regex, f"{r[0]} does not match '{m}'" + if dontMatch: + for m in dontMatch: + assert m not in regex, f"{r[0]} DOES match '{m}'" + except Exception as err: + raise AssertionError(f'pattern = `{r[0]}`, match = `{match}`, dontMatch = `{dontMatch}`') from err + + +def test_no_empty_strings(): + with pytest.raises(ValueError): + str(group('', name='i') + optional(digit)) + + with pytest.raises(ValueError): + str(match_max(group(''))) + + with pytest.raises(ValueError): + str(amt(2, '')) + + with pytest.raises(ValueError): + str(group('abc', name='')) def test_any_of():