2015-10-24 21:13:21 +00:00
|
|
|
import unittest
|
2015-11-20 10:36:42 +00:00
|
|
|
from datetime import datetime
|
2015-10-24 21:13:21 +00:00
|
|
|
|
2015-11-23 19:40:44 +00:00
|
|
|
from ogn.aprs_utils import dmsToDeg, createTimestamp, create_aprs_login
|
2015-12-10 16:28:29 +00:00
|
|
|
from ogn.exceptions import AmbigousTimeError
|
2015-10-24 21:13:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestStringMethods(unittest.TestCase):
|
2015-10-27 19:17:11 +00:00
|
|
|
def test_dmsToDeg(self):
|
|
|
|
dms = 50.4830
|
|
|
|
self.assertAlmostEqual(dmsToDeg(dms), 50.805, 5)
|
|
|
|
|
2015-10-24 21:13:21 +00:00
|
|
|
def test_createTimestamp_seconds_behind(self):
|
2015-12-10 06:43:18 +00:00
|
|
|
timestamp = createTimestamp('235959', reference=datetime(2015, 10, 16, 0, 0, 1))
|
|
|
|
self.assertEqual(timestamp, datetime(2015, 10, 15, 23, 59, 59))
|
2015-10-24 21:13:21 +00:00
|
|
|
|
|
|
|
def test_createTimestamp_seconds_before(self):
|
2015-12-10 06:43:18 +00:00
|
|
|
timestamp = createTimestamp('000001', reference=datetime(2015, 10, 15, 23, 59, 59))
|
|
|
|
self.assertEqual(timestamp, datetime(2015, 10, 16, 0, 0, 1))
|
2015-10-24 21:13:21 +00:00
|
|
|
|
|
|
|
def test_createTimestamp_big_difference(self):
|
2015-12-10 16:28:29 +00:00
|
|
|
with self.assertRaises(AmbigousTimeError):
|
|
|
|
createTimestamp('123456', reference=datetime(2015, 10, 15, 23, 59, 59))
|
2015-10-24 21:13:21 +00:00
|
|
|
|
2015-11-23 19:40:44 +00:00
|
|
|
def test_create_aprs_login(self):
|
|
|
|
basic_login = create_aprs_login('klaus', -1, 'myApp', '0.1')
|
|
|
|
self.assertEqual('user klaus pass -1 vers myApp 0.1\n', basic_login)
|
|
|
|
|
|
|
|
login_with_filter = create_aprs_login('klaus', -1, 'myApp', '0.1', 'r/48.0/11.0/100')
|
|
|
|
self.assertEqual('user klaus pass -1 vers myApp 0.1 filter r/48.0/11.0/100\n', login_with_filter)
|
|
|
|
|
|
|
|
|
2015-10-24 21:13:21 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|