<s> """<STR_LIT>""" <EOL> import unittest <EOL> from django . contrib . gis . measure import Distance , Area , D , A <EOL> class DistanceTest ( unittest . TestCase ) : <EOL> "<STR_LIT>" <EOL> def testInit ( self ) : <EOL> "<STR_LIT>" <EOL> d = Distance ( m = <NUM_LIT:100> ) <EOL> self . assertEqual ( d . m , <NUM_LIT:100> ) <EOL> d1 , d2 , d3 = D ( m = <NUM_LIT:100> ) , D ( meter = <NUM_LIT:100> ) , D ( metre = <NUM_LIT:100> ) <EOL> for d in ( d1 , d2 , d3 ) : <EOL> self . assertEqual ( d . m , <NUM_LIT:100> ) <EOL> d = D ( nm = <NUM_LIT:100> ) <EOL> self . assertEqual ( d . m , <NUM_LIT> ) <EOL> y1 , y2 , y3 = D ( yd = <NUM_LIT:100> ) , D ( yard = <NUM_LIT:100> ) , D ( Yard = <NUM_LIT:100> ) <EOL> for d in ( y1 , y2 , y3 ) : <EOL> self . assertEqual ( d . yd , <NUM_LIT:100> ) <EOL> mm1 , mm2 = D ( millimeter = <NUM_LIT:1000> ) , D ( MiLLiMeTeR = <NUM_LIT:1000> ) <EOL> for d in ( mm1 , mm2 ) : <EOL> self . assertEqual ( d . m , <NUM_LIT:1.0> ) <EOL> self . assertEqual ( d . mm , <NUM_LIT> ) <EOL> def testInitInvalid ( self ) : <EOL> "<STR_LIT>" <EOL> self . assertRaises ( AttributeError , D , banana = <NUM_LIT:100> ) <EOL> def testAccess ( self ) : <EOL> "<STR_LIT>" <EOL> d = D ( m = <NUM_LIT:100> ) <EOL> self . assertEqual ( d . km , <NUM_LIT:0.1> ) <EOL> self . assertAlmostEqual ( d . ft , <NUM_LIT> , <NUM_LIT:3> ) <EOL> def testAccessInvalid ( self ) : <EOL> "<STR_LIT>" <EOL> d = D ( m = <NUM_LIT:100> ) <EOL> self . failIf ( hasattr ( d , '<STR_LIT>' ) ) <EOL> def testAddition ( self ) : <EOL> "<STR_LIT>" <EOL> d1 = D ( m = <NUM_LIT:100> ) <EOL> d2 = D ( m = <NUM_LIT:200> ) <EOL> d3 = d1 + d2 <EOL> self . assertEqual ( d3 . m , <NUM_LIT> ) <EOL> d3 += d1 <EOL> self . assertEqual ( d3 . m , <NUM_LIT> ) <EOL> d4 = d1 - d2 <EOL> self . assertEqual ( d4 . m , - <NUM_LIT:100> ) <EOL> d4 -= d1 <EOL> self . assertEqual ( d4 . m , - <NUM_LIT:200> ) <EOL> try : <EOL> d5 = d1 + <NUM_LIT:1> <EOL> except TypeError , e : <EOL> pass <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) <EOL> try : <EOL> d5 = d1 - <NUM_LIT:1> <EOL> except TypeError , e : <EOL> pass <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) <EOL> try : <EOL> d1 += <NUM_LIT:1> <EOL> except TypeError , e : <EOL> pass <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) <EOL> try : <EOL> d1 -= <NUM_LIT:1> <EOL> except TypeError , e : <EOL> pass <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) <EOL> def testMultiplication ( self ) : <EOL> "<STR_LIT>" <EOL> d1 = D ( m = <NUM_LIT:100> ) <EOL> d3 = d1 * <NUM_LIT:2> <EOL> self . assertEqual ( d3 . m , <NUM_LIT:200> ) <EOL> d3 = <NUM_LIT:2> * d1 <EOL> self . assertEqual ( d3 . m , <NUM_LIT:200> ) <EOL> d3 *= <NUM_LIT:5> <EOL> self . assertEqual ( d3 . m , <NUM_LIT:1000> ) <EOL> d4 = d1 / <NUM_LIT:2> <EOL> self . assertEqual ( d4 . m , <NUM_LIT:50> ) <EOL> d4 /= <NUM_LIT:5> <EOL> self . assertEqual ( d4 . m , <NUM_LIT:10> ) <EOL> a5 = d1 * D ( m = <NUM_LIT:10> ) <EOL> self . assert_ ( isinstance ( a5 , Area ) ) <EOL> self . assertEqual ( a5 . sq_m , <NUM_LIT:100> * <NUM_LIT:10> ) <EOL> try : <EOL> d1 *= D ( m = <NUM_LIT:1> ) <EOL> except TypeError , e : <EOL> pass <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) <EOL> try : <EOL> d5 = d1 / D ( m = <NUM_LIT:1> ) <EOL> except TypeError , e : <EOL> pass <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) <EOL> try : <EOL> d1 /= D ( m = <NUM_LIT:1> ) <EOL> except TypeError , e : <EOL> pass <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) <EOL> def testUnitConversions ( self ) : <EOL> "<STR_LIT>" <EOL> d1 = D ( m = <NUM_LIT:100> ) <EOL> d2 = D ( km = <NUM_LIT:1> ) <EOL> d3 = d1 + d2 <EOL> self . assertEqual ( d3 . _default_unit , '<STR_LIT:m>' ) <EOL> d4 = d2 + d1 <EOL> self . assertEqual ( d4 . _default_unit , '<STR_LIT>' ) <EOL> d5 = d1 * <NUM_LIT:2> <EOL> self . assertEqual ( d5 . _default_unit , '<STR_LIT:m>' ) <EOL> d6 = d1 / <NUM_LIT:2> <EOL> self . assertEqual ( d6 . _default_unit , '<STR_LIT:m>' ) <EOL> def testComparisons ( self ) : <EOL> "<STR_LIT>" <EOL> d1 = D ( m = <NUM_LIT:100> ) <EOL> d2 = D ( km = <NUM_LIT:1> ) <EOL> d3 = D ( km = <NUM_LIT:0> ) <EOL> self . assert_ ( d2 > d1 ) <EOL> self . assert_ ( d1 == d1 ) <EOL> self . assert_ ( d1 < d2 ) <EOL> self . failIf ( d3 ) <EOL> def testUnitsStr ( self ) : <EOL> "<STR_LIT>" <EOL> d1 = D ( m = <NUM_LIT:100> ) <EOL> d2 = D ( km = <NUM_LIT> ) <EOL> self . assertEqual ( str ( d1 ) , '<STR_LIT>' ) <EOL> self . assertEqual ( str ( d2 ) , '<STR_LIT>' ) <EOL> self . assertEqual ( repr ( d1 ) , '<STR_LIT>' ) <EOL> self . assertEqual ( repr ( d2 ) , '<STR_LIT>' ) <EOL> def testUnitAttName ( self ) : <EOL> "<STR_LIT>" <EOL> unit_tuple = [ ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> for nm , att in unit_tuple : <EOL> self . assertEqual ( att , D . unit_attname ( nm ) ) <EOL> class AreaTest ( unittest . TestCase ) : <EOL> "<STR_LIT>" <EOL> def testInit ( self ) : <EOL> "<STR_LIT>" <EOL> a = Area ( sq_m = <NUM_LIT:100> ) <EOL> self . assertEqual ( a . sq_m , <NUM_LIT:100> ) <EOL> a = A ( sq_m = <NUM_LIT:100> ) <EOL> self . assertEqual ( a . sq_m , <NUM_LIT:100> ) <EOL> a = A ( sq_mi = <NUM_LIT:100> ) <EOL> self . assertEqual ( a . sq_m , <NUM_LIT> ) <EOL> def testInitInvaliA ( self ) : <EOL> "<STR_LIT>" <EOL> self . assertRaises ( AttributeError , A , banana = <NUM_LIT:100> ) <EOL> def testAccess ( self ) : <EOL> "<STR_LIT>" <EOL> a = A ( sq_m = <NUM_LIT:100> ) <EOL> self . assertEqual ( a . sq_km , <NUM_LIT> ) <EOL> self . assertAlmostEqual ( a . sq_ft , <NUM_LIT> , <NUM_LIT:3> ) <EOL> def testAccessInvaliA ( self ) : <EOL> "<STR_LIT>" <EOL> a = A ( sq_m = <NUM_LIT:100> ) <EOL> self . failIf ( hasattr ( a , '<STR_LIT>' ) ) <EOL> def testAddition ( self ) : <EOL> "<STR_LIT>" <EOL> a1 = A ( sq_m = <NUM_LIT:100> ) <EOL> a2 = A ( sq_m = <NUM_LIT:200> ) <EOL> a3 = a1 + a2 <EOL> self . assertEqual ( a3 . sq_m , <NUM_LIT> ) <EOL> a3 += a1 <EOL> self . assertEqual ( a3 . sq_m , <NUM_LIT> ) <EOL> a4 = a1 - a2 <EOL> self . assertEqual ( a4 . sq_m , - <NUM_LIT:100> ) <EOL> a4 -= a1 <EOL> self . assertEqual ( a4 . sq_m , - <NUM_LIT:200> ) <EOL> try : <EOL> a5 = a1 + <NUM_LIT:1> <EOL> except TypeError , e : <EOL> pass <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) <EOL> try : <EOL> a5 = a1 - <NUM_LIT:1> <EOL> except TypeError , e : <EOL> pass <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) <EOL> try : <EOL> a1 += <NUM_LIT:1> <EOL> except TypeError , e : <EOL> pass <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) <EOL> try : <EOL> a1 -= <NUM_LIT:1> <EOL> except TypeError , e : <EOL> pass <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) <EOL> def testMultiplication ( self ) : <EOL> "<STR_LIT>" <EOL> a1 = A ( sq_m = <NUM_LIT:100> ) <EOL> a3 = a1 * <NUM_LIT:2> <EOL> self . assertEqual ( a3 . sq_m , <NUM_LIT:200> ) <EOL> a3 = <NUM_LIT:2> * a1 <EOL> self . assertEqual ( a3 . sq_m , <NUM_LIT:200> ) <EOL> a3 *= <NUM_LIT:5> <EOL> self . assertEqual ( a3 . sq_m , <NUM_LIT:1000> ) <EOL> a4 = a1 / <NUM_LIT:2> <EOL> self . assertEqual ( a4 . sq_m , <NUM_LIT:50> ) <EOL> a4 /= <NUM_LIT:5> <EOL> self . assertEqual ( a4 . sq_m , <NUM_LIT:10> ) <EOL> try : <EOL> a5 = a1 * A ( sq_m = <NUM_LIT:1> ) <EOL> except TypeError , e : <EOL> pass <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) <EOL> try : <EOL> a1 *= A ( sq_m = <NUM_LIT:1> ) <EOL> except TypeError , e : <EOL> pass <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) <EOL> try : <EOL> a5 = a1 / A ( sq_m = <NUM_LIT:1> ) <EOL> except TypeError , e : <EOL> pass <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) <EOL> try : <EOL> a1 /= A ( sq_m = <NUM_LIT:1> ) <EOL> except TypeError , e : <EOL> pass <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) <EOL> def testUnitConversions ( self ) : <EOL> "<STR_LIT>" <EOL> a1 = A ( sq_m = <NUM_LIT:100> ) <EOL> a2 = A ( sq_km = <NUM_LIT:1> ) <EOL> a3 = a1 + a2 <EOL> self . assertEqual ( a3 . _default_unit , '<STR_LIT>' ) <EOL> a4 = a2 + a1 <EOL> self . assertEqual ( a4 . _default_unit , '<STR_LIT>' ) <EOL> a5 = a1 * <NUM_LIT:2> <EOL> self . assertEqual ( a5 . _default_unit , '<STR_LIT>' ) <EOL> a6 = a1 / <NUM_LIT:2> <EOL> self . assertEqual ( a6 . _default_unit , '<STR_LIT>' ) <EOL> def testComparisons ( self ) : <EOL> "<STR_LIT>" <EOL> a1 = A ( sq_m = <NUM_LIT:100> ) <EOL> a2 = A ( sq_km = <NUM_LIT:1> ) <EOL> a3 = A ( sq_km = <NUM_LIT:0> ) <EOL> self . assert_ ( a2 > a1 ) <EOL> self . assert_ ( a1 == a1 ) <EOL> self . assert_ ( a1 < a2 ) <EOL> self . failIf ( a3 ) <EOL> def testUnitsStr ( self ) : <EOL> "<STR_LIT>" <EOL> a1 = A ( sq_m = <NUM_LIT:100> ) <EOL> a2 = A ( sq_km = <NUM_LIT> ) <EOL> self . assertEqual ( str ( a1 ) , '<STR_LIT>' ) <EOL> self . assertEqual ( str ( a2 ) , '<STR_LIT>' ) <EOL> self . assertEqual ( repr ( a1 ) , '<STR_LIT>' ) <EOL> self . assertEqual ( repr ( a2 ) , '<STR_LIT>' ) <EOL> def suite ( ) : <EOL> s = unittest . TestSuite ( ) <EOL> s . addTest ( unittest . makeSuite ( DistanceTest ) ) <EOL> s . addTest ( unittest . makeSuite ( AreaTest ) ) <EOL> return s <EOL> def run ( verbosity = <NUM_LIT:2> ) : <EOL> unittest . TextTestRunner ( verbosity = verbosity ) . run ( suite ( ) ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> run ( ) </s>
