def test_differentTypesInequality(self): """ Coordinates with the same values but different types aren't equal. """ c1 = base.Coordinate(1.0, Angles.LATITUDE) c2 = base.Coordinate(1.0, Angles.LONGITUDE) self.assertNotEqual(c1, c2)
def test_differentAnglesInequality(self): """ Coordinates with different values aren't equal. """ c1 = base.Coordinate(1.0) c2 = base.Coordinate(-1.0) self.assertNotEqual(c1, c2)
def test_inDegreesMinutesSeconds(self): """ Coordinate values can be accessed in degrees, minutes, seconds. """ c = base.Coordinate(50.5, Angles.LATITUDE) self.assertEqual(c.inDegreesMinutesSeconds, (50, 30, 0)) c = base.Coordinate(50.213, Angles.LATITUDE) self.assertEqual(c.inDegreesMinutesSeconds, (50, 12, 46))
def test_badHemisphere(self): """ Accessing the hemisphere for a coordinate that can't compute it raises C{ValueError}. """ coordinate = base.Coordinate(1.0, None) self.assertRaises(ValueError, lambda: coordinate.hemisphere)
def test_negativeLongitude(self): """ Negative longitudes have a repr that specifies their type and value. """ longitude = base.Coordinate(-50.0, Angles.LONGITUDE) expectedRepr = "<Longitude ({0} degrees)>".format(-50.0) self.assertEqual(repr(longitude), expectedRepr)
def test_positiveLatitude(self): """ Positive latitudes have a repr that specifies their type and value. """ coordinate = base.Coordinate(10.0, Angles.LATITUDE) expectedRepr = "<Latitude ({0} degrees)>".format(10.0) self.assertEqual(repr(coordinate), expectedRepr)
def test_unknownAngleInDegreesMinutesSeconds(self): """ If the vaue of a coordinate is C{None}, its values in degrees, minutes, seconds is also C{None}. """ c = base.Coordinate(None, None) self.assertEqual(c.inDegreesMinutesSeconds, None)
def test_positiveLongitude(self): """ Positive longitudes have a repr that specifies their type and value. """ longitude = base.Coordinate(50.0, Angles.LONGITUDE) expectedRepr = f"<Longitude ({50.0} degrees)>" self.assertEqual(repr(longitude), expectedRepr)
def test_negativeLatitude(self): """ Negative latitudes have a repr that specifies their type and value. """ coordinate = base.Coordinate(-50.0, Angles.LATITUDE) expectedRepr = f"<Latitude ({-50.0} degrees)>" self.assertEqual(repr(coordinate), expectedRepr)
def test_repr(self): """ Coordinates that aren't explicitly latitudes or longitudes have an appropriate repr. """ coordinate = base.Coordinate(10.0) expectedRepr = "<Angle of unknown type ({0} degrees)>".format(10.0) self.assertEqual(repr(coordinate), expectedRepr)
def test_west(self): """ NMEA coordinate representations in the western hemisphere convert correctly. """ sentenceData = {"longitudeFloat": "1030.000", "longitudeHemisphere": "W"} state = {"longitude": base.Coordinate(-10.5, Angles.LONGITUDE)} self._fixerTest(sentenceData, state)
def test_north(self): """ NMEA coordinate representations in the northern hemisphere convert correctly. """ sentenceData = {"latitudeFloat": "1030.000", "latitudeHemisphere": "N"} state = {"latitude": base.Coordinate(10.5, Angles.LATITUDE)} self._fixerTest(sentenceData, state)
def test_sign(self): """ Setting the sign on a coordinate sets the sign of the value of the coordinate. """ c = base.Coordinate(50., Angles.LATITUDE) c.setSign(1) self.assertEqual(c.inDecimalDegrees, 50.) c.setSign(-1) self.assertEqual(c.inDecimalDegrees, -50.)
def test_badVariationSign(self): """ Setting a bogus sign value (not -1 or 1) on a coordinate raises C{ValueError} and doesn't affect the coordinate. """ value = 50.0 c = base.Coordinate(value, Angles.LATITUDE) self.assertRaises(ValueError, c.setSign, -50) self.assertEqual(c.inDecimalDegrees, 50.) self.assertRaises(ValueError, c.setSign, 0) self.assertEqual(c.inDecimalDegrees, 50.) self.assertRaises(ValueError, c.setSign, 50) self.assertEqual(c.inDecimalDegrees, 50.)
def _fixCoordinateFloat(self, coordinateType): """ Turns the NMEAProtocol coordinate format into Python float. @param coordinateType: The coordinate type. @type coordinateType: One of L{Angles.LATITUDE} or L{Angles.LONGITUDE}. """ if coordinateType is Angles.LATITUDE: coordinateName = "latitude" else: # coordinateType is Angles.LONGITUDE coordinateName = "longitude" nmeaCoordinate = getattr(self.currentSentence, coordinateName + "Float") left, right = nmeaCoordinate.split('.') degrees, minutes = int(left[:-2]), float("%s.%s" % (left[-2:], right)) angle = degrees + minutes/60 coordinate = base.Coordinate(angle, coordinateType) self._sentenceData[coordinateName] = coordinate
def test_northernHemisphere(self): """ Positive latitudes are in the northern hemisphere. """ coordinate = base.Coordinate(1.0, Angles.LATITUDE) self.assertEqual(coordinate.hemisphere, Directions.NORTH)
def _makeLongitude(value): """ Builds and returns a longitude of given value. """ return base.Coordinate(value, Angles.LONGITUDE)
def _makeLatitude(value): """ Builds and returns a latitude of given value. """ return base.Coordinate(value, Angles.LATITUDE)
def test_float(self): """ Coordinates can be converted to floats. """ coordinate = base.Coordinate(10.0) self.assertEqual(float(coordinate), 10.0)
def makeCoordinate(): return base.Coordinate(1.0, Angles.LONGITUDE)
def test_westernHemisphere(self): """ Negative longitudes are in the western hemisphere. """ coordinate = base.Coordinate(-1.0, Angles.LONGITUDE) self.assertEqual(coordinate.hemisphere, Directions.WEST)
def test_southernHemisphere(self): """ Negative latitudes are in the southern hemisphere. """ coordinate = base.Coordinate(-1.0, Angles.LATITUDE) self.assertEqual(coordinate.hemisphere, Directions.SOUTH)
def test_easternHemisphere(self): """ Positive longitudes are in the eastern hemisphere. """ coordinate = base.Coordinate(1.0, Angles.LONGITUDE) self.assertEqual(coordinate.hemisphere, Directions.EAST)