def __init__(self, latitude, longitude, lat_ref='N', lon_ref='E'): #convert to an appropriate format if not isinstance(latitude, DegreeFormat): latitude = DegreeFormatFactory.create(latitude) self.latitude = latitude if not isinstance(longitude, DegreeFormat): longitude = DegreeFormatFactory.create(longitude) self.longitude = longitude self.lat_ref = lat_ref self.lon_ref = lon_ref
def test_open_location_coordinates(self): deg = DegreeFormatFactory.create((1, 1, 1)) data = [["gps_latitude", deg], ["gps_longitude", deg]] self.__train_sheet_for_data(data) self.mediator.open_url = MagicMock() self.mediator.show_location() self.mediator.open_url.assert_called_once()
def test_parse_location_restore_origin(self): cell = (1, 1) deg = DegreeFormatFactory.create("78.4") self.sheet.get_cell_data = Mock(side_effect=[deg, "gps_latitude", "a"]) self.mediator.begin_edit_cell(cell) self.mediator.end_edit_cell(cell) self.sheet.set_cell_data.assert_called_with(cell[0], cell[1], deg)
def to_format(key, value): """ Converts value to existing custom formats. """ if Converter.is_gps_timestamp(key): return TimeStamp.parse(value) if Converter.is_geoloc(key): return DegreeFormatFactory.create(value) #human readable value if we have an enum if isinstance(value, Enum): return value.name return value
def test_to_exif_dms(self): loc = DegreeFormatFactory.create([78.0, 55.0, 44.33324]) res = Converter.to_exif('', loc) self.assertIsInstance(res, tuple)
def test_has_location(self): deg = DegreeFormatFactory.create((1, 1, 1)) data = [["gps_latitude", deg], ["gps_longitude", deg]] self.__train_sheet_for_data(data) self.assertTrue(self.mediator.has_location())
def test_wrong_args(self): self.assertRaises(ValueError, lambda: DmsFormat([1])) self.assertRaises(ValueError, lambda: DecimalFormat(None)) self.assertRaises(ValueError, lambda: DegreeFormatFactory.create("a")) self.assertRaises(ValueError, lambda: TimeStamp.parse([1])) self.assertRaises(ValueError, lambda: TimeStamp.parse(1))
def test_parse_to_dec(self): loc = DegreeFormatFactory.create("30.263888889°") self.assertEqual((30, 15, 50), loc.as_tuple())
def test_parser_raises_error(self): self.assertRaises(ValueError, lambda: DegreeFormatFactory.parse('4711a'))
def test_dec_to_string(self): loc = DegreeFormatFactory.create(30.263888889) self.assertEqual("30.263889°", loc.__repr__())
def test_parse_to_dms(self): loc = DegreeFormatFactory.create("78°55\'44.33324\"") self.assertEqual(78.928981, loc.as_float())
def test_dec_to_dms(self): loc = DegreeFormatFactory.create(30.263888889) self.assertEqual((30, 15, 50), loc.as_tuple())
def test_dms_to_string(self): loc = DegreeFormatFactory.create([78.0, 55.0, 44.33324]) self.assertEqual("78°55\'44.33324\"", loc.__repr__())
def test_dms_to_dd_list(self): loc = DegreeFormatFactory.create([-78, 55, 44.33324]) self.assertEqual(-78.928981, loc.as_float())
def test_dms_to_dd_tuple(self): loc = DegreeFormatFactory.create((78, 55, 44.33324)) self.assertEqual(78.928981, loc.as_float())
def test_factory_format_arg(self): loc = DmsFormat((78, 55, 44.33324)) self.assertEqual(loc, DegreeFormatFactory.create(loc))