Skip to content

Commit

Permalink
Fix test blast damage
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberiaResurrection committed Nov 8, 2023
1 parent 576c15a commit 2f0e738
Showing 1 changed file with 80 additions and 6 deletions.
86 changes: 80 additions & 6 deletions Tests/Hypothesis/testAllegiance.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def text_starts_with(draw, starts="Na", min_size=2, max_size=4):

@composite
def text_flanking_comma(draw):
before = draw(text(min_size=1, alphabet='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWYXZ -{}()[]?\'+*'))
after = draw(text(min_size=1, alphabet='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWYXZ -{}()[]?\'+*'))
before = draw(text(min_size=1, alphabet='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWYXZ -{}()?\'+*'))
after = draw(text(min_size=1, alphabet='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWYXZ -{}()?\'+*'))

return before + ',' + after

Expand All @@ -53,14 +53,19 @@ class testAllegiance(unittest.TestCase):
@example('', '', False)
@example('0,,', '00', True)
@example('0,,', '00', False)
@example('[', '', False)
def test_allegiance_creation_without_specified_population(self, name, code, base):
alg = None
allowed = [
"Name must be string - received",
"Code must be string - received",
"Code must not exceed 4 characters - received",
"Name must not be empty string",
"Name must have at most one comma"
"Name must have at most one comma",
"Name must not contain square brackets",
'First part of name string must not be an empty string itself',
'Second part of name string must not be an empty string itself',
'Name must not be pair of empty strings'
]

try:
Expand Down Expand Up @@ -94,7 +99,29 @@ def test_allegiance_creation_without_specified_population(self, name, code, base
@example('00 ', 'Na', False)
def test_allegiance_creation_with_nonaligned_code(self, name, code, base):
assume('' != name.strip())
alg = Allegiance(code, name, base)
alg = None
allowed = [
'First part of name string must not be an empty string itself',
'Name must not contain square brackets',
'Second part of name string must not be an empty string itself',
'Name must have at most one comma'
]

try:
alg = Allegiance(code, name, base)
except ValueError as e:
msg = str(e)
unexplained = True

for line in allowed:
if line in msg:
unexplained = False
break

if unexplained:
raise e

assume(alg is not None)

result, msg = alg.is_well_formed()
self.assertTrue(result, msg)
Expand All @@ -108,9 +135,34 @@ def test_allegiance_creation_with_nonaligned_code(self, name, code, base):
@example('0 ', 'Cs', True)
@example('0 0', 'Cs', False)
@example('0 0', 'Cs', False)
@example('00[', 'Cs', False)
@example('0,,', 'Cs', False)
def test_allegiance_creation_with_client_state_code(self, name, code, base):
assume('' != name.strip())
alg = Allegiance(code, name, base)
alg = None

allowed = [
'Name must not contain square brackets',
'First part of name string must not be an empty string itself',
'Second part of name string must not be an empty string itself',
'Name must have at most one comma'
]

try:
alg = Allegiance(code, name, base)
except ValueError as e:
msg = str(e)
unexplained = True

for line in allowed:
if line in msg:
unexplained = False
break

if unexplained:
raise e

assume(alg is not None)

result, msg = alg.is_well_formed()
self.assertTrue(result, msg)
Expand All @@ -122,7 +174,29 @@ def test_allegiance_creation_with_client_state_code(self, name, code, base):
)
def test_allegiance_creation_with_comma_in_name(self, name, code, base):
assume('' != name.strip())
alg = Allegiance(code, name, base)
alg = None

allowed = [
"Name must not be pair of empty strings",
'First part of name string must not be an empty string itself',
'Second part of name string must not be an empty string itself'
]

try:
alg = Allegiance(code, name, base)
except ValueError as e:
msg = str(e)
unexplained = True

for line in allowed:
if line in msg:
unexplained = False
break

if unexplained:
raise e

assume(alg is not None)

result, msg = alg.is_well_formed()
self.assertTrue(result, msg)
Expand Down

0 comments on commit 2f0e738

Please sign in to comment.