Ϫf\t@dZddlmZddlmZddlmZddlmZm Z ddl m Z ddl m Z Gdd e ZGd d e ZGd d e ZddZddZGdde ZGdde ZGdde ZGdde ZGdde ZGdde ZGdde Zy) z( Test cases for positioning primitives. ) annotations)verify)base)Angles Directions)IPositioningBeacon)TestCasec0eZdZdZddZddZddZddZy) AngleTestsz@ Tests for the L{twisted.positioning.base.Angle} class. cbtj}|jdt|y)zd The repr of an empty angle says that is of unknown type and unknown value. z'NrAngle assertEqualreprselfas D/usr/lib/python3/dist-packages/twisted/positioning/test/test_base.py test_emptyzAngleTests.test_emptys$ JJL BDGLctjtj}|j dt |y)zf The repr of an empty variation says that it is a variation of unknown value.  angleTypezN)rrr VARIATIONrrrs rtest_variationzAngleTests.test_variations- JJ!1!1 2 6Q@rcdtjd}|jdt|y)zz The repr of an angle of unknown type but a given value displays that type and value in its repr. ?z%Nr rs rtest_unknownTypezAngleTests.test_unknownType%s& JJsO @$q'JrcP|jttjdy)zS Trying to create an angle with a bogus type raises C{ValueError}. BOGUSrN) assertRaises ValueErrorrrrs rtest_bogusTypezAngleTests.test_bogusType-s *djjGDrNreturnNone)__name__ __module__ __qualname____doc__rrrr$rrr r sMAKErr ceZdZdZddZddZddZddZddZddZ ddZ dd Z dd Z dd Z dd Zdd ZddZddZddZddZddZddZddZddZddZddZy) HeadingTestszB Tests for the L{twisted.positioning.base.Heading} class. ctjd}|j|jd|jt |d|j |j |j |jy)z Tests that a simple heading has a value in decimal degrees, which is also its value when converted to a float. Its variation, and by consequence its corrected heading, is L{None}. rN)rHeadingrinDecimalDegreesfloat assertIsNone variationcorrectedHeadingrhs r test_simplezHeadingTests.test_simple9sb LL  ++S1 q3' !++& !,,-rchtjd}d}|jt||y)zt A repr of a heading with no variation reports its value and that the variation is unknown. rz*N)rr0rr)rheading expectedReprs r test_headingWithoutVariationReprz-HeadingTests.test_headingWithoutVariationReprEs+ ,,s#C  g 5rcd\}}tjj||}d}|jt ||j ||y)zu A repr of a heading with known variation reports its value and the value of that variation. )r$variationValuez2)>N)rr0 fromFloatsrrformat)rangler4r: reprTemplates rtest_headingWithVariationReprz*HeadingTests.test_headingWithVariationReprNsM &y,,))% )JK  g (;(;E9(MNrct|jtjdtjdy)z> Headings with the same values compare equal. rN)rrr0r#s rtest_valueEqualityzHeadingTests.test_valueEqualityXs& c*DLL,=>rct|jtjdtjdy)zA Headings with different values compare unequal. r@N)assertNotEqualrr0r#s rtest_valueInequalityz!HeadingTests.test_valueInequality^s& DLL-t||C/@Arc.tjdy)zR Headings can be instantiated with a value of 0 and no variation. rNrr0r#s rtest_zeroHeadingEdgeCasez%HeadingTests.test_zeroHeadingEdgeCaseds Qrc0tjddy)zh Headings can be instantiated with a value of 0 and a variation of 180 degrees. rNrMr#s r*test_zeroHeading180DegreeVariationEdgeCasez7HeadingTests.test_zeroHeading180DegreeVariationEdgeCasejs Qrc d|jttjjfi|y)z Helper function for verifying that bad values raise C{ValueError}. @param kw: The keyword arguments passed to L{base.Heading.fromFloats}. N)r!r"rr0rA)rkws r _badValueTestzHeadingTests._badValueTestqs% *dll&=&=DDrc(|jdy)zO Headings can not be instantiated with a value of 360 degrees. gv@ angleValueNrTr#s rtest_badAngleValueEdgeCasez'HeadingTests.test_badAngleValueEdgeCasey e,rc(|jdy)zT Headings can not be instantiated with a variation of -180 degrees. fr?NrXr#s rtest_badVariationEdgeCasez&HeadingTests.test_badVariationEdgeCase &1rc(|jdy)z> Negative heading values raise C{ValueError}. r>rVNrXr#s rtest_negativeHeadingz!HeadingTests.test_negativeHeadingrZrc(|jdy)zK Heading values greater than C{360.0} raise C{ValueError}. g w@rVNrXr#s rtest_headingTooLargez!HeadingTests.test_headingTooLargerZrc(|jdy)zK Variation values less than C{-180.0} raise C{ValueError}. ggr?NrXr#s rtest_variationTooNegativez&HeadingTests.test_variationTooNegativer^rc(|jdy)zM Variation values greater than C{180.0} raise C{ValueError}. gg@r?NrXr#s rtest_variationTooPositivez&HeadingTests.test_variationTooPositives %0rctjjdd}|j|jtj dt jy)zQ A heading with a value and a variation has a corrected heading. rr>r?g&@Nrr0rArr5rrHEADINGr6s rtest_correctedHeadingz"HeadingTests.test_correctedHeadingsB LL # #C # > ++TZZfnn-MNrctjjdd}|j|jtj dt jy)z A heading with a value and a variation has the appropriate corrected heading value, even when the variation puts it across the 360 degree boundary. pv@gr?rNrhr6s rtest_correctedHeadingOverflowz*HeadingTests.test_correctedHeadingOverflowB LL # #E$ # ? ++TZZV^^-LMrctjjdd}|j|jtj dt jy)z A heading with a value and a variation has the appropriate corrected heading value, even when the variation puts it exactly at the 360 degree boundary. rlr?Nrhr6s r%test_correctedHeadingOverflowEdgeCasez2HeadingTests.test_correctedHeadingOverflowEdgeCasernrctjjdd}|j|jtj dt jy)z A heading with a value and a variation has the appropriate corrected heading value, even when the variation puts it under the 0 degree boundary. rrIr?rlNrhr6s rtest_correctedHeadingUnderflowz+HeadingTests.test_correctedHeadingUnderflowsB LL # #C # < ++TZZv~~-NOrctjjdd}|j|jtj dt jy)z A heading with a value and a variation has the appropriate corrected heading value, even when the variation puts it exactly at the 0 degree boundary. rr?rqNrhr6s r&test_correctedHeadingUnderflowEdgeCasez3HeadingTests.test_correctedHeadingUnderflowEdgeCasesB LL # #C # < ++TZZV^^-LMrc"tjjdd}|jd|j |j j d|jd|j |j j dy)zK Setting the sign of a heading changes the variation sign. rr?rpN)rr0rAsetSignrr4r1r6s rtest_setVariationSignz"HeadingTests.test_setVariationSignsg LL # #C # < !  55s; "  55tN)rrrrrrr;s r test_reprzCoordinateTests.test_reprs5 __T* 1$zB  j)<8rctjdtj}ddd}|j t ||y)zU Positive latitudes have a repr that specifies their type and value. r .makeCoordinate.s??3(8(89 9rN)r&base.Coordinate)r)rrs r test_equalityzCoordinateTests.test_equality)s  : )>+;__S&// 2 __S&"2"2 3 B#rctjdtj}|j d|j |j d|j d|j |j dy)zh Setting the sign on a coordinate sets the sign of the value of the coordinate. rrxryrN)rrrrrzrr1rcs r test_signzCoordinateTests.test_signCsZ OOD&// 2 !  ++T2 "  ++U3rcd}tj|tj}|j t |j d|j|jd|j t |j d|j|jd|j t |j d|j|jdy)z Setting a bogus sign value (not -1 or 1) on a coordinate raises C{ValueError} and doesn't affect the coordinate. rr}rr~N) rrrrr!r"rzrr1)rvaluers rtest_badVariationSignz%CoordinateTests.test_badVariationSignNs  OOE6?? 3 *aii5 ++T2 *aii3 ++T2 *aii4 ++T2rctjdtj}|j |j t jy)zD Positive latitudes are in the northern hemisphere. rN)rrrrr hemisphererNORTHrs rtest_northernHemispherez'CoordinateTests.test_northernHemisphere_s4__S&//:  .. 0@0@Arctjdtj}|j |j t jy)zD Positive longitudes are in the eastern hemisphere. rN)rrrrrrrEASTrs rtest_easternHemispherez&CoordinateTests.test_easternHemispherefs4__S&*:*:;  .. @rctjdtj}|j |j t jy)zD Negative latitudes are in the southern hemisphere. rpN)rrrrrrrSOUTHrs rtest_southernHemispherez'CoordinateTests.test_southernHemispherems4__T6??;  .. 0@0@Arctjdtj}|j |j t jy)zD Negative longitudes are in the western hemisphere. rpN)rrrrrrrWESTrs rtest_westernHemispherez&CoordinateTests.test_westernHemispherets4__T6+;+;<  .. @rcdtjdd|jtfdy)zo Accessing the hemisphere for a coordinate that can't compute it raises C{ValueError}. rNcjS)N)r)rsrz4CoordinateTests.test_badHemisphere..s j.C.Cr)rrr!r"rs @rtest_badHemispherez"CoordinateTests.test_badHemisphere{s& __S$/  *&CDrcp|jttd|jttdy)zt Creating a latitude with a value greater than or equal to 90 degrees raises C{ValueError}. rgV@Nr!r" _makeLatituder#s rtest_latitudeTooLargez%CoordinateTests.test_latitudeTooLarges( *mU; *mT:rcp|jttd|jttdy)zr Creating a latitude with a value less than or equal to -90 degrees raises C{ValueError}. gbgVNrr#s rtest_latitudeTooSmallz%CoordinateTests.test_latitudeTooSmalls( *mV< *mU;rcp|jttd|jttdy)zv Creating a longitude with a value greater than or equal to 180 degrees raises C{ValueError}. g@o@gf@Nr!r"_makeLongituder#s rtest_longitudeTooLargez&CoordinateTests.test_longitudeTooLarges( *ne< *neB5rrcJtj|tjS)z7 Builds and returns a latitude of given value. )rrrrrs rrrs ??5&// 22rcJtj|tjS)z8 Builds and returns a longitude of given value. rrs rrrs ??5&"2"2 33rc0eZdZdZddZddZddZddZy) AltitudeTestszC Tests for the L{twisted.positioning.base.Altitude} class. ctjd}|jt|d|j|jd|j|j dtj z y)z Altitudes can be instantiated and reports the correct value in meters and feet, as well as when converted to float. rN)rAltituderr2inMetersinFeetMETERS_PER_FOOTraltitudes r test_valuezAltitudeTests.test_values[ ==% x#. **C0 #0D0D*DErcdtjd}|jt|dy)zF Altitudes report their type and value in their repr. rzN)rrrrrs rrzAltitudeTests.test_reprs'==% h)=>rc|tjd}tjd}|j||y)z< Altitudes with equal values compare equal. rN)rrrr firstAltitudesecondAltitudes rrzAltitudeTests.test_equalitys0 c* s+ 7rc|tjd}tjd}|j||y)zF Altitudes with different values don't compare equal. rrpN)rrrJrs rtest_inequalityzAltitudeTests.test_inequalitys0 c* t, M>:rNr%)r(r)r*r+rrrrr,rrrrsF?8;rrc8eZdZdZddZddZddZddZddZy) SpeedTestsz@ Tests for the L{twisted.positioning.base.Speed} class. ctjd}|j|jd|jt |dy) Speeds can be instantiated, and report their value in meters per second, and can be converted to floats. rN)rSpeedrinMetersPerSecondr2rspeeds rrzSpeedTests.test_value<  4  00$7 ut,rcdtjd}|jt|dy)zC Speeds report their type and value in their repr. rzN)rrrrrs rrzSpeedTests.test_repr' 4  e&:;rcN|jttjdy)zA Creating a negative speed raises C{ValueError}. rpN)r!r"rrr#s rtest_negativeSpeedszSpeedTests.test_negativeSpeedss *djj$7rctjd}|jdtjz |jy)zC A speed can be converted into its value in knots. rrxN)rrr MPS_PER_KNOTinKnotsrs r test_inKnotszSpeedTests.test_inKnots0 3 T... >rc`|jdttjdy)z; A speed can be converted into a C{float}. rN)rr2rrr#s r test_asFloatzSpeedTests.test_asFloat ! eDJJsO45rNr%) r(r)r*r+rrrrrr,rrrrs -<8 ?6rrc8eZdZdZddZddZddZddZddZy) ClimbTestsz6 Tests for L{twisted.positioning.base.Climb}. ctjd}|j|jd|jt |dy)rE@NrClimbrrr2rclimbs rr8zClimbTests.test_simplerrcdtjd}|jt|dy)zC Climbs report their type and value in their repr. r zN)rr rrr s rrzClimbTests.test_repr"rrctjd}|j|jd|jt |dy)z Climbs can have negative values, and still report that value in meters per second and when converted to floats. gENr r s rtest_negativeClimbszClimbTests.test_negativeClimbs)s<  5! 00%8 uu-rctjd}|jdtjz |jy)zC A climb can be converted into its value in knots. rrxN)rr rrrr s rtest_speedInKnotszClimbTests.test_speedInKnots2rrc`|jdttjdy)z; A climb can be converted into a C{float}. rN)rr2rr r#s rrzClimbTests.test_asFloat9rrNr%) r(r)r*r+r8rrrrr,rrrrs -<.?6rrceZdZdZddZddZddZddZddZddZ ddZ dd Z d Z dd Z dd Zdd ZddZy)PositionErrorTestsz> Tests for L{twisted.positioning.base.PositionError}. ctj}|j|j|j|j|j|j y)z~ In an empty L{base.PositionError} with no invariant testing, all dilutions of positions are L{None}. Nr PositionErrorr3pdophdopvdopr positionErrors r test_allUnsetz PositionErrorTests.test_allUnsetEsN **,  -,,- -,,- -,,-rctjd}|j|j|j|j|j|j y)z{ In an empty L{base.PositionError} with invariant testing, all dilutions of positions are L{None}. T) testInvariantNrrs rtest_allUnsetWithInvariantz-PositionErrorTests.test_allUnsetWithInvariantOsP **>  -,,- -,,- -,,-rchtjd}|j|jdy)zN L{base.PositionError}s can be instantiated with just a HDOP. r)rNrrrrrs rtest_withoutInvariantz(PositionErrorTests.test_withoutInvariantYs***4  ++S1rcjtjdd}|j|jdy)zv Creating a simple L{base.PositionError} with just a HDOP while checking the invariant works. rT)rr!Nr$rs rtest_withInvariantz%PositionErrorTests.test_withInvariant`s, **4H  ++S1rctjddd}|j|jd|j|jd|j|j dy)z Creating a L{base.PositionError} with values set to an impossible combination works if the invariant is not checked. r)rrrN)rrrrrr)rerrors rtest_invalidWithoutInvariantz/PositionErrorTests.test_invalidWithoutInvarianthsT ""#C@ S) S) S)rcV|jttjddddy)z Creating a L{base.PositionError} with values set to an impossible combination raises C{ValueError} if the invariant is being tested. rT)rrrr!N)r!r"rrr#s rtest_invalidWithInvariantz,PositionErrorTests.test_invalidWithInvariantrs/       rcxtjdd}d|_|j|jdy)z} You can set the PDOP value to value inconsisted with HDOP and VDOP when not checking the invariant. rrrY@N)rrrr)rpes rtest_setDOPWithoutInvariantz.PositionErrorTests.test_setDOPWithoutInvariants1   Ss 3 %(rctjddd}|j}dd}|jt|||j |j|y)z Attempting to set the PDOP value to value inconsisted with HDOP and VDOP when checking the invariant raises C{ValueError}. rT)rrr!cd|_y)Nr/)r)r0s rsetPDOPz.setPDOPs BGrN)r0base.PositionErrorr&r')rrrr!r"r)rr0rr4s rtest_setDOPWithInvariantz+PositionErrorTests.test_setDOPWithInvariantsN   Ss$ Gww  *gr2 $'rz.c|j|j||j|j||j|j||jt ||j |||fzy)a Tests the DOP values in a position error, and the repr of that position error. @param pe: The position error under test. @type pe: C{PositionError} @param pdop: The expected position dilution of precision. @type pdop: C{float} or L{None} @param hdop: The expected horizontal dilution of precision. @type hdop: C{float} or L{None} @param vdop: The expected vertical dilution of precision. @type vdop: C{float} or L{None} N)rrrrr REPR_TEMPLATE)rr0rrrs r_testDOPzPositionErrorTests._testDOPsf( $' $' $' b4#5#5tT8J#JKrcd\}}|dz|dzz dz}tj||}|j||||y)zF The VDOP is correctly determined from PDOP and HDOP. rIr?)rrNrrr9)rrrrr0s rtest_positionAndHorizontalSetz0PositionErrorTests.test_positionAndHorizontalSetH da$'!c)   T 5 b$d+rcd\}}|dz|dzz dz}tj||}|j||||y)zF The HDOP is correctly determined from PDOP and VDOP. r;r<r=)rrNr>)rrrrr0s rtest_positionAndVerticalSetz.PositionErrorTests.test_positionAndVerticalSetr@rcd\}}|dz|dzzdz}tj||}|j||||y)zF The PDOP is correctly determined from HDOP and VDOP. )rrr<r=r.Nr>)rrrrr0s rtest_horizontalAndVerticalSetz0PositionErrorTests.test_horizontalAndVerticalSetr@rNr%) r0r5r float | NonerrErrEr&r')r(r)r*r+rr"r%r'r*r,r1r6r8r9r?rBrDr,rrrr@s..22*  ) (EML LL L  L  L2,,,rrc4eZdZdZd dZddddZd dZd dZy) BeaconInformationTestszB Tests for L{twisted.positioning.base.BeaconInformation}. ctj}|jt|jdd}|jt ||y)z 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. rz>N)rBeaconInformationrlen usedBeaconsr)rbir;s r test_minimalz#BeaconInformationTests.test_minimalsI  # # % R^^,a0 R  b<0rrxr)azimuth elevationsignalToNoiseRatiocld fd }t}tddD]}|j||tj|}j t |jdj t |jdj t|dy) zw Tests a beacon information with a bunch of satellites, none of which used in computing a fix. cztj}|j|tjdi|S)Nr,)dictsatelliteKwargsupdater Satellite)rSkwargsrs r_buildSatellitez;BeaconInformationTests.test_simple.._buildSatellites1$../F MM" >>+F+ +rrx ) identifier ra, , , , , , , , ])>N)rSr2r&zbase.Satellite) setrangeaddrrIrrJ seenBeaconsrKr)rrXbeaconsprnrLs` rr8z"BeaconInformationTests.test_simples  , %B< 9C KK37 8 9 # #G , R^^,a0 R^^,a0  H  rctj}tddD]_}tjd d|i|j}|j j ||dzsE|jj |a|jt|j d|jt|jd|jt|dy) zv Tests a beacon information with a bunch of satellites, some of them used in computing a fix. rxrYrZr<r[a, , , , ], unused beacons: [, , , ])>Nr,) rrIr]rVrTr_r^rKrrJr)rrLra satellites rtest_someSatellitesUsedz.BeaconInformationTests.test_someSatellitesUseds  # # %B< .CN#N9M9MNI NN  y )Qw""9-  . R^^,a0 R^^,a0  H E rNr%)r(r)r*r+rMrTr8rer,rrrGrGs% 1#$!3OO! F rrGc eZdZdZddZddZy)PositioningBeaconTestsz. Tests for L{base.PositioningBeacon}. ctjtj}|j |t j ttjdy)zX Tests that L{base.PositioningBeacon} implements L{IPositioningBeacon}. rxN)r implementedByrPositioningBeacon assertTruer verifyObject)r implementss rtest_interfacez%PositioningBeaconTests.test_interface*sB(55d6L6LM   #.0F0Fq0IJrc`|jttjddy)z9 Tests the repr of a positioning beacon. Az N)rrrrjr#s rrz PositioningBeaconTests.test_repr2s$ d44S9:NKrNr%)r(r)r*r+rnrr,rrrgrg%sKLrrgc eZdZdZddZddZy)SatelliteTestsz: Tests for L{twisted.positioning.base.Satellite}. c>tjd}|j|jd|j |j |j |j |j |j|jt|dy)z Tests a minimal satellite that only has a known PRN. Tests that the azimuth, elevation and signal to noise ratios are L{None} and verifies the repr. rxz:N) rrVrrZr3rNrOrPrrss rrMzSatelliteTests.test_minimal>sv NN1  q) !))$ !++& !../  GT rcLtjdddd}|j|jd|j|jd|j|j d|j|j d|jt|dy)z Tests a minimal satellite that only has a known PRN. Tests that the azimuth, elevation and signal to noise ratios are correct and verifies the repr. rxgp@g>@g9@)rZrNrOrPz;N)rrVrrZrNrOrPrrts rr8zSatelliteTests.test_simpleNs NN%4D  q) E* d+ --t4  GU rNr%)r(r)r*r+rMr8r,rrrrrr9s  rrrN)rr2r&r)r+ __future__rzope.interfacertwisted.positioningrtwisted.positioning.baserr twisted.positioning.ipositioningrtwisted.trial.unittestr r r.rrrrrrrrGrgrrr,rrr}s#!$7?+!E!EHt48t4nH5hH5V34$;H$;N&6&6R)6)6XK,K,\T XT nLXL(& X& r