Skip to content

Commit

Permalink
Added, fixed some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
smartycope committed Apr 19, 2024
1 parent aae093c commit 8619f9f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 35 deletions.
7 changes: 1 addition & 6 deletions tests/data/regexs.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@
],
[
"literal('test')",
["test", " sdfstestsdfs",],
["test", " sdfstestsdfs"],
["te st",]
],
[
Expand Down Expand Up @@ -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')),
// (, (,), (,)),
Expand Down
14 changes: 2 additions & 12 deletions tests/test_invert.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

strictness=20
dontIncludePassed=True
invertBackend='re_parser'
invertBackend=...
invert_tries=5
import jstyleson

Expand Down Expand Up @@ -51,21 +51,11 @@ 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]}`'"

if len(table.rows):
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()
48 changes: 31 additions & 17 deletions tests/test_python.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,41 @@
import pytest
from ezregex import python
import jstyleson
import ezregex as er
from ezregex import EZRegex
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():
Expand Down

0 comments on commit 8619f9f

Please sign in to comment.