Esempio n. 1
0
 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)
Esempio n. 2
0
 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)
Esempio n. 3
0
    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))
Esempio n. 4
0
 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)
Esempio n. 5
0
 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)
Esempio n. 6
0
 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)
Esempio n. 7
0
 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)
Esempio n. 8
0
 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)
Esempio n. 9
0
 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)
Esempio n. 10
0
 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)
Esempio n. 11
0
 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)
Esempio n. 12
0
 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)
Esempio n. 13
0
 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.)
Esempio n. 14
0
    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.)
Esempio n. 15
0
    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
Esempio n. 16
0
 def test_northernHemisphere(self):
     """
     Positive latitudes are in the northern hemisphere.
     """
     coordinate = base.Coordinate(1.0, Angles.LATITUDE)
     self.assertEqual(coordinate.hemisphere, Directions.NORTH)
Esempio n. 17
0
def _makeLongitude(value):
    """
    Builds and returns a longitude of given value.
    """
    return base.Coordinate(value, Angles.LONGITUDE)
Esempio n. 18
0
def _makeLatitude(value):
    """
    Builds and returns a latitude of given value.
    """
    return base.Coordinate(value, Angles.LATITUDE)
Esempio n. 19
0
 def test_float(self):
     """
     Coordinates can be converted to floats.
     """
     coordinate = base.Coordinate(10.0)
     self.assertEqual(float(coordinate), 10.0)
Esempio n. 20
0
 def makeCoordinate():
     return base.Coordinate(1.0, Angles.LONGITUDE)
Esempio n. 21
0
 def test_westernHemisphere(self):
     """
     Negative longitudes are in the western hemisphere.
     """
     coordinate = base.Coordinate(-1.0, Angles.LONGITUDE)
     self.assertEqual(coordinate.hemisphere, Directions.WEST)
Esempio n. 22
0
 def test_southernHemisphere(self):
     """
     Negative latitudes are in the southern hemisphere.
     """
     coordinate = base.Coordinate(-1.0, Angles.LATITUDE)
     self.assertEqual(coordinate.hemisphere, Directions.SOUTH)
Esempio n. 23
0
 def test_easternHemisphere(self):
     """
     Positive longitudes are in the eastern hemisphere.
     """
     coordinate = base.Coordinate(1.0, Angles.LONGITUDE)
     self.assertEqual(coordinate.hemisphere, Directions.EAST)