diff --git a/Tests/Hypothesis/testAllegiance.py b/Tests/Hypothesis/testAllegiance.py index f086c557b..0b7fabf30 100644 --- a/Tests/Hypothesis/testAllegiance.py +++ b/Tests/Hypothesis/testAllegiance.py @@ -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 @@ -53,6 +53,7 @@ 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 = [ @@ -60,7 +61,11 @@ def test_allegiance_creation_without_specified_population(self, name, code, base "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: @@ -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) @@ -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) @@ -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)