<s> """<STR_LIT>""" <EOL> import datetime <EOL> from operator import attrgetter <EOL> from zope . interface import implementer <EOL> from twisted . positioning import base , nmea , ipositioning <EOL> from twisted . positioning . test . receiver import MockPositioningReceiver <EOL> from twisted . trial . unittest import TestCase <EOL> from twisted . positioning . base import Angles <EOL> GPGGA = '<STR_LIT>' <EOL> GPRMC = '<STR_LIT>' <EOL> GPGSA = '<STR_LIT>' <EOL> GPHDT = '<STR_LIT>' <EOL> GPGLL = '<STR_LIT>' <EOL> GPGLL_PARTIAL = '<STR_LIT>' <EOL> GPGSV_SINGLE = '<STR_LIT>' <EOL> GPGSV_EMPTY_MIDDLE = '<STR_LIT>' <EOL> GPGSV_SEQ = GPGSV_FIRST , GPGSV_MIDDLE , GPGSV_LAST = """<STR_LIT>""" . split ( ) <EOL> @ implementer ( ipositioning . INMEAReceiver ) <EOL> class NMEATestReceiver ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . clear ( ) <EOL> def clear ( self ) : <EOL> """<STR_LIT>""" <EOL> self . receivedSentence = None <EOL> def sentenceReceived ( self , sentence ) : <EOL> self . receivedSentence = sentence <EOL> class CallbackTests ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> receiver = NMEATestReceiver ( ) <EOL> self . protocol = nmea . NMEAProtocol ( receiver , self . _sentenceCallback ) <EOL> self . sentenceTypes = set ( ) <EOL> def _sentenceCallback ( self , sentence ) : <EOL> """<STR_LIT>""" <EOL> self . sentenceTypes . add ( sentence . type ) <EOL> def test_callbacksCalled ( self ) : <EOL> """<STR_LIT>""" <EOL> sentencesByType = { <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] <EOL> } <EOL> for sentenceType , sentences in sentencesByType . iteritems ( ) : <EOL> for sentence in sentences : <EOL> self . protocol . lineReceived ( sentence ) <EOL> self . assertEqual ( self . sentenceTypes , set ( [ sentenceType ] ) ) <EOL> self . sentenceTypes . clear ( ) <EOL> class BrokenSentenceCallbackTests ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> receiver = NMEATestReceiver ( ) <EOL> self . protocol = nmea . NMEAProtocol ( receiver , self . _sentenceCallback ) <EOL> def _sentenceCallback ( self , sentence ) : <EOL> """<STR_LIT>""" <EOL> raise AttributeError ( "<STR_LIT>" ) <EOL> def test_dontSwallowCallbackExceptions ( self ) : <EOL> """<STR_LIT>""" <EOL> lineReceived = self . protocol . lineReceived <EOL> self . assertRaises ( AttributeError , lineReceived , '<STR_LIT>' ) <EOL> class SplitTest ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_withChecksum ( self ) : <EOL> """<STR_LIT>""" <EOL> splitSentence = nmea . _split ( "<STR_LIT>" ) <EOL> self . assertEqual ( splitSentence , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_noCheckum ( self ) : <EOL> """<STR_LIT>""" <EOL> splitSentence = nmea . _split ( "<STR_LIT>" ) <EOL> self . assertEqual ( splitSentence , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> class ChecksumTests ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_valid ( self ) : <EOL> """<STR_LIT>""" <EOL> nmea . _validateChecksum ( GPGGA ) <EOL> def test_missing ( self ) : <EOL> """<STR_LIT>""" <EOL> nmea . _validateChecksum ( GPGGA [ : - <NUM_LIT:2> ] ) <EOL> def test_invalid ( self ) : <EOL> """<STR_LIT>""" <EOL> validate = nmea . _validateChecksum <EOL> bareSentence , checksum = GPGGA . split ( "<STR_LIT:*>" ) <EOL> badChecksum = "<STR_LIT>" % ( int ( checksum , <NUM_LIT:16> ) + <NUM_LIT:1> ) <EOL> sentences = [ "<STR_LIT>" % ( bareSentence , badChecksum ) ] <EOL> for s in sentences : <EOL> self . assertRaises ( base . InvalidChecksum , validate , s ) <EOL> class NMEAReceiverSetup ( object ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> self . receiver = NMEATestReceiver ( ) <EOL> self . protocol = nmea . NMEAProtocol ( self . receiver ) <EOL> class GSVSequenceTests ( NMEAReceiverSetup , TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_firstSentence ( self ) : <EOL> """<STR_LIT>""" <EOL> self . protocol . lineReceived ( GPGSV_FIRST ) <EOL> sentence = self . receiver . receivedSentence <EOL> self . assertTrue ( sentence . _isFirstGSVSentence ( ) ) <EOL> self . assertFalse ( sentence . _isLastGSVSentence ( ) ) <EOL> def test_middleSentence ( self ) : <EOL> """<STR_LIT>""" <EOL> self . protocol . lineReceived ( GPGSV_MIDDLE ) <EOL> sentence = self . receiver . receivedSentence <EOL> self . assertFalse ( sentence . _isFirstGSVSentence ( ) ) <EOL> self . assertFalse ( sentence . _isLastGSVSentence ( ) ) <EOL> def test_lastSentence ( self ) : <EOL> """<STR_LIT>""" <EOL> self . protocol . lineReceived ( GPGSV_LAST ) <EOL> sentence = self . receiver . receivedSentence <EOL> self . assertFalse ( sentence . _isFirstGSVSentence ( ) ) <EOL> self . assertTrue ( sentence . _isLastGSVSentence ( ) ) <EOL> class BogusSentenceTests ( NMEAReceiverSetup , TestCase ) : <EOL> """<STR_LIT>""" <EOL> def assertRaisesOnSentence ( self , exceptionClass , sentence ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaises ( exceptionClass , self . protocol . lineReceived , sentence ) <EOL> def test_raiseOnUnknownSentenceType ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaisesOnSentence ( ValueError , "<STR_LIT>" ) <EOL> def test_raiseOnMalformedSentences ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaisesOnSentence ( base . InvalidSentence , "<STR_LIT>" ) <EOL> class NMEASentenceTests ( NMEAReceiverSetup , TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_repr ( self ) : <EOL> """<STR_LIT>""" <EOL> sentencesWithExpectedRepr = [ <EOL> ( GPGSA , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> ] <EOL> for sentence , expectedRepr in sentencesWithExpectedRepr : <EOL> self . protocol . lineReceived ( sentence ) <EOL> received = self . receiver . receivedSentence <EOL> self . assertEqual ( repr ( received ) , expectedRepr ) <EOL> class ParsingTests ( NMEAReceiverSetup , TestCase ) : <EOL> """<STR_LIT>""" <EOL> def _parserTest ( self , sentence , expected ) : <EOL> """<STR_LIT>""" <EOL> self . protocol . lineReceived ( sentence ) <EOL> received = self . receiver . receivedSentence <EOL> self . assertEqual ( expected , received . _sentenceData ) <EOL> def test_fullRMC ( self ) : <EOL> """<STR_LIT>""" <EOL> expected = { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:N>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:E>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:A>' , <EOL> } <EOL> self . _parserTest ( GPRMC , expected ) <EOL> def test_fullGGA ( self ) : <EOL> """<STR_LIT>""" <EOL> expected = { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:M>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:M>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:N>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:E>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> } <EOL> self . _parserTest ( GPGGA , expected ) <EOL> def test_fullGLL ( self ) : <EOL> """<STR_LIT>""" <EOL> expected = { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:N>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:A>' , <EOL> } <EOL> self . _parserTest ( GPGLL , expected ) <EOL> def test_partialGLL ( self ) : <EOL> """<STR_LIT>""" <EOL> expected = { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:S>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:E>' , <EOL> } <EOL> self . _parserTest ( GPGLL_PARTIAL , expected ) <EOL> def test_fullGSV ( self ) : <EOL> """<STR_LIT>""" <EOL> expected = { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT:3>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> self . _parserTest ( GPGSV_FIRST , expected ) <EOL> def test_partialGSV ( self ) : <EOL> """<STR_LIT>""" <EOL> expected = { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:3>' , <EOL> '<STR_LIT>' : '<STR_LIT:3>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> self . _parserTest ( GPGSV_LAST , expected ) <EOL> def test_fullHDT ( self ) : <EOL> """<STR_LIT>""" <EOL> expected = { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> self . _parserTest ( GPHDT , expected ) <EOL> def test_typicalGSA ( self ) : <EOL> """<STR_LIT>""" <EOL> expected = { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:A>' , <EOL> '<STR_LIT>' : '<STR_LIT:3>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:1.0>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> self . _parserTest ( GPGSA , expected ) <EOL> class FixUnitsTests ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . adapter = nmea . NMEAAdapter ( base . BasePositioningReceiver ( ) ) <EOL> def test_noValueKey ( self ) : <EOL> """<STR_LIT>""" <EOL> class FakeSentence ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . foo = <NUM_LIT:1> <EOL> self . adapter . currentSentence = FakeSentence ( ) <EOL> self . adapter . _fixUnits ( unitKey = "<STR_LIT>" , unit = "<STR_LIT:N>" ) <EOL> self . assertNotEqual ( self . adapter . _sentenceData [ "<STR_LIT:foo>" ] , <NUM_LIT:1> ) <EOL> def test_unitKeyButNoUnit ( self ) : <EOL> """<STR_LIT>""" <EOL> class FakeSentence ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . foo = <NUM_LIT:1> <EOL> self . fooUnits = "<STR_LIT:N>" <EOL> self . adapter . currentSentence = FakeSentence ( ) <EOL> self . adapter . _fixUnits ( unitKey = "<STR_LIT>" ) <EOL> self . assertNotEqual ( self . adapter . _sentenceData [ "<STR_LIT:foo>" ] , <NUM_LIT:1> ) <EOL> def test_noValueKeyAndNoUnitKey ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaises ( ValueError , self . adapter . _fixUnits , unit = "<STR_LIT>" ) <EOL> class FixerTestMixin : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . adapter = nmea . NMEAAdapter ( base . BasePositioningReceiver ( ) ) <EOL> def _fixerTest ( self , sentenceData , expected = None , exceptionClass = None ) : <EOL> """<STR_LIT>""" <EOL> sentence = nmea . NMEASentence ( sentenceData ) <EOL> def receiveSentence ( ) : <EOL> self . adapter . sentenceReceived ( sentence ) <EOL> if exceptionClass is None : <EOL> receiveSentence ( ) <EOL> self . assertEqual ( self . adapter . _state , expected ) <EOL> else : <EOL> self . assertRaises ( exceptionClass , receiveSentence ) <EOL> self . adapter . clear ( ) <EOL> class TimestampFixerTests ( FixerTestMixin , TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_simple ( self ) : <EOL> """<STR_LIT>""" <EOL> data = { '<STR_LIT>' : '<STR_LIT>' } <EOL> expected = { '<STR_LIT>' : datetime . time ( <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT> ) } <EOL> self . _fixerTest ( data , expected ) <EOL> def test_broken ( self ) : <EOL> """<STR_LIT>""" <EOL> badTimestamps = '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> for t in badTimestamps : <EOL> self . _fixerTest ( { '<STR_LIT>' : t } , exceptionClass = ValueError ) <EOL> class DatestampFixerTests ( FixerTestMixin , TestCase ) : <EOL> def test_defaultYearThreshold ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( self . adapter . yearThreshold , <NUM_LIT> ) <EOL> def test_beforeThreshold ( self ) : <EOL> """<STR_LIT>""" <EOL> datestring , date = '<STR_LIT>' , datetime . date ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> self . _fixerTest ( { '<STR_LIT>' : datestring } , { '<STR_LIT>' : date } ) <EOL> def test_afterThreshold ( self ) : <EOL> """<STR_LIT>""" <EOL> datestring , date = '<STR_LIT>' , datetime . date ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> self . _fixerTest ( { '<STR_LIT>' : datestring } , { '<STR_LIT>' : date } ) <EOL> def test_invalidMonth ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _fixerTest ( { '<STR_LIT>' : '<STR_LIT>' } , exceptionClass = ValueError ) <EOL> def test_invalidDay ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _fixerTest ( { '<STR_LIT>' : '<STR_LIT>' } , exceptionClass = ValueError ) <EOL> self . _fixerTest ( { '<STR_LIT>' : '<STR_LIT>' } , exceptionClass = ValueError ) <EOL> def _nmeaFloat ( degrees , minutes ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % ( degrees , minutes ) <EOL> def _coordinateSign ( hemisphere ) : <EOL> """<STR_LIT>""" <EOL> return <NUM_LIT:1> if hemisphere in "<STR_LIT>" else - <NUM_LIT:1> <EOL> def _coordinateType ( hemisphere ) : <EOL> """<STR_LIT>""" <EOL> return Angles . LATITUDE if hemisphere in "<STR_LIT>" else Angles . LONGITUDE <EOL> class CoordinateFixerTests ( FixerTestMixin , TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_north ( self ) : <EOL> """<STR_LIT>""" <EOL> sentenceData = { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT:N>" } <EOL> state = { "<STR_LIT>" : base . Coordinate ( <NUM_LIT> , Angles . LATITUDE ) } <EOL> self . _fixerTest ( sentenceData , state ) <EOL> def test_south ( self ) : <EOL> """<STR_LIT>""" <EOL> sentenceData = { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT:S>" } <EOL> state = { "<STR_LIT>" : base . Coordinate ( - <NUM_LIT> , Angles . LATITUDE ) } <EOL> self . _fixerTest ( sentenceData , state ) <EOL> def test_east ( self ) : <EOL> """<STR_LIT>""" <EOL> sentenceData = { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT:E>" } <EOL> state = { "<STR_LIT>" : base . Coordinate ( <NUM_LIT> , Angles . LONGITUDE ) } <EOL> self . _fixerTest ( sentenceData , state ) <EOL> def test_west ( self ) : <EOL> """<STR_LIT>""" <EOL> sentenceData = { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } <EOL> state = { "<STR_LIT>" : base . Coordinate ( - <NUM_LIT> , Angles . LONGITUDE ) } <EOL> self . _fixerTest ( sentenceData , state ) <EOL> def test_badHemisphere ( self ) : <EOL> """<STR_LIT>""" <EOL> sentenceData = { '<STR_LIT>' : '<STR_LIT>' } <EOL> self . _fixerTest ( sentenceData , exceptionClass = ValueError ) <EOL> def test_badHemisphereSign ( self ) : <EOL> """<STR_LIT>""" <EOL> getSign = lambda : self . adapter . _getHemisphereSign ( "<STR_LIT>" ) <EOL> self . assertRaises ( ValueError , getSign ) <EOL> class AltitudeFixerTests ( FixerTestMixin , TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_fixAltitude ( self ) : <EOL> """<STR_LIT>""" <EOL> key , value = '<STR_LIT>' , '<STR_LIT>' <EOL> altitude = base . Altitude ( float ( value ) ) <EOL> self . _fixerTest ( { key : value } , { key : altitude } ) <EOL> def test_heightOfGeoidAboveWGS84 ( self ) : <EOL> """<STR_LIT>""" <EOL> key , value = '<STR_LIT>' , '<STR_LIT>' <EOL> altitude = base . Altitude ( float ( value ) ) <EOL> self . _fixerTest ( { key : value } , { key : altitude } ) <EOL> class SpeedFixerTests ( FixerTestMixin , TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_speedInKnots ( self ) : <EOL> """<STR_LIT>""" <EOL> key , value , targetKey = "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" <EOL> speed = base . Speed ( float ( value ) * base . MPS_PER_KNOT ) <EOL> self . _fixerTest ( { key : value } , { targetKey : speed } ) <EOL> class VariationFixerTests ( FixerTestMixin , TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_west ( self ) : <EOL> """<STR_LIT>""" <EOL> variation , direction = "<STR_LIT>" , "<STR_LIT>" <EOL> heading = base . Heading . fromFloats ( variationValue = - <NUM_LIT:1> * float ( variation ) ) <EOL> sentenceData = { '<STR_LIT>' : variation , <EOL> '<STR_LIT>' : direction } <EOL> self . _fixerTest ( sentenceData , { '<STR_LIT>' : heading } ) <EOL> def test_east ( self ) : <EOL> """<STR_LIT>""" <EOL> variation , direction = "<STR_LIT>" , "<STR_LIT:E>" <EOL> heading = base . Heading . fromFloats ( variationValue = float ( variation ) ) <EOL> sentenceData = { '<STR_LIT>' : variation , <EOL> '<STR_LIT>' : direction } <EOL> self . _fixerTest ( sentenceData , { '<STR_LIT>' : heading } ) <EOL> def test_withHeading ( self ) : <EOL> """<STR_LIT>""" <EOL> trueHeading , variation , direction = "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:E>" <EOL> sentenceData = { '<STR_LIT>' : trueHeading , <EOL> '<STR_LIT>' : variation , <EOL> '<STR_LIT>' : direction } <EOL> heading = base . Heading . fromFloats ( float ( trueHeading ) , <EOL> variationValue = float ( variation ) ) <EOL> self . _fixerTest ( sentenceData , { '<STR_LIT>' : heading } ) <EOL> class PositionErrorFixerTests ( FixerTestMixin , TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_simple ( self ) : <EOL> self . _fixerTest ( <EOL> { '<STR_LIT>' : '<STR_LIT>' } , <EOL> { '<STR_LIT>' : base . PositionError ( hdop = <NUM_LIT> ) } ) <EOL> def test_mixing ( self ) : <EOL> pdop , hdop , vdop = "<STR_LIT:1>" , "<STR_LIT:1>" , "<STR_LIT:1>" <EOL> positionError = base . PositionError ( pdop = float ( pdop ) , <EOL> hdop = float ( hdop ) , <EOL> vdop = float ( vdop ) ) <EOL> sentenceData = { '<STR_LIT>' : pdop , <EOL> '<STR_LIT>' : hdop , <EOL> '<STR_LIT>' : vdop } <EOL> self . _fixerTest ( sentenceData , { "<STR_LIT>" : positionError } ) <EOL> class ValidFixTests ( FixerTestMixin , TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_GGA ( self ) : <EOL> """<STR_LIT>""" <EOL> sentenceData = { '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : nmea . GPGGAFixQualities . GPS_FIX } <EOL> expectedState = { '<STR_LIT>' : base . Altitude ( <NUM_LIT> ) } <EOL> self . _fixerTest ( sentenceData , expectedState ) <EOL> def test_GLL ( self ) : <EOL> """<STR_LIT>""" <EOL> sentenceData = { '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : nmea . GPGLLGPRMCFixQualities . ACTIVE } <EOL> expectedState = { '<STR_LIT>' : base . Altitude ( <NUM_LIT> ) } <EOL> self . _fixerTest ( sentenceData , expectedState ) <EOL> class InvalidFixTests ( FixerTestMixin , TestCase ) : <EOL> """<STR_LIT>""" <EOL> def _invalidFixTest ( self , sentenceData ) : <EOL> """<STR_LIT>""" <EOL> self . _fixerTest ( sentenceData , { } ) <EOL> def test_GGA ( self ) : <EOL> """<STR_LIT>""" <EOL> sentenceData = { '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : nmea . GPGGAFixQualities . INVALID_FIX } <EOL> self . _invalidFixTest ( sentenceData ) <EOL> def test_GLL ( self ) : <EOL> """<STR_LIT>""" <EOL> sentenceData = { '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : nmea . GPGLLGPRMCFixQualities . VOID } <EOL> self . _invalidFixTest ( sentenceData ) <EOL> def test_badGSADataMode ( self ) : <EOL> """<STR_LIT>""" <EOL> sentenceData = { '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : nmea . GPGLLGPRMCFixQualities . ACTIVE , <EOL> '<STR_LIT>' : nmea . GPGSAFixTypes . GSA_NO_FIX } <EOL> self . _invalidFixTest ( sentenceData ) <EOL> def test_badGSAFixType ( self ) : <EOL> """<STR_LIT>""" <EOL> sentenceData = { '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : nmea . GPGLLGPRMCFixQualities . VOID , <EOL> '<STR_LIT>' : nmea . GPGSAFixTypes . GSA_2D_FIX } <EOL> self . _invalidFixTest ( sentenceData ) <EOL> def test_badGSADataModeAndFixType ( self ) : <EOL> """<STR_LIT>""" <EOL> sentenceData = { '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : nmea . GPGLLGPRMCFixQualities . VOID , <EOL> '<STR_LIT>' : nmea . GPGSAFixTypes . GSA_NO_FIX } <EOL> self . _invalidFixTest ( sentenceData ) <EOL> class NMEAReceiverTest ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . receiver = MockPositioningReceiver ( ) <EOL> self . adapter = nmea . NMEAAdapter ( self . receiver ) <EOL> self . protocol = nmea . NMEAProtocol ( self . adapter ) <EOL> def test_onlyFireWhenCurrentSentenceHasNewInformation ( self ) : <EOL> """<STR_LIT>""" <EOL> self . protocol . lineReceived ( GPGGA ) <EOL> GPGGACallbacks = set ( [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> self . assertEqual ( set ( self . receiver . called . keys ( ) ) , GPGGACallbacks ) <EOL> self . receiver . clear ( ) <EOL> self . assertNotEqual ( self . adapter . _state , { } ) <EOL> self . protocol . lineReceived ( GPHDT ) <EOL> GPHDTCallbacks = set ( [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( set ( self . receiver . called . keys ( ) ) , GPHDTCallbacks ) <EOL> def _receiverTest ( self , sentences , expectedFired = ( ) , extraTest = None ) : <EOL> """<STR_LIT>""" <EOL> for sentence in sentences : <EOL> self . protocol . lineReceived ( sentence ) <EOL> actuallyFired = self . receiver . called . keys ( ) <EOL> self . assertEqual ( set ( actuallyFired ) , set ( expectedFired ) ) <EOL> if extraTest is not None : <EOL> extraTest ( ) <EOL> self . receiver . clear ( ) <EOL> self . adapter . clear ( ) <EOL> def test_positionErrorUpdateAcrossStates ( self ) : <EOL> """<STR_LIT>""" <EOL> sentences = [ GPGSA ] + GPGSV_SEQ <EOL> callbacksFired = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> def _getIdentifiers ( beacons ) : <EOL> return sorted ( map ( attrgetter ( "<STR_LIT>" ) , beacons ) ) <EOL> def checkBeaconInformation ( ) : <EOL> beaconInformation = self . adapter . _state [ '<STR_LIT>' ] <EOL> seenIdentifiers = _getIdentifiers ( beaconInformation . seenBeacons ) <EOL> expected = [ <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:16> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> self . assertEqual ( seenIdentifiers , expected ) <EOL> usedIdentifiers = _getIdentifiers ( beaconInformation . usedBeacons ) <EOL> self . assertEqual ( usedIdentifiers , [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> self . _receiverTest ( sentences , callbacksFired , checkBeaconInformation ) <EOL> def test_emptyMiddleGSV ( self ) : <EOL> """<STR_LIT>""" <EOL> sentences = [ GPGSV_EMPTY_MIDDLE ] <EOL> callbacksFired = [ '<STR_LIT>' ] <EOL> def checkBeaconInformation ( ) : <EOL> beaconInformation = self . adapter . _state [ '<STR_LIT>' ] <EOL> seenBeacons = beaconInformation . seenBeacons <EOL> self . assertEqual ( len ( seenBeacons ) , <NUM_LIT:2> ) <EOL> self . assertIn ( <NUM_LIT> , [ b . identifier for b in seenBeacons ] ) <EOL> self . _receiverTest ( sentences , callbacksFired , checkBeaconInformation ) <EOL> def test_GGASentences ( self ) : <EOL> """<STR_LIT>""" <EOL> sentences = [ GPGGA ] <EOL> callbacksFired = [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> self . _receiverTest ( sentences , callbacksFired ) <EOL> def test_GGAWithDateInState ( self ) : <EOL> """<STR_LIT>""" <EOL> self . adapter . _state [ "<STR_LIT>" ] = datetime . date ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> sentences = [ GPGGA ] <EOL> callbacksFired = [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> self . _receiverTest ( sentences , callbacksFired ) <EOL> def test_RMCSentences ( self ) : <EOL> """<STR_LIT>""" <EOL> sentences = [ GPRMC ] <EOL> callbacksFired = [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> self . _receiverTest ( sentences , callbacksFired ) <EOL> def test_GSVSentences ( self ) : <EOL> """<STR_LIT>""" <EOL> sentences = [ GPGSV_FIRST , GPGSV_MIDDLE , GPGSV_LAST ] <EOL> callbacksFired = [ '<STR_LIT>' ] <EOL> def checkPartialInformation ( ) : <EOL> self . assertNotIn ( '<STR_LIT>' , self . adapter . _state ) <EOL> self . _receiverTest ( sentences , callbacksFired , checkPartialInformation ) <EOL> def test_emptyMiddleEntriesGSVSequence ( self ) : <EOL> """<STR_LIT>""" <EOL> sentences = [ GPGSV_EMPTY_MIDDLE ] <EOL> self . _receiverTest ( sentences , [ "<STR_LIT>" ] ) <EOL> def test_incompleteGSVSequence ( self ) : <EOL> """<STR_LIT>""" <EOL> sentences = [ GPGSV_FIRST ] <EOL> self . _receiverTest ( sentences ) <EOL> def test_singleSentenceGSVSequence ( self ) : <EOL> """<STR_LIT>""" <EOL> sentences = [ GPGSV_SINGLE ] <EOL> self . _receiverTest ( sentences , [ "<STR_LIT>" ] ) <EOL> def test_GLLSentences ( self ) : <EOL> """<STR_LIT>""" <EOL> sentences = [ GPGLL_PARTIAL , GPGLL ] <EOL> self . _receiverTest ( sentences , [ '<STR_LIT>' ] ) <EOL> def test_HDTSentences ( self ) : <EOL> """<STR_LIT>""" <EOL> sentences = [ GPHDT ] <EOL> self . _receiverTest ( sentences , [ '<STR_LIT>' ] ) <EOL> def test_mixedSentences ( self ) : <EOL> """<STR_LIT>""" <EOL> sentences = [ GPRMC , GPGGA ] <EOL> callbacksFired = [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> def checkTime ( ) : <EOL> expectedDateTime = datetime . datetime ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT> ) <EOL> self . assertEqual ( self . adapter . _state [ '<STR_LIT:time>' ] , expectedDateTime ) <EOL> self . _receiverTest ( sentences , callbacksFired , checkTime ) <EOL> def test_lotsOfMixedSentences ( self ) : <EOL> """<STR_LIT>""" <EOL> sentences = [ GPGSA ] + GPGSV_SEQ + [ GPRMC , GPGGA , GPGLL ] <EOL> callbacksFired = [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> self . _receiverTest ( sentences , callbacksFired ) </s>
