def test_create_size_rewrite(self):
        '''
        Test create objects that can't exist - size changes
        - K5-M9 IV
        - B0-F4 VI
        '''
        # IVs
        for decimal in range(5, 10):
            code = 'K{} IV'.format(decimal)
            star = Star(code)
            self.assertTrue(star.size == 'V')
        for decimal in range(0, 10):
            code = 'M{} IV'.format(decimal)
            star = Star(code)
            self.assertTrue(star.size == 'V')

        # VIs
        for decimal in range(0, 10):
            code = 'B{} VI'.format(decimal)
            star = Star(code)
            self.assertTrue(star.size == 'V')
        for decimal in range(0, 5):
            code = 'F{} VI'.format(decimal)
            star = Star(code)
            self.assertTrue(star.size == 'V')
    def test_json(self):
        '''Test JSON representation'''
        # Test with star specfied
        expected = json.dumps(
            {
                "angular_diameter": 0.522,
                "au": 1,
                "mkm": 149.6,
                "notes": [],
                "orbit_no": 3,
                "period": 1.0,
                "star": "G2 V"
            },
            sort_keys=True)
        orbit = Orbit(3, Star('G2 V'))
        LOGGER.debug('orbit.json() = %s', orbit.json())
        self.assertTrue(orbit.json() == expected)

        # Test, no star
        expected = json.dumps(
            {
                "angular_diameter": None,
                "au": 1,
                "mkm": 149.6,
                "notes": [],
                "orbit_no": 3,
                "period": None,
                "star": None
            },
            sort_keys=True)
        orbit = Orbit(3)
        LOGGER.debug('orbit.json() = %s', orbit.json())
        self.assertTrue(orbit.json() == expected)
 def test_temperature(self):
     '''Temperature tests'''
     star = Star('G2 V')
     for test in [{
             'uwp': 'A867A69-F',
             'orbit': 3,
             'expected': MinMax(221.0, 303.0)
     }, {
             'uwp': 'F20067C-F',
             'orbit': 3,
             'expected': MinMax(299.0, 299.0)
     }, {
             'uwp': 'F43056A-F',
             'orbit': 4,
             'expected': MinMax(237.0, 237.0)
     }, {
             'uwp': 'G8B0168-F',
             'orbit': 2,
             'expected': MinMax(300.0, 707.0)
     }, {
             'uwp': 'F10046C-F',
             'orbit': 9,
             'expected': MinMax(48.0, 48.0)
     }]:
         planet = LBB6Planet(uwp=test['uwp'])
         planet.generate(star=star, orbit=Orbit(test['orbit']))
         LOGGER.debug('planet = %s', planet.json())
         LOGGER.debug('uwp = %s expected = %s, actual = %s', test['uwp'],
                      test['expected'], planet.temperature)
         self.assertAlmostEqual(planet.temperature.min(),
                                test['expected'].min(),
                                delta=2)
         self.assertAlmostEqual(planet.temperature.max(),
                                test['expected'].max(),
                                delta=2)
 def test_create_valid(self):
     '''Test object create (valid star types)'''
     tests = {'G2 V': 'G2 V', 'K5VI': 'K5 VI', 'MD': 'M D'}
     for clas in tests:
         star = Star(clas)
         LOGGER.debug('classification = %s', star.classification)
         self.assertTrue(star.classification == tests[clas])
 def test_albedo_ice_no_hz(self):
     '''Ensure star.hz_orbit being None doesn't raise exception'''
     star = Star('MD')
     orbit = Orbit(3)
     planet = LBB6Planet(uwp='X644000-0')
     planet.generate(star=star, orbit=orbit)
     self.assertTrue(planet._determine_albedo_ice_coverage() == float(
         int(planet.hydrographics) / 10.0))
 def test_non_hz_orbits(self):
     '''Test non-HZ orbits (hydrographics)'''
     star = Star('G2 V')
     planet = LBB6Planet()
     planet.generate(star=star, orbit=Orbit(1))
     self.assertTrue(int(planet.hydrographics) == 0)
     planet = LBB6Planet()
     planet.generate(star=star, orbit=Orbit(11))
     self.assertTrue(str(planet.atmosphere) in '0A')
Esempio n. 7
0
    def on_get(self, req, resp):
        '''GET <apiserver>/ct/lbb6/star?code=<star>'''
        self.query_parameters = {'doc': False, 'code': None}
        self.parse_query_string(req.query_string)

        if self.query_parameters['doc'] is True:
            resp.body = self.get_doc_json(req)
            resp.status = falcon.HTTP_200
        else:
            try:
                self.query_parameters['code'] = \
                    catch_html_space(self.query_parameters['code'])
                star = StarData(self.query_parameters['code'])
            except ValueError as err:
                raise falcon.HTTPError(title='Invalid star',
                                       status='400 Invalid parameter',
                                       description=str(err))
            resp.body = star.json()
            resp.status = falcon.HTTP_200
 def test_unavailable_orbits(self):
     '''Test for interior orbit, mnimum orbit'''
     # Interior orbit
     orbit = Orbit(2, Star('M9 Ia'))
     LOGGER.debug('notes = %s', orbit.notes)
     self.assertTrue(
         'Orbit 2 is within M9 Ia star; minimum orbit is 8' in \
         orbit.notes
     )
     # Minimum orbit
     orbit = Orbit(2, Star('B5 V'))
     LOGGER.debug('notes = %s', orbit.notes)
     self.assertTrue(
         'Orbit 2 is unavailable to B5 V star; minimum orbit is 3' in \
         orbit.notes
     )
     # Edge case: orbit == minimum_orbit
     orbit = Orbit(0, Star('G2 V'))
     LOGGER.debug('notes = %s', orbit.notes)
     self.assertTrue(orbit.notes == [])
 def test_albedo_ice_coverage(self):
     '''
     Test albedo_ice_coverage
     Inner zone => ice_coverage = 0%
     HZ => ice_coverage == 10%
     Outer zone => ice_coverage = hydrographics
     Can't find orbit or star => ice_coverage = 10%
     '''
     planet = LBB6Planet(uwp='X644000-0')
     # Inner zone
     planet.generate(star=Star('G2 V'), orbit=Orbit(1))
     self.assertTrue(planet._determine_albedo_ice_coverage() == 0.0)
     # Habitable zone
     planet.generate(star=Star('G2 V'), orbit=Orbit(3))
     self.assertTrue(planet._determine_albedo_ice_coverage() == 0.1)
     # Outer zone
     planet.generate(star=Star('G2 V'), orbit=Orbit(5))
     for hyd in range(0, 11):
         planet.hydrographics = ehex(hyd)
         self.assertTrue(
             planet._determine_albedo_ice_coverage() == float(hyd / 10.0))
 def test_json(self):
     '''Test JSON representation'''
     expected = json.dumps(
         {
             "type": "G",
             "decimal": 2,
             "size": "V",
             "min_orbit": 0,
             "hz_orbit": 3,
             "hz_period": 1.0,
             "magnitude": 4.82,
             "luminosity": 0.994,
             "temperature": 5800,
             "radius": 0.98,
             "mass": 1.0,
             "int_orbit": None,
             "classification": "G2 V"
         },
         sort_keys=True)
     code = 'G2 V'
     star = Star(code)
     LOGGER.debug('json = %s', star.json())
     self.assertTrue(expected == star.json())
    def test_creates(self):
        '''Test making orbit, valid and invalid values'''
        for orbit_no in [0, 19]:
            orbit = Orbit(orbit_no)
            self.assertTrue(orbit_no == orbit.orbit_no)
            self.assertTrue(orbit.period is None)
        orbit = Orbit(3, Star('G2 V'))
        self.assertTrue(orbit.orbit_no == 3)
        self.assertTrue(str(orbit.star) == 'G2 V')
        self.assertTrue(orbit.period == 1.0)

        # Bogus creates
        for orbit_no in ['foo', -1, 25]:
            with self.assertRaises(ValueError):
                _ = Orbit(orbit_no)
 def test_albedo(self):
     '''Albedo tests'''
     star = Star('G2 V')
     tests = [{
         'uwp': 'A867977-8',
         'star': star,
         'orbit': Orbit(3),
         'expected': (0.265, 0.465)
     }]
     for test in tests:
         planet = LBB6Planet(uwp=test['uwp'])
         planet.generate(star=test['star'], orbit=test['orbit'])
         LOGGER.debug('uwp = %s TCs = %s albedo = %s', str(planet),
                      planet.trade_codes, str(planet.albedo))
         self.assertTrue(planet.albedo.min() == test['expected'][0])
         self.assertTrue(planet.albedo.max() == test['expected'][1])
 def test_str(self):
     '''Test str() representation'''
     for code in ['G2 V', 'M D']:
         star = Star(code)
         self.assertTrue(str(star) == code)
 def test_create_bogus(self):
     '''Test object create (bogus star types)'''
     with self.assertRaises(ValueError):
         _ = Star('foo')
 def test_period_calc(self):
     '''Test period calculation'''
     orbit = Orbit(3, Star('G2 V'))
     self.assertTrue(orbit.period == 1.0)
     orbit = Orbit(2)
     self.assertTrue(orbit.period is None)
 def test_angdia(self, mock_fn):
     '''Test angdia response if API server is down'''
     orbit = Orbit(3, Star('G2 V'))
     self.assertTrue(
         'Unable to connect to API endpoint http://api.trav.phraction.org'
         in orbit.notes)
    def test_json(self, mock_fn):
        '''Test JSON representation'''
        # No orbit or star
        expected = json.dumps(
            {
                "is_mainworld": True,
                "name": "",
                "orbit": None,
                "orbital_period": None,
                "star": None,
                "temperature": {
                    "max": None,
                    "min": None
                },
                "temperature_factors": {
                    "albedo": {
                        "max": 0.266,
                        "min": 0.226
                    },
                    "cloudiness": 0.1,
                    'greenhouse': {
                        "max": 1.0,
                        "min": 1.0
                    }
                },
                "trade_codes": ["Ni", "Po"],
                "uwp": "B433432-A"
            },
            sort_keys=True)
        planet = LBB6Planet(uwp='B433432-A')
        planet.generate()
        LOGGER.debug('expected      = %s', expected)
        LOGGER.debug('planet.json() = %s', planet.json())
        self.assertTrue(planet.json() == expected)

        # Orbit, star
        expected = json.dumps(
            {
                "is_mainworld": True,
                "name": "Planet 9",
                "orbit": "Orbit 3: 1.0 AU, 149.6 Mkm",
                "orbital_period": None,
                "star": "G2 V",
                "temperature": {
                    "max": 289.0,
                    "min": 274.0
                },
                "temperature_factors": {
                    "albedo": {
                        "max": 0.266,
                        "min": 0.226
                    },
                    "cloudiness": 0.1,
                    'greenhouse': {
                        "max": 1.0,
                        "min": 1.0
                    }
                },
                "trade_codes": ["Ni", "Po"],
                "uwp": "B433432-A"
            },
            sort_keys=True)
        planet = LBB6Planet('Planet 9', uwp='B433432-A')
        planet.generate(star=Star('G2 V'), orbit=Orbit(3))
        LOGGER.debug('expected      = %s', expected)
        LOGGER.debug('planet.json() = %s', planet.json())
        self.assertTrue(planet.json() == expected)