ogn-python/tests/test_ognutils.py

52 wiersze
1.6 KiB
Python
Czysty Zwykły widok Historia

2015-11-06 21:34:19 +00:00
import unittest
from ogn.utils import get_ddb, get_country_code, wgs84_to_sphere
2015-11-11 07:03:42 +00:00
from ogn.model.address_origin import AddressOrigin
2015-11-06 21:34:19 +00:00
class TestStringMethods(unittest.TestCase):
2015-11-11 07:03:42 +00:00
def test_get_devices(self):
devices = get_ddb()
2015-11-06 21:34:19 +00:00
self.assertGreater(len(devices), 1000)
2015-11-11 07:03:42 +00:00
def test_get_ddb_from_file(self):
devices = get_ddb('tests/custom_ddb.txt')
self.assertEqual(len(devices), 3)
device = devices[0]
self.assertEqual(device.address, 'DD4711')
self.assertEqual(device.aircraft, 'HK36 TTC')
self.assertEqual(device.registration, 'D-EULE')
self.assertEqual(device.competition, '')
self.assertTrue(device.tracked)
self.assertTrue(device.identified)
self.assertEqual(device.address_origin, AddressOrigin.userdefined)
2015-11-06 21:34:19 +00:00
def test_get_country_code(self):
latitude = 48.0
longitude = 11.0
country_code = get_country_code(latitude, longitude)
self.assertEquals(country_code, 'de')
2015-11-12 07:38:43 +00:00
def test_get_country_code_bad(self):
latitude = 0.0002274
longitude = -0.0009119
country_code = get_country_code(latitude, longitude)
self.assertEqual(country_code, None)
2015-11-15 00:16:19 +00:00
def test_wgs84_to_sphere(self):
2015-11-15 07:53:39 +00:00
# receiver
lat1 = 48.865
lon1 = 9.2225
alt1 = 574
# aircraft beacon
lat2 = 48.74435
lon2 = 9.578
alt2 = 929
2015-11-15 00:16:19 +00:00
[radius, theta, phi] = wgs84_to_sphere(lat1, lat2, lon1, lon2, alt1, alt2)
self.assertAlmostEqual(radius, 29265.6035812215, 5)
self.assertAlmostEqual(theta, 0.694979846308314, 5)
2015-11-15 07:53:39 +00:00
self.assertAlmostEqual(phi, 117.1275408121, 5)