diff --git a/PyRoute/Inputs/BaseTransformer.py b/PyRoute/Inputs/BaseTransformer.py index 7bf6acbd5..c2db91dd9 100644 --- a/PyRoute/Inputs/BaseTransformer.py +++ b/PyRoute/Inputs/BaseTransformer.py @@ -29,31 +29,55 @@ def __init__(self, visit_tokens: bool = True, raw=None): self.crankshaft = False def starline(self, args): - tradelen = sum([len(item) for item in args[2]]) + len(args[2]) - 1 - if 16 < tradelen and 3 <= len(args[2]) and 1 == len(args[3]) and '' == args[3][0].value.strip(): # Square up overspilled trade codes - if '' == args[4][0].value and '' != args[5][0].value and '' == args[6][0].value: - move_fwd = 3 == len(args[5][0].value) and args[5][0].value[0].isdigit() # Will base code still make sense as PBG? - move_rev = 3 == len(args[7][2][0].value) # Will allegiance code still make sense as PBG? + # These are the as-parsed values, and we're confirming the values as needed + trade = args[2] + extensions = args[3] + nobles = args[4].children[0][0] + base = args[4].children[1][0] + zone = args[4].children[2][0] + pbg = args[5][0][0] + worlds = args[5][1][0] if 1 < len(args[5]) else Token('__ANON__11', ' ') + allegiance = args[5][2][0] if 2 < len(args[5]) else Token('__ANON__12', ' ') + + tradelen = sum([len(item) for item in trade]) + len(trade) - 1 + if 16 < tradelen and 3 <= len(trade) and 1 == len(extensions) and '' == extensions[0].value.strip(): # Square up overspilled trade codes + if '' == nobles.value and '' != base.value and '' == zone.value: + move_fwd = 3 == len(base.value) and base.value.isdigit() # Will base code still make sense as PBG? + move_rev = 3 == len(allegiance.value) # Will allegiance code still make sense as PBG? if move_fwd and not move_rev: - last = args[2][-1] - mid = args[2][-2] - args[6][0].value = args[5][0].value - args[5][0].value = last - args[4][0].value = mid - args[2] = args[2][:-2] + last = trade[-1] + mid = trade[-2] + zone.value = base.value + base.value = last + nobles.value = mid + trade = trade[:-2] elif move_rev and not move_fwd: pass elif move_fwd and move_rev: pass - if '*' != args[5][0].value and '' != args[5][0].value and 3 != len(args[3]): - if not self.crankshaft and args[6][0].value.upper() not in self.zone_active: - if '' == args[4][0].value: - args[4][0].value = args[5][0].value - args[5][0].value = args[6][0].value - elif '' == args[6][0].value: # if only 1 extension child? - args[6][0].value = args[5][0].value - args[5][0].value = args[4][0].value - args[4][0].value = '' + + if '*' != base.value and '' != base.value and 3 != len(extensions): + if not self.crankshaft and zone.value.upper() not in self.zone_active: + if '' == nobles.value: + nobles.value = base.value + base.value = zone.value + elif '' == zone.value: # if only 1 extension child? + zone.value = base.value + base.value = nobles.value + nobles.value = '' + elif '*' != base.value and 3 == len(extensions): + if '' == nobles.value and '' != base.value and '' == zone.value: + if pbg.value == allegiance.value: + nobles.value = base.value + base.value = pbg.value + zone.value = worlds.value + pbg.value = allegiance.value + worlds.value = ' ' + if 7 == len(args): + allegiance.value = args[6][0].value + args[6][0].value = '' + else: + allegiance.value = '' if 8 == len(args): # If there's no residual argument if 1 < len(args[7]): tailend = args[7][2][0].value @@ -98,10 +122,14 @@ def nobles(self, args): def base(self, args): args[0].value = args[0].value.strip() + if '' == args[0].value: + args[0].value = '-' return args def zone(self, args): args[0].value = args[0].value.strip() + if '' == args[0].value: + args[0].value = '-' return args def pbg(self, args): @@ -143,7 +171,7 @@ def trade_transform(self, trade): def extensions_transform(self, extensions): if 1 == len(extensions): # Fallback no-extensions return None, None, None - data = {} + data = {'ix': '', 'ex': '', 'cx': ''} for kid in extensions: if isinstance(kid, Token): val = str(kid.type) @@ -163,11 +191,10 @@ def world_alg_transform(self, world_alg): return world_alg[0][0].value, world_alg[1][0].value, world_alg[2][0].value def transform(self, tree): - self.crankshaft = '' == tree.children[4].children[0].value.strip() and '-' == tree.children[5].children[ - 0].value and '' == tree.children[6].children[0].value.strip() and 1 == self.raw.count(' -') and 1 == self.raw.count('- ') + self.crankshaft = '' == tree.children[4].children[0].children[0].value.strip() and '-' == tree.children[4].children[ + 1].children[0].value and '' == tree.children[4].children[2].children[0].value.strip() and 1 == self.raw.count(' -')\ + and 1 == self.raw.count('- ') tree = self._preprocess_trade_and_extensions(tree) - tree = self._preprocess_extensions_and_nbz(tree) - tree = self._preprocess_trade_and_nbz(tree) tree = self._preprocess_tree_suspect_empty_trade_code(tree) tree = self._transform_tree(tree) parsed = {'ix': None, 'ex': None, 'cx': None, 'residual': ''} @@ -176,12 +203,12 @@ def transform(self, tree): parsed['name'], parsed['uwp'] = self.starname_transform(tree[1][0].value) parsed['trade'] = self.trade_transform(tree[2]) parsed['ix'], parsed['ex'], parsed['cx'] = self.extensions_transform(tree[3]) - parsed['nobles'] = tree[4][0].value - parsed['base'] = tree[5][0].value - parsed['zone'] = tree[6][0].value - parsed['pbg'], parsed['worlds'], parsed['allegiance'] = self.world_alg_transform(tree[7]) - if 9 == len(tree): - parsed['residual'] = tree[8][0].value + parsed['nobles'] = tree[4].children[0][0].value + parsed['base'] = tree[4].children[1][0].value + parsed['zone'] = tree[4].children[2][0].value + parsed['pbg'], parsed['worlds'], parsed['allegiance'] = self.world_alg_transform(tree[5]) + if 7 == len(tree): + parsed['residual'] = tree[6][0].value parsed = self._square_up_parsed(parsed) self.trim_raw_string(parsed) @@ -235,71 +262,6 @@ def _preprocess_trade_and_extensions(self, tree): return tree - def _preprocess_extensions_and_nbz(self, tree): - extensions = tree.children[3] - if 5 > len(extensions.children): # Nothing to move around, bail out - return tree - - nobles = tree.children[4] - # base = tree.children[5] - zone = tree.children[6] - - nobles.children[0].value = extensions.children[4].value - if 5 < len(extensions.children): - zone.children[0].value = extensions.children[5].value - - return tree - - def _preprocess_trade_and_nbz(self, tree): - from PyRoute.Inputs.ParseStarInput import ParseStarInput - trade = tree.children[2] - tradelen = sum([len(item.value) for item in trade.children]) + (len(trade.children) - 1) - if 17 > tradelen: - return tree - - trade_last = trade.children[-1].value - trade_final_keep = trade_last.startswith('O:') or trade_last.startswith('C:') - if trade_final_keep: - return tree - - starname = tree.children[1].children[0].value - bitz = starname.split(' ') - bitz = [item for item in bitz if '' != item] - rawbitz = self.raw.split(bitz[-1]) - - if ParseStarInput.can_be_nobles(tree.children[4].children[0].value) and \ - ParseStarInput.can_be_base(tree.children[5].children[0].value): - overrun = 0 - else: - overrun = self._calc_trade_overrun(trade.children, rawbitz[1]) - if 0 == overrun: # if the reconstructed trade code is fully in the raw string, nothing to do - bail out now - return tree - nobles = tree.children[4] - base = tree.children[5] - zone = tree.children[6] - - if 0 < overrun: - relocate = trade.children[-overrun:] - if 1 == overrun: - relval = relocate[0].value - if '*' == relval: - zone.children[0].value = base.children[0].value - base.children[0].value = relval - nobles.children[0].value = '' - else: - zone.children[0].value = base.children[0].value - base.children[0].value = nobles.children[0].value - nobles.children[0].value = relval - trade.children = trade.children[:-1] - elif 2 == overrun: - if '' == nobles.children[0].value.strip() and '' == zone.children[0].value.strip(): - zone.children[0].value = base.children[0].value - base.children[0].value = relocate[1].value - nobles.children[0].value = relocate[0].value - trade.children = trade.children[:-2] - - return tree - def _is_noble(self, noble_string): noble = "BCcDEeFfGH" return all(char in noble for char in noble_string) @@ -322,11 +284,11 @@ def _preprocess_tree_suspect_empty_trade_code(self, tree): all_noble = self._is_noble(tree.children[2].children[0]) if not all_noble: return tree - if self._is_zone(tree.children[6].children[0].value.strip()): + if self._is_zone(tree.children[4].children[2].children[0].value.strip()): return tree - tree.children[6].children[0].value = tree.children[5].children[0].value - tree.children[5].children[0].value = tree.children[4].children[0].value - tree.children[4].children[0].value = tree.children[2].children[0].value + tree.children[4].children[2].children[0].value = tree.children[4].children[1].children[0].value + tree.children[4].children[1].children[0].value = tree.children[4].children[0].children[0].value + tree.children[4].children[0].children[0].value = tree.children[2].children[0].value tree.children[2].children[0].value = "" return tree diff --git a/PyRoute/Inputs/StarlineParser.py b/PyRoute/Inputs/StarlineParser.py index 89ec68d58..acf3a0286 100644 --- a/PyRoute/Inputs/StarlineParser.py +++ b/PyRoute/Inputs/StarlineParser.py @@ -16,7 +16,7 @@ def dashrepl(m): class StarlineParser: starline_grammar = r""" - starline: position starname trade extensions nobles base zone world_alg residual? + starline: position starname trade extensions nbz world_alg residual? position: /^((?:0[1-9]|[1-2]\d|3[0-2])(?:0[1-9]|40|[1-3]\d))/ @@ -40,7 +40,9 @@ class StarlineParser: ex: /\([0-9A-Za-z]{3}[+-]\d\)|-/ cx: /(\[[0-9A-Za-z]{4}[\]\}]|-)/ - nobles: /([BcCDeEfFGH]{1,5}|-| ) / + nbz: nobles base zone + + nobles: /([BcCDeEfFGH]{1,5}|-| )/ base: /([A-Z]{1,3}|-|\*) / diff --git a/PyRoute/Inputs/StarlineStationParser.py b/PyRoute/Inputs/StarlineStationParser.py index 1c616a788..4ef0e8d9b 100644 --- a/PyRoute/Inputs/StarlineStationParser.py +++ b/PyRoute/Inputs/StarlineStationParser.py @@ -16,7 +16,7 @@ def dashrepl(m): class StarlineStationParser: starline_grammar = r""" - starline: position starname trade extensions nobles base zone world_alg? residual? + starline: position starname trade extensions nbz world_alg? residual? position: /^((?:0[1-9]|[1-2]\d|3[0-2])(?:0[1-9]|40|[1-3]\d))/ @@ -40,7 +40,9 @@ class StarlineStationParser: ex: /\([0-9A-Za-z]{3}[+-]\d\)|-/ cx: /(\[[0-9A-Za-z]{4}[\]\}]|-)/ - nobles: /([BcCDeEfFGH]{1,5}|-| ) / + nbz: nobles base zone + + nobles: /([BcCDeEfFGH]{1,5}|-| )/ base: /([A-Z]{1,3}|-|\*) / diff --git a/Tests/Hypothesis/testDeltaStar.py b/Tests/Hypothesis/testDeltaStar.py index 1d5fb3b49..a07bc2961 100644 --- a/Tests/Hypothesis/testDeltaStar.py +++ b/Tests/Hypothesis/testDeltaStar.py @@ -28,7 +28,7 @@ def trade_code(draw): @composite -def starline(draw): +def starline(draw, barren_world=False): col = draw(integers(min_value=1, max_value=32)) row = draw(integers(min_value=1, max_value=40)) posn = str(col).rjust(2, '0') + str(row).rjust(2, '0') @@ -39,9 +39,13 @@ def starline(draw): uwp_alphabet = '0123456789ABCDEFGH' uwp = port + draw(text(min_size=6, max_size=6, alphabet=uwp_alphabet)) + '-' + draw(text(min_size=1, max_size=1, alphabet=uwp_alphabet)) + if barren_world: + uwp = uwp[0:4] + "0" + uwp[5:] # TODO - tradecode picks trade_array = draw(trade_code()) + if barren_world: + trade_array.append('Ba') tradeCodes = ' '.join(trade_array) extension_alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' @@ -372,7 +376,7 @@ def test_canonicalise_missing_trade_codes(self, starline): badline = '' if 0 == len(invalid) else invalid[0] self.assertEqual(0, len(invalid), 'At least one missing trade code not added: \n' + starline + '\n' + badline) - @given(starline()) + @given(starline(barren_world=True)) @settings(suppress_health_check=[HealthCheck(3), HealthCheck(2)], deadline=timedelta(1000)) @example('0101 0 A000000-0 As Ba { 0 } (000+0) [0001] - - A 000 0 NaHu G5 V') @example('0101 0 A000000-0 As Ba { 0 } (000+0) [0010] - - A 000 0 NaHu G5 V') diff --git a/Tests/Hypothesis/testStar.py b/Tests/Hypothesis/testStar.py index 734624cca..a58109ed3 100644 --- a/Tests/Hypothesis/testStar.py +++ b/Tests/Hypothesis/testStar.py @@ -80,86 +80,87 @@ def setUp(self) -> None: """ Given a regex-matching string, parse_line_to_star should return either a valid Star object or None """ - @given(from_regex(regex=ParseStarInput.starline, alphabet='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWYXZ -{}()[]?\'+*')) + @given(from_regex(regex=ParseStarInput.starline, alphabet='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWYXZ -{}()[]?\'+*'), none()) @settings(suppress_health_check=[HealthCheck(3), HealthCheck(2)], deadline=timedelta(1000)) # suppress slow-data health check, too-much filtering - @example('0101 000000000000000 00000O0-0 000000000000000 - - 0 000 00') - @example('0101 000000000000000 ???????-? 000000000000000 {0} (000-0) - - - 0 000 00') - @example('0101 000000000000000 00000ź0-0 000000000000000 {0} - [0000] - - 0 000 00') - @example('0101 000000000000000 ?000000-0 000000000000000 {0} (000-0) [0000] - - 0 000 00') - @example('0101 000000000000000 ???????-? 000000000000000 {0} - [0000] - - 0 000 00') - @example('0150 000000000000000 ???????-? 000000000000000 {0} - [0000] - - 0 000 00') - @example('0101 000000000000000 ?000000-0 000000000000000 {0} (000-0) [0000] - - 0 000 00') - @example('0101 000000000000000 ???????-? 0000000000000 0 - - 0 000 00') - @example('0101 000000000000000 ???????-? 000000000000000 {0} (000-0) - - - 0 000 0000D') - @example('0101 000000000000000 ???????-? 000000000000000 - - 0 000 0000BDD') - @example('0101 000000000000000 ???????-? 000000000000000 - - 0 000 0000D') - @example('0101 000000000000000 ???????-? 000000000000000 - - 0 00A 0000D') - @example('0101 000000000000000 ???????-? 000000000000000 - - 0 0A0 0000D') - @example('0101 000000000000000 ???????-? 000000000000000 - - 0 000 0000D') - @example('0101 000000000000000 ???????-? 000 0000000BCDEFG - - 0 000 00') - @example('0101 000000000000000 ???????-? (000000000000)00 - 0 000 00') - @example('0101 000000000000000 ???????-? 000000000000000 - - 0 000 10 +') - @example('0101 000000000000000 ???????-? 000000000000000 - - 0 000 00 0') - @example('0101 000000000000000 ???????-? 000000000000000 - 001 000') - @example('0101 000000000000000 ???????-? 000000000000000 - 000 A00') - @example('0101 000000000000000 ???????-? 000000000000000 - 000 00') - @example('0101 000000000000000 ???????-? 000000000000000 - 000 0 ?00 00') - @example('0101 000000000000000 0000000-0 000000000000000 0 0 0 000 000 000+') - @example('0101 000000000000000 ???????-? {0}000000000000 - - 0 000 00') - @example('0101 000000000000000 ???????-? 000000000000000 {0} (000-0) [0000] - a 000 00') - @example('0101 000000000000000 ???????-? 000000000000000 a - 000 00') - @example('0101 000000000000000 ???????-? 00000000000+ 0 - a 000 00') - @example('0101 000000000000000 ???????-? 000000000000000 c - 000 00') - @example('0101 000000000000000 ???????-? 00000000+ 0000 - 000 00') - @example('0101 000000000000000 ???????-? 000000000000000 { -0} - - c - 000 00') - @example('0101 000000000000000 A0000y0-0 000000000000000 - - 0 000 0000D') - @example('0110 000000000000000 ???????-? 000000000000000 H B A 000 0 00') - @example('0110 000000000000000 ???????-? 000000000000000 e - A 000 00') - @example('0101 000000000000000 0000000-0 0000000000000 B - A A 000 00') - @example('0101 000000000000000 0000000-0 [00000000000000 - - [0000] - - A 000 00') - @example('0110 000000000000000 ???????-? 0000000000 (000 - (000-0) [0000] - - A 000 0 00') - @example('0101 000000000000000 0000000-0 000000000000000 BB A A 000 0 00') - @example('0101 000000000000000 ???????-? 0000000000000 0 0 B - A 000 00') - @example('0101 000000000000000 ???????-? 000000000000000 {-0} (000-0) - * A 000 00') - @example('0101 000000000000000 ???????-? 000000000000000 {-0} (000-0) - - - A 000 00') - @example("0101 000000000000000 ?000000-0 {3 } (7TG-1) [2IBt] EHEG - 569 9 C5'") - @example('0101 000000000000000 ???????-? 0000000000000 B - - A 000 00') - @example('0101 111111111111000 A000011-1 000000000000100 {0} (100-0) - - - B 001 10') - @example('1804 ORx}KK-E66IM+\'RwvRrB1 ???????-? bI9cqWeGEH9jJlGJi7 { -2} - - FEee A 48X 11{2l') - @example('1804 0ORx}KK-E6wvRrB1 ???????-? bI9cqWeGEH9jJlGJ { -2} - - FEee A 48X 11{2l') - @example('0603 Xfdr5TXRv*E?Nwk ecUr4ug-c 26yTW ?tP0 AVh5X+ AAA 7XX 11') - @example('0408 10B1616111MOBeZ A000001-1 G(mdVjYHP)V*jEz BCFG - 011 2X0') - @example('0101 000000000000000 A000000-0 000000000000000 {0} (000+0) - DFBe - A 000 14 ) T5neYuvB1') - @example('0101 000011111111000 A000011-1 000000000000101 {0} - - B - A 000 00 m0') - @example('0101 000000000000000 A000000-0 (00000000000000 - (000-0) [0010] BBB - A 000 00u?2{KjY') - @example('0101 000000000000000 f72110b-1 00 317TbjkYG3u}(f) G - A 000 01') - @example('2040 JH*U1CnPh(Gtg00 ???????-? 11222[aQg)V]111 - - A 000 00 2}iK') - @example('0140 000000000000000 ???????-? 0000000000000 0 - - A 000 100 00') - @example('0940 ouV)anTg*V0QDeNL ???????-? ]naJy2GDuB{hq8qG - - [ouJB] - XFX X01 11') - @example('0101 000000000000000 ???????-? B 0000000000000 - - A 000 --0') - @example('0205 b9N00077 ???????-? B - * A ?E3 --B1n') - @example('0101 000000000000000 ???????-? B 0000000000000 - - A 000 --00') - @example('0140 116EFJ0( cdvw{ A000000-0 } 0000000000000 - - A 000 00') - @example('0101 000000000000000 ???????-? 0000000 0000000 C - A 000 00') - @example('0101 000000000000000 ???????-? 000000 00000000 C - A 000 00') - @example('0140 111111111111111 A000000-1 1 0000000000000 C - A 000 00') - @example('0140 000000000000000 A000000-0 F 0000000000000 C - F 000 00') - @example('0940 ouV)anT-eB00111 A111110-X RH?xJy Hcb-O-a} ov4111111 EBCCH - B 2FA 070R') - @example('0940 ouV)anT-eB00111 ?11111A-X ?HHJOR-- abcxy} 1 BCCE - B 001 00R') - @example('0140 000000000000000 A000000-0 00 0000000 + 0 00 - A 000 00') - @example('0140 000000000000000 ???????-? 0000000000000 0 De * A ?00 00') - @example('0140 000000000000000 ???????-? [00r0MOW0 mw}]C BB - A 000 00') - @example('0140 000000000000000 ???????-? 0000000000000 C BB B A 000 00') - @example('0101 000000000000000 ???????-? 000000000000000 De - A ?00 00') - @example('0140 ]00111111111111 ???????-? 111111111111111 - - [0100] - 010 010') - @example('0101 000000000000000 ???????-? [000000000000]( - - A 000 00)') - @example('0101 000000000000000 ???????-? [000000000000]X - - A 000 00)') - @example('0101 000000000000000 ???????-? [0000000000)(]( - - A 000 00)') - @example('0101 000000000000000 ???????-? [000000000000000000000000000000000000]? - - A 000 00') - @example('0101 02111111111111) ???????-? [oPrh00011111GitpHqwhA{KRNf{rpjqI}7bj]A - - B 000 100') - @example('0101 000000000000000 ???????-? [0000000)(]X [ - - B 001 100') - def test_parse_line_to_star(self, s): + @example('0101 000000000000000 00000O0-0 000000000000000 - - 0 000 00', '') + @example('0101 000000000000000 ???????-? 000000000000000 {0} (000-0) - - - 0 000 00', '') + @example('0101 000000000000000 00000ź0-0 000000000000000 {0} - [0000] - - 0 000 00', '') + @example('0101 000000000000000 ?000000-0 000000000000000 {0} (000-0) [0000] - - 0 000 00', '') + @example('0101 000000000000000 ???????-? 000000000000000 {0} - [0000] - - 0 000 00', '') + @example('0150 000000000000000 ???????-? 000000000000000 {0} - [0000] - - 0 000 00', '') + @example('0101 000000000000000 ?000000-0 000000000000000 {0} (000-0) [0000] - - 0 000 00', '') + @example('0101 000000000000000 ???????-? 0000000000000 0 - - 0 000 00', '') + @example('0101 000000000000000 ???????-? 000000000000000 {0} (000-0) - - - 0 000 0000D', '') + @example('0101 000000000000000 ???????-? 000000000000000 - - 0 000 0000BDD', '') + @example('0101 000000000000000 ???????-? 000000000000000 - - 0 000 0000D', '') + @example('0101 000000000000000 ???????-? 000000000000000 - - 0 00A 0000D', '') + @example('0101 000000000000000 ???????-? 000000000000000 - - 0 0A0 0000D', '') + @example('0101 000000000000000 ???????-? 000000000000000 - - 0 000 0000D', '') + @example('0101 000000000000000 ???????-? 000 0000000BCDEFG - - 0 000 00', '') + @example('0101 000000000000000 ???????-? (000000000000)00 - 0 000 00', '') + @example('0101 000000000000000 ???????-? 000000000000000 - - 0 000 10 +', '') + @example('0101 000000000000000 ???????-? 000000000000000 - - 0 000 00 0', '') + @example('0101 000000000000000 ???????-? 000000000000000 - 001 000', '0101 000000000000000 ???????-? - - - 001 0 000 ') + @example('0101 000000000000000 ???????-? 000000000000000 - 000 A00', '0101 000000000000000 ???????-? - - - 000 0 A00 ') + @example('0101 000000000000000 ???????-? 000000000000000 - 000 00', '0101 000000000000000 ???????-? - - - 000 0 00 ') + @example('0101 000000000000000 ???????-? 000000000000000 - 000 0 ?00 00', '') + @example('0101 000000000000000 0000000-0 000000000000000 0 0 0 000 000 000+', '') + @example('0101 000000000000000 ???????-? {0}000000000000 - - 0 000 00', '') + @example('0101 000000000000000 ???????-? 000000000000000 {0} (000-0) [0000] - a 000 00', '0101 000000000000000 ???????-? - - A 000 0 00 ') + @example('0101 000000000000000 ???????-? 000000000000000 a - 000 00', '') + @example('0101 000000000000000 ???????-? 00000000000+ 0 - a 000 00', '0101 000000000000000 ???????-? - - A 000 0 00 ') + @example('0101 000000000000000 ???????-? 000000000000000 c - 000 00', '0101 000000000000000 ???????-? c - - 000 0 00 ') + @example('0101 000000000000000 ???????-? 00000000+ 0000 - 000 00', '0101 000000000000000 ???????-? - - - 000 0 00 ') + @example('0101 000000000000000 ???????-? 000000000000000 { -0} - - c - 000 00', '0101 000000000000000 ???????-? c - - 000 0 00 ') + @example('0101 000000000000000 A0000y0-0 000000000000000 - - 0 000 0000D', '') + @example('0110 000000000000000 ???????-? 000000000000000 H B A 000 0 00', '0110 000000000000000 ???????-? H B A 000 0 00 ') + @example('0110 000000000000000 ???????-? 000000000000000 e - A 000 00', '0110 000000000000000 ???????-? e - A 000 0 00 ') + @example('0101 000000000000000 0000000-0 0000000000000 B - A A 000 00', '') + @example('0101 000000000000000 0000000-0 [00000000000000 - - [0000] - - A 000 00', '') + @example('0110 000000000000000 ???????-? 0000000000 (000 - (000-0) [0000] - - A 000 0 00', '0110 000000000000000 ???????-? - - A 000 0 00 ') + @example('0101 000000000000000 0000000-0 000000000000000 BB A A 000 0 00', '') + @example('0101 000000000000000 ???????-? 0000000000000 0 0 B - A 000 00', '0101 000000000000000 ???????-? B - A 000 0 00 ') + @example('0101 000000000000000 ???????-? 000000000000000 {-0} (000-0) - * A 000 00', '0101 000000000000000 ???????-? - - A 000 0 00 ') + @example('0101 000000000000000 ???????-? 000000000000000 {-0} (000-0) - - - A 000 00', '0101 000000000000000 ???????-? - - A 000 0 00 ') + @example("0101 000000000000000 ?000000-0 {3 } (7TG-1) [2IBt] EHEG - 569 9 C5'", '0101 000000000000000 ?000000-0 EGH - - 569 9 C5 ') + @example('0101 000000000000000 ???????-? 0000000000000 B - - A 000 00', '0101 000000000000000 ???????-? - - A 000 0 00 ') + @example('0101 111111111111000 A000011-1 000000000000100 {0} (100-0) - - - B 001 10', '0101 111111111111000 A000011-1 { -1 } (100-0) - - - B 001 0 10 ') + @example('1804 ORx}KK-E66IM+\'RwvRrB1 ???????-? bI9cqWeGEH9jJlGJi7 { -2} - - FEee A 48X 11{2l', '1804 ORx}KK-E66IM+\'RwvRrB1 ???????-? eEF A - 480 0 11 ') + @example('1804 0ORx}KK-E6wvRrB1 ???????-? bI9cqWeGEH9jJlGJ { -2} - - FEee A 48X 11{2l', '1804 0ORx}KK-E6wvRrB1 ???????-? eEF A - 480 0 11 ') + @example('0603 Xfdr5TXRv*E?Nwk ecUr4ug-c 26yTW ?tP0 AVh5X+ AAA 7XX 11', '0603 Xfdr5TXRv*E?Nwk ECUR4UG-C { -1 } - - - AAA - 700 0 11 ') + @example('0408 10B1616111MOBeZ A000001-1 G(mdVjYHP)V*jEz BCFG - 011 2X0', '0408 10B1616111MOBeZ A000001-1 { -1 } - - BCFG - - 011 0 2X0 ') + @example('0101 000000000000000 A000000-0 000000000000000 {0} (000+0) - DFBe - A 000 14 ) T5neYuvB1', '0101 000000000000000 A000000-0 { -1 } (000+0) - BDeF - A 000 0 14 B1 V ') + @example('0101 000011111111000 A000011-1 000000000000101 {0} - - B - A 000 00 m0', '0101 000011111111000 A000011-1 { -1 } - - B - A 000 0 00 ') + @example('0101 000000000000000 A000000-0 (00000000000000 - (000-0) [0010] BBB - A 000 00u?2{KjY', '0101 000000000000000 A000000-0 { -1 } (000-0) [0010] B - A 000 0 00u? ') + @example('0101 000000000000000 f72110b-1 00 317TbjkYG3u}(f) G - A 000 01', '0101 000000000000000 F72110B-1 { -2 } - - G - A 000 0 01 ') + @example('2040 JH*U1CnPh(Gtg00 ???????-? 11222[aQg)V]111 - - A 000 00 2}iK', '2040 JH*U1CnPh(Gtg00 ???????-? - - A 000 0 00 ') + @example('0140 000000000000000 ???????-? 0000000000000 0 - - A 000 100 00', '0140 000000000000000 ???????-? - - A 000 100 00 ') + @example('0940 ouV)anTg*V0QDeNL ???????-? ]naJy2GDuB{hq8qG - - [ouJB] - XFX X01 11', '0940 ouV)anTg*V0QDeNL ???????-? - XFX - 001 0 11 ') + @example('0101 000000000000000 ???????-? B 0000000000000 - - A 000 --0', '0101 000000000000000 ???????-? - - A 000 0 -- ') + @example('0205 b9N00077 ???????-? B - * A ?E3 --B1n', '0205 b9N00077 ???????-? - - A 0E3 0 -- ') + @example('0101 000000000000000 ???????-? B 0000000000000 - - A 000 --00', '0101 000000000000000 ???????-? - - A 000 0 -- ') + @example('0140 116EFJ0( cdvw{ A000000-0 } 0000000000000 - - A 000 00', '0140 116EFJ0( cdvw{ A000000-0 { -1 } - - - - A 000 0 00 ') + @example('0101 000000000000000 ???????-? 0000000 0000000 C - A 000 00', '0101 000000000000000 ???????-? - - A 000 0 00 ') + @example('0101 000000000000000 ???????-? 000000 00000000 C - A 000 00', '0101 000000000000000 ???????-? - - A 000 0 00 ') + @example('0140 111111111111111 A000000-1 1 0000000000000 C - A 000 00', '0140 111111111111111 A000000-1 { -1 } - - - - A 000 0 00 ') + @example('0140 000000000000000 A000000-0 F 0000000000000 C - F 000 00', '0140 000000000000000 A000000-0 { -1 } - - - - F 000 0 00 ') + @example('0940 ouV)anT-eB00111 A111110-X RH?xJy Hcb-O-a} ov4111111 EBCCH - B 2FA 070R', '0940 ouV)anT-eB00111 A111110-X { 2 } - - BCEH - B 2FA 0 070R ') + @example('0940 ouV)anT-eB00111 ?11111A-X ?HHJOR-- abcxy} 1 BCCE - B 001 00R', '0940 ouV)anT-eB00111 ?11111A-X BCE - B 001 0 00R ') + @example('0140 000000000000000 A000000-0 00 0000000 + 0 00 - A 000 00', '0140 000000000000000 A000000-0 { -1 } - - - - A 000 0 00 ') + @example('0140 000000000000000 ???????-? 0000000000000 0 De * A ?00 00', '0140 000000000000000 ???????-? De - A - 000 0 00 ') + @example('0140 000000000000000 ???????-? [00r0MOW0 mw}]C BB - A 000 00', '0140 000000000000000 ???????-? [00r0MOW0 mw}] - - A 000 0 00 ') + @example('0140 000000000000000 ???????-? 0000000000000 C BB B A 000 00', '0140 000000000000000 ???????-? - B A 000 0 00 ') + @example('0101 000000000000000 ???????-? 000000000000000 De - A ?00 00', '0101 000000000000000 ???????-? De - - A 000 0 00 ') + @example('0140 ]00111111111111 ???????-? 111111111111111 - - [0100] - 010 010', '0140 ]00111111111111 ???????-? - - - 010 0 010 ') + @example('0101 000000000000000 ???????-? [000000000000]( - - A 000 00)', '0101 000000000000000 ???????-? [000000000000] - - A 000 0 00 ') + @example('0101 000000000000000 ???????-? [000000000000]X - - A 000 00)', '0101 000000000000000 ???????-? [000000000000]X - - A 000 0 00 ') + @example('0101 000000000000000 ???????-? [0000000000)(]( - - A 000 00)', '0101 000000000000000 ???????-? [0000000000)(] - - A 000 0 00 ') + @example('0101 000000000000000 ???????-? [000000000000000000000000000000000000]? - - A 000 00', '0101 000000000000000 ???????-? [00000000000000000000000000000000000]? - - A 000 0 00 ') + @example('0101 02111111111111) ???????-? [oPrh00011111GitpHqwhA{KRNf{rpjqI}7bj]A - - B 000 100', '0101 02111111111111) ???????-? [oPrh00011111GitpHqwhA{KRNf{rpjqI}7b] - - B 000 0 100 ') + @example('0101 000000000000000 ???????-? [0000000)(]X [ - - B 001 100', '0101 000000000000000 ???????-? [0000000)(]X - - B 001 0 100 ') + @example('2931 Dinenruum E432679-6 Na Ni Po Da { -3 } (851-2) [7367] B - A 122 10 ImDc K1 IV M3 V M4 V', '2931 Dinenruum E432679-6 Da Na Ni Po { -3 } (851-2) [7367] B - A 122 10 ImDc K1 IV M3 V M4 V ') + def test_parse_line_to_star(self, s, t): hyp_line = "Hypothesis input: " + s sector = Sector('# Core', '# 0, 0') pop_code = 'scaled' @@ -191,6 +192,9 @@ def test_parse_line_to_star(self, s): new_skool = nu_foo.oldskool self.assertEqual(old_skool, new_skool, "Oldskool status should be invariant across reparsing. " + hyp_line) + if t is not None: + self.assertEqual(t, nu_line, "Reparsed line not equal to expected line.\n " + hyp_line + " \n Reparsed: '" + nu_line + "'\n Expected: '" + t + "'\n") + @given(importance_starline()) @settings(suppress_health_check=[HealthCheck(3), HealthCheck(2)], deadline=timedelta(1000)) # suppress slow-data health check, too-much filtering diff --git a/Tests/Inputs/testStarlineParser.py b/Tests/Inputs/testStarlineParser.py index 9381979d7..1134f0dca 100644 --- a/Tests/Inputs/testStarlineParser.py +++ b/Tests/Inputs/testStarlineParser.py @@ -454,7 +454,7 @@ def test_parser_screwball_synthetic_starline_17(self): self.assertEqual(None, transformed[7]) self.assertEqual('-', transformed[11], 'Unexpected nobles code') self.assertEqual('-', transformed[12], 'Unexpected base code') - self.assertEqual('', transformed[13], 'Unexpected trade zone') + self.assertEqual('-', transformed[13], 'Unexpected trade zone') self.assertEqual('000', transformed[14], 'Unexpected PBG code') self.assertEqual('0', transformed[15], 'Unexpected worlds count') self.assertEqual('A00', transformed[16], 'Unexpected allegiance') @@ -479,7 +479,7 @@ def test_parser_screwball_synthetic_starline_18(self): self.assertEqual(None, transformed[7]) self.assertEqual('-', transformed[11], 'Unexpected nobles code') self.assertEqual('-', transformed[12], 'Unexpected base code') - self.assertEqual('', transformed[13], 'Unexpected trade zone') + self.assertEqual('-', transformed[13], 'Unexpected trade zone') self.assertEqual('001', transformed[14], 'Unexpected PBG code') self.assertEqual('0', transformed[15], 'Unexpected worlds count') self.assertEqual('000', transformed[16], 'Unexpected allegiance') @@ -606,7 +606,7 @@ def test_parser_screwball_synthetic_starline_23(self): self.assertEqual(None, transformed[7]) self.assertEqual('-', transformed[11], 'Unexpected nobles code') self.assertEqual('-', transformed[12], 'Unexpected base code') - self.assertEqual('', transformed[13], 'Unexpected trade zone') + self.assertEqual('-', transformed[13], 'Unexpected trade zone') self.assertEqual('000', transformed[14], 'Unexpected PBG code') self.assertEqual('0', transformed[15], 'Unexpected worlds count') self.assertEqual('00', transformed[16], 'Unexpected allegiance')