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(_)
#! /usr/bin/env python

from __future__ import print_function

from T5_worldgen.mapping_region import Sector
import os

sector_name = 'Test_Sector_Sparse'

sector = Sector(sector_name, 'Sparse')
# sector.display()
for _ in sector.t5_tab():
    print(_)

# Save JSON data in ./tmp/sector_name/subsector_name.json
try:
    os.makedirs('/tmp/{}/'.format(sector_name))
except OSError:
    if not os.path.isdir('/tmp/{}/'.format(sector_name)):
        raise
for ss_id in sector.subsectors.keys():
    with open(
            '/tmp/{}/Subsector-{}.json'.format(sector_name, ss_id),
            'w') as jout:
        for hex_id in sector.subsectors[ss_id].hexes.keys():
            jout.write(
                sector.subsectors[ss_id].hexes[hex_id].as_json() + "\n"
            )