def test_someSatellitesUsed(self): """ Tests a beacon information with a bunch of satellites, some of them used in computing a fix. """ bi = base.BeaconInformation() for prn in range(1, 10): satellite = base.Satellite(identifier=prn, **self.satelliteKwargs) bi.seenBeacons.add(satellite) if prn % 2: bi.usedBeacons.add(satellite) self.assertEqual(len(bi.seenBeacons), 9) self.assertEqual(len(bi.usedBeacons), 5) self.assertEqual( repr(bi), "<BeaconInformation (used beacons (5): [" "<Satellite (1), azimuth: 1, elevation: 1, snr: 1.0>, " "<Satellite (3), azimuth: 1, elevation: 1, snr: 1.0>, " "<Satellite (5), azimuth: 1, elevation: 1, snr: 1.0>, " "<Satellite (7), azimuth: 1, elevation: 1, snr: 1.0>, " "<Satellite (9), azimuth: 1, elevation: 1, snr: 1.0>], " "unused beacons: [" "<Satellite (2), azimuth: 1, elevation: 1, snr: 1.0>, " "<Satellite (4), azimuth: 1, elevation: 1, snr: 1.0>, " "<Satellite (6), azimuth: 1, elevation: 1, snr: 1.0>, " "<Satellite (8), azimuth: 1, elevation: 1, snr: 1.0>])>")
def test_simple(self): """ Tests a beacon information with a bunch of satellites, none of which used in computing a fix. """ def _buildSatellite(**kw): kwargs = dict(self.satelliteKwargs) kwargs.update(kw) return base.Satellite(**kwargs) beacons = set() for prn in range(1, 10): beacons.add(_buildSatellite(identifier=prn)) bi = base.BeaconInformation(beacons) self.assertEqual(len(bi.seenBeacons), 9) self.assertEqual(len(bi.usedBeacons), 0) self.assertEqual( repr(bi), "<BeaconInformation (used beacons (0): [], " "unused beacons: [" "<Satellite (1), azimuth: 1, elevation: 1, snr: 1.0>, " "<Satellite (2), azimuth: 1, elevation: 1, snr: 1.0>, " "<Satellite (3), azimuth: 1, elevation: 1, snr: 1.0>, " "<Satellite (4), azimuth: 1, elevation: 1, snr: 1.0>, " "<Satellite (5), azimuth: 1, elevation: 1, snr: 1.0>, " "<Satellite (6), azimuth: 1, elevation: 1, snr: 1.0>, " "<Satellite (7), azimuth: 1, elevation: 1, snr: 1.0>, " "<Satellite (8), azimuth: 1, elevation: 1, snr: 1.0>, " "<Satellite (9), azimuth: 1, elevation: 1, snr: 1.0>" "])>")
def _fixGSV(self): """ Parses partial visible satellite information from a GSV sentence. """ # To anyone who knows NMEA, this method's name should raise a chuckle's # worth of schadenfreude. 'Fix' GSV? Hah! Ludicrous. beaconInformation = base.BeaconInformation() self._sentenceData["_partialBeaconInformation"] = beaconInformation keys = "satellitePRN", "azimuth", "elevation", "signalToNoiseRatio" for index in range(4): prn, azimuth, elevation, snr = [ getattr(self.currentSentence, attr) for attr in ("%s_%i" % (key, index) for key in keys) ] if prn is None or snr is None: # The peephole optimizer optimizes the jump away, meaning that # coverage.py thinks it isn't covered. It is. Replace it with # break, and watch the test case fail. # ML thread about this issue: http://goo.gl/1KNUi # Related CPython bug: http://bugs.python.org/issue2506 continue satellite = base.Satellite(prn, azimuth, elevation, snr) beaconInformation.seenBeacons.add(satellite)
def test_minimal(self): """ For an empty beacon information object, the number of used beacons is zero, the number of seen beacons is zero, and the repr of the object reflects that. """ bi = base.BeaconInformation() self.assertEqual(len(bi.usedBeacons), 0) expectedRepr = ("<BeaconInformation (" "used beacons (0): [], " "unused beacons: [])>") self.assertEqual(repr(bi), expectedRepr)