kopia lustrzana https://github.com/ctjacobs/pyqso
Added WorldMap unit tests.
rodzic
785d3b320f
commit
1fcdb4f6ee
|
@ -18,7 +18,10 @@
|
||||||
# along with PyQSO. If not, see <http://www.gnu.org/licenses/>.
|
# along with PyQSO. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
import os
|
try:
|
||||||
|
import unittest.mock as mock
|
||||||
|
except ImportError:
|
||||||
|
import mock
|
||||||
from pyqso.world_map import *
|
from pyqso.world_map import *
|
||||||
|
|
||||||
|
|
||||||
|
@ -38,13 +41,34 @@ class TestMaidenhead(unittest.TestCase):
|
||||||
assert self.maidenhead.ll2gs(latitude, longitude, subsquare=True) == "IO91gb"
|
assert self.maidenhead.ll2gs(latitude, longitude, subsquare=True) == "IO91gb"
|
||||||
|
|
||||||
def test_gs2ll(self):
|
def test_gs2ll(self):
|
||||||
|
""" Check that a Maidenhead grid square can correctly be converted to a latitude-longitude coordinate. """
|
||||||
gs4 = "JN05"
|
gs4 = "JN05"
|
||||||
assert self.maidenhead.gs2ll(gs4) == (45.5, 1.0)
|
assert self.maidenhead.gs2ll(gs4) == (45.5, 1.0)
|
||||||
gs6 = "JN05aa"
|
gs6 = "JN05aa"
|
||||||
assert self.maidenhead.gs2ll(gs6) == (45.020833333333336, 0.041666666666666664)
|
assert self.maidenhead.gs2ll(gs6) == (45.020833333333336, 0.041666666666666664)
|
||||||
gs6 = "IO91gb"
|
gs6 = "IO91gb"
|
||||||
print(self.maidenhead.gs2ll(gs6))
|
|
||||||
assert self.maidenhead.gs2ll(gs6) == (51.0625, -1.4583333333333335)
|
assert self.maidenhead.gs2ll(gs6) == (51.0625, -1.4583333333333335)
|
||||||
|
|
||||||
|
|
||||||
|
class TestWorldMap(unittest.TestCase):
|
||||||
|
|
||||||
|
""" The unit tests for the WorldMap class. """
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
""" Set up the WorldMap object needed for the unit tests. """
|
||||||
|
PyQSO = mock.MagicMock()
|
||||||
|
self.world_map = WorldMap(application=PyQSO())
|
||||||
|
|
||||||
|
def test_get_worked_grid_squares(self):
|
||||||
|
""" Check that the worked grid squares are determined correctly. """
|
||||||
|
Logbook = mock.MagicMock()
|
||||||
|
Log = mock.MagicMock()
|
||||||
|
logbook = Logbook()
|
||||||
|
l = Log()
|
||||||
|
l.records = [{"CALL": "TEST123", "COUNTRY": "England", "GRIDSQUARE": "IO91gb"}, {"CALL": "TEST456", "COUNTRY": "England", "GRIDSQUARE": "IO90hv"}, {"CALL": "TEST789", "COUNTRY": "England", "GRIDSQUARE": None}]
|
||||||
|
logbook.logs = [l]
|
||||||
|
worked_grid_squares = self.world_map.get_worked_grid_squares(logbook=logbook)
|
||||||
|
assert worked_grid_squares[14, 8] # IO square.
|
||||||
|
|
||||||
if(__name__ == '__main__'):
|
if(__name__ == '__main__'):
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
Ładowanie…
Reference in New Issue