コード例 #1
0
 def test_json_importer(self):
     '''Test system.json_import() importer'''
     jdata = '{"mainworld": "{\\"trade_codes\\": [\\"Ni\\"], \\"travel_code\\": \\"\\", \\"is_mainworld\\": true, \\"mainworld_type\\":  \\"Planet\\", \\"parent_type\\": null, \\"orbit_around_parent\\": null, \\"uwp\\": \\"E510423-8\\", \\"orbit\\": 7, \\"bases\\": \\"\\"}", "worlds": 5, "allegiance": "Na", "stellar": "{\\"decimal\\": 2, \\"companion\\": \\"{\\\\\\"habitable_zone\\\\\\": 7, \\\\\\"spectral_type\\\\\\": \\\\\\"A\\\\\\", \\\\\\"companion\\\\\\": null, \\\\\\"decimal\\\\\\": 7, \\\\\\"size\\\\\\": \\\\\\"V\\\\\\"}\\", \\"habitable_zone\\": 7, \\"spectral_type\\": \\"A\\", \\"secondaries\\": {}, \\"size\\": \\"V\\"}", "Ix": "{-3}", "name": "", "zone": "", "Cx": "[511C]", "hex": "0000", "pbg": "001", "bases": "", "Ex": "(A31+2)", "nobility": "B"}'
     s_data = json.loads(jdata)
     system = System()
     system.json_import(jdata)
     self.assertTrue(s_data['name'] == system.name)
     self.assertTrue(s_data['hex'] == system.hex)
     self.assertTrue(s_data['bases'] == system.bases)
     self.assertTrue(s_data['allegiance'] == system.allegiance)
     self.assertTrue(s_data['worlds'] == system.num_worlds)
     self.assertTrue(s_data['Ix'] == str(system.importance_x))
     self.assertTrue(s_data['Ex'] == str(system.economic_x))
     self.assertTrue(s_data['Cx'] == str(system.cultural_x))
     self.assertTrue(s_data['pbg'] == str(system.pbg))
コード例 #2
0
    def test_owning_system_sector(self):
        '''Test owning system (sector)'''
        # Sector data - 0105 is the owned world, 0308 should be the owning world
        sector = Sector('Test sector')
        sector.hexes = {}
        s_data = [
            '{"mainworld": "{\\"trade_codes\\": [\\"Ni\\", \\"O:0101\\"],' + \
                '\\"travel_code\\": \\"\\",' + \
                '\\"is_mainworld\\": true,' + \
                '\\"mainworld_type\\":  \\"Planet\\",' + \
                '\\"parent_type\\": null,' + \
                '\\"orbit_around_parent\\": null,' + \
                '\\"uwp\\": \\"E9D8665-7\\",' + \
                '\\"orbit\\": 3,' + \
                '\\"bases\\": \\"\\"}",' + \
                '"worlds": 4,' + \
                '"allegiance": "Na",' + \
                '"stellar": "{\\"decimal\\": 3,' + \
                '\\"companion\\": null,' + \
                '\\"habitable_zone\\": 3,' + \
                '\\"spectral_type\\": \\"G\\",' + \
                '\\"secondaries\\": {},' + \
                '\\"size\\": \\"V\\"}",' + \
                '"Ix": "{-3}",' + \
                '"name": "Name-0105A",' + \
                '"zone": "",' + \
                '"Cx": "[5349]",' + \
                '"hex": "0105",' + \
                '"pbg": "202",' + \
                '"bases": "",' + \
                '"Ex": "(753+1)",' + \
                '"nobility": "B"}',
            '{"mainworld": "{\\"trade_codes\\": [\\"De\\", \\"Hi\\",' + \
                '\\"In\\", \\"Po\\", \\"Tz\\"],' + \
                '\\"travel_code\\": \\"\\",' + \
                '\\"is_mainworld\\": true,' + \
                '\\"mainworld_type\\":  \\"Planet\\",' + \
                '\\"parent_type\\": null,' + \
                '\\"orbit_around_parent\\": null,' + \
                '\\"uwp\\": \\"B140987-A\\",' + \
                '\\"orbit\\": 0,' + \
                '\\"bases\\": \\"\\"}",' + \
                '"worlds": 5,' + \
                '"allegiance": "Na",' + \
                '"stellar": "{\\"decimal\\": 0,' + \
                '\\"companion\\": null,' + \
                '\\"habitable_zone\\": 0,' + \
                '\\"spectral_type\\": \\"M\\",' + \
                '\\"secondaries\\": {},' + \
                '\\"size\\": \\"III\\"}",' + \
                '"Ix": "{+4}",' + \
                '"name": "Name-0308A",' + \
                '"zone": "",' + \
                '"Cx": "[ED17]",' + \
                '"hex": "0308",' + \
                '"pbg": "103",' + \
                '"bases": "",' + \
                '"Ex": "(A8A+1)",' + \
                '"nobility": "BEf"}',
            '{"mainworld": "{\\"trade_codes\\": [\\"Hi\\", \\"In\\"],' + \
                '\\"travel_code\\": \\"\\",' + \
                '\\"is_mainworld\\": true,' + \
                '\\"mainworld_type\\": \\"Planet\\",' + \
                '\\"parent_type\\": null,' + \
                '\\"orbit_around_parent\\": null,' + \
                '\\"uwp\\": \\"A54598A-C\\",' + \
                '\\"orbit\\": 2,' + \
                '\\"bases\\": \\"\\"}",' + \
                '"worlds": 5,' + \
                '"allegiance": "Na",' + \
                '"stellar": "{\\"decimal\\": 0,' + \
                '\\"companion\\": null,' + \
                '\\"habitable_zone\\": 2,' + \
                '\\"spectral_type\\": \\"K\\",' + \
                '\\"secondaries\\": {},' + \
                '\\"size\\": \\"V\\"}",' + \
                '"Ix": "{+4}",' + \
                '"name": "Name-0805A",' + \
                '"zone": "",' + \
                '"Cx": "[5D4C]",' + \
                '"hex": "0805",' + \
                '"pbg": "403",' + \
                '"bases": "N",' + \
                '"Ex": "(98A+3)",' + \
                '"nobility": "BEf"}',
            '{"mainworld": "{\\"trade_codes\\": [\\"Ni\\", \\"Ag\\", \\"Pr\\"],' + \
                '\\"travel_code\\": \\"\\",' + \
                '\\"is_mainworld\\": true,' + \
                '\\"mainworld_type\\":  \\"Planet\\",' + \
                '\\"parent_type\\": null,' + \
                '\\"orbit_around_parent\\": null,' + \
                '\\"uwp\\": \\"B588510-8\\",' + \
                '\\"orbit\\": 3,' + \
                '\\"bases\\": \\"\\"}",' + \
                '"worlds": 9,' + \
                '"allegiance": "Na",' + \
                '"stellar": "{\\"decimal\\": 7,' + \
                '\\"companion\\": null,' + \
                '\\"habitable_zone\\": 3,' + \
                '\\"spectral_type\\": \\"G\\",' + \
                '\\"secondaries\\": {},' + \
                '\\"size\\": \\"V\\"}",' + \
                '"Ix": "{+0}",' + \
                '"name":' + \
                '"Name-0702A",' + \
                '"zone": "",' + \
                '"Cx": "[7567]",' + \
                '"hex": "0702",' + \
                '"pbg": "802",' + \
                '"bases": "",' + \
                '"Ex": "(B41-1)",' + \
                '"nobility": "BcC"}'
        ]
        for dta in s_data:
            system = System()
            system.json_import(dta)
            sector.hexes[system.hex] = system

        self.assertTrue(sector.find_owning_system('0105') == '0308')
        sector.trade_code_owning_system()
        self.assertTrue('O:0308' in sector.hexes['0105'].mainworld.trade_codes)

        for _ in sector.t5_tab():
            print(_)