Skip to content

Commit

Permalink
Wring out set_wiki_name
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberiaResurrection committed Nov 8, 2023
1 parent fd2cc9c commit 28e09ee
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
9 changes: 9 additions & 0 deletions PyRoute/Galaxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,19 @@ def set_wiki_name(name, code, base):
name = name.strip()
if '' == name:
raise ValueError("Name must not be empty string")
if ',' == name:
raise ValueError("Name must not be pair of empty strings")
if '[' in name or ']' in name:
raise ValueError("Name must not contain square brackets")

names = name.split(',') if ',' in name else [name, '']
names[0] = names[0].strip()
names[1] = names[1].strip()
if '' == names[0]:
raise ValueError("First part of name string must not be an empty string itself")
if '' == names[1]:
raise ValueError("Second part of name string must not be an empty string itself")

if code.startswith('Na'):
return '[[{}]] {}'.format(names[0], names[1])
elif code.startswith('Cs'):
Expand Down
22 changes: 18 additions & 4 deletions Tests/Hypothesis/testAllegiance.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
from PyRoute.Galaxy import Allegiance

@composite
def text_or_none(draw):
def text_or_none(draw, alphabet=None):
choice = draw(floats(min_value=0.0, max_value=1.0))

if 0.8 < choice:
return None

if alphabet is not None:
return draw(text(alphabet=alphabet))
return draw(text())

@composite
Expand Down Expand Up @@ -125,20 +127,32 @@ def test_allegiance_creation_with_comma_in_name(self, name, code, base):
result, msg = alg.is_well_formed()
self.assertTrue(result, msg)

@given(text_or_none(), text_or_none(), booleans())
@settings(max_examples=1100)
@given(
text_or_none(alphabet=',0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWYXZ -{}()[]?\'+*'),
text_starts_with(starts="Na"),
booleans()
)
@settings(suppress_health_check=[HealthCheck(3), HealthCheck(2)])
@example(None, None, True)
@example(None, None, False)
@example('', None, True)
@example('', None, False)
@example(',', '', False)
@example('0,', '', False)
@example(',0', '', False)
@example('[,0', 'Na', False)
@example('],0', 'Na', False)
def test_set_wiki_name(self, name, code, base):
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 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",
"Name must not contain square brackets"
]

wiki_name = None
Expand Down

0 comments on commit 28e09ee

Please sign in to comment.