<s> import openmdao . units as units <EOL> import unittest <EOL> import math <EOL> import cStringIO <EOL> from pkg_resources import resource_string , resource_stream <EOL> class test_moduleLevelFunctions ( unittest . TestCase ) : <EOL> def tearDown ( self ) : <EOL> unitLib = resource_stream ( units . __name__ , '<STR_LIT>' ) <EOL> units . import_library ( unitLib ) <EOL> def test_importlib ( self ) : <EOL> unitLib_test_bad = resource_stream ( units . __name__ , <EOL> '<STR_LIT>' ) <EOL> try : <EOL> units . import_library ( unitLib_test_bad ) <EOL> except ValueError , err : <EOL> self . assertEqual ( str ( err ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> unitLib_test_bad = resource_stream ( units . __name__ , <EOL> '<STR_LIT>' ) <EOL> try : <EOL> units . import_library ( unitLib_test_bad ) <EOL> except ValueError , err : <EOL> self . assertEqual ( str ( err ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_update_library ( self ) : <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> try : <EOL> x . convert_to_unit ( '<STR_LIT>' ) <EOL> except ValueError , exc : <EOL> self . assertEqual ( str ( exc ) , "<STR_LIT>" ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> update = cStringIO . StringIO ( """<STR_LIT>""" ) <EOL> units . update_library ( update ) <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> x . convert_to_unit ( '<STR_LIT>' ) <EOL> self . assertAlmostEqual ( x . value , <EOL> units . PhysicalQuantity ( <EOL> '<STR_LIT>' ) . value , places = <NUM_LIT:5> ) <EOL> class test_NumberDict ( unittest . TestCase ) : <EOL> def test__UknownKeyGives0 ( self ) : <EOL> x = units . NumberDict ( ) <EOL> self . assertEqual ( x [ <NUM_LIT:0> ] , <NUM_LIT:0> ) <EOL> self . assertEqual ( x [ '<STR_LIT:t>' ] , <NUM_LIT:0> ) <EOL> def test__add__KnownValues ( self ) : <EOL> x = units . NumberDict ( ) <EOL> y = units . NumberDict ( ) <EOL> x [ '<STR_LIT>' ] , x [ '<STR_LIT>' ] = <NUM_LIT:1> , <NUM_LIT:2> <EOL> y [ '<STR_LIT>' ] , y [ '<STR_LIT>' ] = <NUM_LIT:2> , <NUM_LIT:1> <EOL> result1 , result2 = x + y , y + x <EOL> self . assertEqual ( ( <NUM_LIT:3> , <NUM_LIT:3> ) , ( result1 [ '<STR_LIT>' ] , result1 [ '<STR_LIT>' ] ) ) <EOL> self . assertEqual ( ( <NUM_LIT:3> , <NUM_LIT:3> ) , ( result2 [ '<STR_LIT>' ] , result2 [ '<STR_LIT>' ] ) ) <EOL> def test__sub__KnownValues ( self ) : <EOL> x = units . NumberDict ( ) <EOL> y = units . NumberDict ( ) <EOL> x [ '<STR_LIT>' ] , x [ '<STR_LIT>' ] = <NUM_LIT:1> , <NUM_LIT:2> <EOL> y [ '<STR_LIT>' ] , y [ '<STR_LIT>' ] = <NUM_LIT:2> , <NUM_LIT:1> <EOL> result1 , result2 = x - y , y - x <EOL> self . assertEqual ( ( - <NUM_LIT:1> , <NUM_LIT:1> ) , ( result1 [ '<STR_LIT>' ] , result1 [ '<STR_LIT>' ] ) ) <EOL> self . assertEqual ( ( <NUM_LIT:1> , - <NUM_LIT:1> ) , ( result2 [ '<STR_LIT>' ] , result2 [ '<STR_LIT>' ] ) ) <EOL> def test__mul__KnownValues ( self ) : <EOL> x = units . NumberDict ( [ ( '<STR_LIT>' , <NUM_LIT:1> ) , ( '<STR_LIT>' , <NUM_LIT:2> ) ] ) <EOL> y = <NUM_LIT:10> <EOL> result1 , result2 = x * y , y * x <EOL> self . assertEqual ( ( <NUM_LIT:10> , <NUM_LIT:20> ) , ( result1 [ '<STR_LIT>' ] , result1 [ '<STR_LIT>' ] ) ) <EOL> self . assertEqual ( ( <NUM_LIT:10> , <NUM_LIT:20> ) , ( result2 [ '<STR_LIT>' ] , result2 [ '<STR_LIT>' ] ) ) <EOL> def test__div__KnownValues ( self ) : <EOL> x = units . NumberDict ( ) <EOL> x = units . NumberDict ( [ ( '<STR_LIT>' , <NUM_LIT:1> ) , ( '<STR_LIT>' , <NUM_LIT:2> ) ] ) <EOL> y = <NUM_LIT> <EOL> result1 = x / y <EOL> self . assertEqual ( ( <NUM_LIT> , <NUM_LIT> ) , ( result1 [ '<STR_LIT>' ] , result1 [ '<STR_LIT>' ] ) ) <EOL> _unitLib = units . import_library ( resource_stream ( units . __name__ , <EOL> '<STR_LIT>' ) ) <EOL> def _get_powers ( ** powdict ) : <EOL> powers = [ <NUM_LIT:0> ] * len ( _unitLib . base_types ) <EOL> for name , power in powdict . items ( ) : <EOL> powers [ _unitLib . base_types [ name ] ] = power <EOL> return powers <EOL> class test__PhysicalQuantity ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> unitLib = resource_stream ( units . __name__ , '<STR_LIT>' ) <EOL> self . unitlib = units . import_library ( unitLib ) <EOL> def test_init ( self ) : <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> y = units . PhysicalQuantity ( <NUM_LIT:1> , '<STR_LIT:m>' ) <EOL> self . assertEqual ( x . value , y . value ) <EOL> self . assertEqual ( x . unit , y . unit ) <EOL> z = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> try : <EOL> x = units . PhysicalQuantity ( '<STR_LIT:m>' ) <EOL> except TypeError , err : <EOL> self . assertEqual ( str ( err ) , "<STR_LIT>" ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> try : <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> except ValueError , err : <EOL> self . assertEqual ( str ( err ) , "<STR_LIT>" ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> try : <EOL> x = units . PhysicalQuantity ( <NUM_LIT:1> , None ) <EOL> except TypeError , err : <EOL> self . assertEqual ( str ( err ) , "<STR_LIT>" ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_str ( self ) : <EOL> self . assertEqual ( str ( units . PhysicalQuantity ( '<STR_LIT>' ) ) , "<STR_LIT>" ) <EOL> def test_repr ( self ) : <EOL> self . assertEqual ( repr ( units . PhysicalQuantity ( '<STR_LIT>' ) ) , "<STR_LIT>" ) <EOL> def test_cmp ( self ) : <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> y = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> self . assertEqual ( cmp ( x , y ) , - <NUM_LIT:1> ) <EOL> self . assertEqual ( cmp ( y , x ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( cmp ( x , x ) , <NUM_LIT:0> ) <EOL> try : <EOL> cmp ( x , <NUM_LIT:2> ) <EOL> except TypeError , err : <EOL> self . assertEqual ( "<STR_LIT>" , str ( err ) ) <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) <EOL> def test_integers_in_unit_string ( self ) : <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> self . assertAlmostEqual ( x . unit . factor , <NUM_LIT> , places = <NUM_LIT:5> ) <EOL> self . assertEqual ( x . unit . names , { '<STR_LIT:1>' : <NUM_LIT:1> , '<STR_LIT>' : - <NUM_LIT:1> } ) <EOL> self . assertEqual ( x . unit . powers , _get_powers ( time = - <NUM_LIT:1> ) ) <EOL> def test_currency_unit ( self ) : <EOL> try : <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> except ValueError : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_pi ( self ) : <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> x . convert_to_unit ( '<STR_LIT>' ) <EOL> self . assertAlmostEqual ( x . value , <EOL> units . PhysicalQuantity ( '<STR_LIT>' ) . value , <EOL> places = <NUM_LIT:3> ) <EOL> def test_new_units ( self ) : <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> x . convert_to_unit ( '<STR_LIT:h>' ) <EOL> self . assertEqual ( x , units . PhysicalQuantity ( '<STR_LIT>' ) ) <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> x . convert_to_unit ( '<STR_LIT>' ) <EOL> self . assertEqual ( x , units . PhysicalQuantity ( '<STR_LIT>' ) ) <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> x . convert_to_unit ( '<STR_LIT>' ) <EOL> self . assertEqual ( x , units . PhysicalQuantity ( '<STR_LIT>' ) ) <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> x . convert_to_unit ( '<STR_LIT>' ) <EOL> self . assertEqual ( x , units . PhysicalQuantity ( '<STR_LIT>' ) ) <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> x . convert_to_unit ( '<STR_LIT>' ) <EOL> self . assertEqual ( x , units . PhysicalQuantity ( '<STR_LIT>' ) ) <EOL> def test_prefix_plus_math ( self ) : <EOL> x1 = units . convert_units ( <NUM_LIT:1.0> , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( x1 , <NUM_LIT> ) <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> def test_add_known_Values ( self ) : <EOL> known_add_values = ( ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:6> ) , ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:2> ) , ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT> ) ) <EOL> for q1 , q2 , result in known_add_values : <EOL> x = units . PhysicalQuantity ( q1 ) <EOL> y = units . PhysicalQuantity ( q2 ) <EOL> sum = x + y <EOL> self . assertEqual ( sum . value , result ) <EOL> self . assertEqual ( sum . unit , x . unit ) <EOL> q1 = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> q2 = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> try : <EOL> q1 + q2 <EOL> except TypeError , err : <EOL> self . assertEqual ( str ( err ) , "<STR_LIT>" ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> q1 = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> q2 = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> q3 = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> result = q1 + q2 <EOL> self . assertAlmostEqual ( result . value , <NUM_LIT> , <NUM_LIT:3> ) <EOL> self . assertEqual ( result . unit , q1 . unit ) <EOL> try : <EOL> q3 + q2 <EOL> except TypeError , err : <EOL> self . assertEqual ( str ( err ) , "<STR_LIT>" ) <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) <EOL> def test_sub_known_Values ( self ) : <EOL> known_sub_Values = ( ( '<STR_LIT>' , '<STR_LIT>' , - <NUM_LIT:4> ) , ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:0> ) , ( '<STR_LIT>' , '<STR_LIT>' , - <NUM_LIT> ) , ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT> ) ) <EOL> for q1 , q2 , sum in known_sub_Values : <EOL> x = units . PhysicalQuantity ( q1 ) <EOL> y = units . PhysicalQuantity ( q2 ) <EOL> self . assertEqual ( ( x - y ) . value , sum ) <EOL> self . assertEqual ( ( x - y ) . unit , x . unit ) <EOL> self . assertEqual ( x . __rsub__ ( y ) . value , - sum ) <EOL> self . assertEqual ( x . __rsub__ ( y ) . unit , x . unit ) <EOL> q1 = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> q2 = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> try : <EOL> q1 - q2 <EOL> except TypeError , err : <EOL> self . assertEqual ( str ( err ) , "<STR_LIT>" ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> q1 = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> q2 = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> q3 = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> result = q1 - q2 <EOL> self . assertAlmostEqual ( result . value , <NUM_LIT> , <NUM_LIT:3> ) <EOL> self . assertEqual ( result . unit , q1 . unit ) <EOL> try : <EOL> q3 - q2 <EOL> except TypeError , err : <EOL> self . assertEqual ( str ( err ) , "<STR_LIT>" ) <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) <EOL> def test_mul_known_Values ( self ) : <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> y = <NUM_LIT> <EOL> self . assertEqual ( x * y , units . PhysicalQuantity ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( y * x , units . PhysicalQuantity ( '<STR_LIT>' ) ) <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> y = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> z = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> self . assertEqual ( ( x * y ) . value , <NUM_LIT:1> ) <EOL> self . assertEqual ( ( x * y ) . unit , x . unit * y . unit ) <EOL> self . assertEqual ( str ( x * y ) , '<STR_LIT>' ) <EOL> self . assertEqual ( ( x * z ) , <NUM_LIT:1.0> ) <EOL> self . assertEqual ( type ( x * z ) , float ) <EOL> self . assertEqual ( str ( x * z ) , '<STR_LIT:1.0>' ) <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> y = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> self . assertEqual ( ( x * y ) . value , <NUM_LIT> ) <EOL> self . assertEqual ( ( x * y ) . unit , x . unit * y . unit ) <EOL> self . assertEqual ( str ( x * y ) , '<STR_LIT>' ) <EOL> z = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> try : <EOL> x * z <EOL> except TypeError , err : <EOL> self . assertEqual ( str ( err ) , "<STR_LIT>" ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_div_known_Values ( self ) : <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> y = <NUM_LIT> <EOL> z = <NUM_LIT:1> / <NUM_LIT> <EOL> self . assertAlmostEqual ( ( x / y ) . value , units . PhysicalQuantity ( '<STR_LIT>' % z ) . value , <NUM_LIT:4> ) <EOL> self . assertEqual ( ( x / y ) . unit , units . PhysicalQuantity ( '<STR_LIT>' % z ) . unit ) <EOL> self . assertEqual ( y / x , units . PhysicalQuantity ( '<STR_LIT>' ) ) <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> y = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> quo = <NUM_LIT:1.0> / <NUM_LIT:5> <EOL> self . assertEqual ( ( x / y ) , quo ) <EOL> self . assertEqual ( x . __rdiv__ ( y ) , <NUM_LIT:1> / quo ) <EOL> self . assertEqual ( type ( x / y ) , float ) <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> y = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> quo = <NUM_LIT> / <NUM_LIT:5> <EOL> self . assertEqual ( ( x / y ) . value , quo ) <EOL> self . assertEqual ( x . __rdiv__ ( y ) . value , <NUM_LIT:1> / quo ) <EOL> self . assertEqual ( ( x / y ) . unit , x . unit / y . unit ) <EOL> self . assertEqual ( x . __rdiv__ ( y ) . unit , y . unit / x . unit ) <EOL> self . assertEqual ( str ( x / y ) , '<STR_LIT>' ) <EOL> def test_pow_known_Values ( self ) : <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> self . assertEqual ( ( x ** <NUM_LIT:2> ) . value , <NUM_LIT:5> ** <NUM_LIT:2> ) <EOL> self . assertEqual ( ( x ** <NUM_LIT:2> ) . unit , x . unit ** <NUM_LIT:2> ) <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> y = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> self . assertEqual ( x ** ( <NUM_LIT:1.0> / <NUM_LIT> ) , y ) <EOL> self . assertEqual ( x / y , y ) <EOL> try : <EOL> x ** <NUM_LIT> <EOL> except TypeError , err : <EOL> self . assertEqual ( str ( err ) , "<STR_LIT>" ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> try : <EOL> x ** <NUM_LIT:2> <EOL> except TypeError , err : <EOL> self . assertEqual ( str ( err ) , '<STR_LIT>' ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> try : <EOL> x ** x <EOL> except TypeError , err : <EOL> self . assertEqual ( str ( err ) , '<STR_LIT>' ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> try : <EOL> <NUM_LIT:2> ** x <EOL> except TypeError , err : <EOL> self . assertEqual ( str ( err ) , '<STR_LIT>' ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_abs_known_Values ( self ) : <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> self . assertEqual ( abs ( x ) . unit , x . unit ) <EOL> self . assertEqual ( abs ( x ) . value , <NUM_LIT:5> ) <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> self . assertEqual ( abs ( x ) . unit , x . unit ) <EOL> self . assertEqual ( abs ( x ) . value , <NUM_LIT:5> ) <EOL> def test_pos_known_Values ( self ) : <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> self . assertEqual ( ( + x ) . value , <NUM_LIT:5> ) <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> self . assertEqual ( ( + x ) . value , - <NUM_LIT> ) <EOL> def test_neg_known_Values ( self ) : <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> self . assertEqual ( ( - x ) . value , - <NUM_LIT:5> ) <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> self . assertEqual ( ( - x ) . value , <NUM_LIT> ) <EOL> def test_sqrt_known_Values ( self ) : <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> self . assertEqual ( ( x * x ) . sqrt ( ) , x ) <EOL> def test_sin_cos_tan_known_Values ( self ) : <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> x . sin ( ) <EOL> self . assertEqual ( x . sin ( ) , math . sin ( x . value ) ) <EOL> self . assertEqual ( x . cos ( ) , math . cos ( x . value ) ) <EOL> self . assertEqual ( x . tan ( ) , math . tan ( x . value ) ) <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> try : <EOL> x . sin ( ) <EOL> except TypeError , err : <EOL> self . assertEqual ( str ( err ) , "<STR_LIT>" ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> try : <EOL> x . cos ( ) <EOL> except TypeError , err : <EOL> self . assertEqual ( str ( err ) , "<STR_LIT>" ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> try : <EOL> x . tan ( ) <EOL> except TypeError , err : <EOL> self . assertEqual ( str ( err ) , "<STR_LIT>" ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_nonzero ( self ) : <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> self . assertTrue ( x ) <EOL> def test_convert_to_unit ( self ) : <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> x . convert_to_unit ( '<STR_LIT:m>' ) <EOL> self . assertEqual ( x , units . PhysicalQuantity ( '<STR_LIT>' ) ) <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> try : <EOL> x . convert_to_unit ( '<STR_LIT>' ) <EOL> except TypeError , err : <EOL> self . assertEqual ( str ( err ) , '<STR_LIT>' ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> x . convert_to_unit ( '<STR_LIT>' ) <EOL> self . assertEqual ( x , units . PhysicalQuantity ( '<STR_LIT>' ) ) <EOL> def test_in_units_of ( self ) : <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> y = x . in_units_of ( '<STR_LIT:m>' ) <EOL> self . assertEqual ( y , units . PhysicalQuantity ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( x , units . PhysicalQuantity ( '<STR_LIT>' ) ) <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> try : <EOL> y = x . in_units_of ( '<STR_LIT>' ) <EOL> except TypeError , err : <EOL> self . assertEqual ( str ( err ) , '<STR_LIT>' ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_in_base_units ( self ) : <EOL> x = units . PhysicalQuantity ( <NUM_LIT:1> , '<STR_LIT>' ) <EOL> y = x . in_base_units ( ) <EOL> self . assertEqual ( y , units . PhysicalQuantity ( <NUM_LIT:1> / <NUM_LIT> , '<STR_LIT>' ) ) <EOL> self . assertEqual ( x , units . PhysicalQuantity ( <NUM_LIT:1> , '<STR_LIT>' ) ) <EOL> x = units . PhysicalQuantity ( <NUM_LIT:1> , '<STR_LIT>' ) <EOL> y = x . in_base_units ( ) <EOL> self . assertEqual ( y , units . PhysicalQuantity ( <NUM_LIT> , '<STR_LIT>' ) ) <EOL> x = units . PhysicalQuantity ( <NUM_LIT:1> , '<STR_LIT>' ) <EOL> y = x . in_base_units ( ) <EOL> self . assertEqual ( y , units . PhysicalQuantity ( <NUM_LIT> , '<STR_LIT>' ) ) <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> y = x . in_base_units ( ) <EOL> self . assertEqual ( y , units . PhysicalQuantity ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( x , units . PhysicalQuantity ( '<STR_LIT>' ) ) <EOL> def test__is_compatible__known__Values ( self ) : <EOL> testvals = ( ( '<STR_LIT>' , '<STR_LIT>' , True ) , ( '<STR_LIT>' , '<STR_LIT>' , True ) , ( '<STR_LIT>' , '<STR_LIT>' , False ) ) <EOL> for q1 , q2 , bool in testvals : <EOL> x = units . PhysicalQuantity ( q1 ) <EOL> self . assertEqual ( x . is_compatible ( q2 ) , bool ) <EOL> def test_integers_in_unit_definition ( self ) : <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> self . assertEqual ( x . unit . factor , <NUM_LIT:1> / <NUM_LIT> ) <EOL> self . assertEqual ( x . unit . powers , _get_powers ( time = - <NUM_LIT:1> ) ) <EOL> class test__PhysicalUnit ( unittest . TestCase ) : <EOL> def test_repr_str ( self ) : <EOL> u = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> self . assertEqual ( repr ( u . unit ) , <EOL> "<STR_LIT>" % _get_powers ( time = <NUM_LIT:1> ) ) <EOL> self . assertEqual ( str ( u . unit ) , "<STR_LIT>" ) <EOL> def test_cmp ( self ) : <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> y = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> z = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> self . assertEqual ( cmp ( x , y ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( cmp ( x , x ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( cmp ( y , x ) , - <NUM_LIT:1> ) <EOL> try : <EOL> cmp ( x , z ) <EOL> except TypeError , err : <EOL> self . assertEqual ( str ( err ) , "<STR_LIT>" ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> known__mul__Values = ( ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:5> ) , ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:1> ) , ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:5> ) , ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:7> ) ) <EOL> def test_multiply ( self ) : <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> y = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> z = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> self . assertEqual ( x . unit * y . unit , units . PhysicalUnit ( { '<STR_LIT:s>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:1> } , <NUM_LIT> , <EOL> _get_powers ( mass = <NUM_LIT:1> , time = <NUM_LIT:1> ) , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( y . unit * x . unit , units . PhysicalUnit ( { '<STR_LIT:s>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:1> } , <NUM_LIT> , <EOL> _get_powers ( mass = <NUM_LIT:1> , time = <NUM_LIT:1> ) , <NUM_LIT:0> ) ) <EOL> try : <EOL> x . unit * z . unit <EOL> except TypeError , err : <EOL> self . assertEqual ( str ( err ) , "<STR_LIT>" ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_division ( self ) : <EOL> w = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> y = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> z = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> quo = w . unit / x . unit <EOL> quo2 = x . unit / y . unit <EOL> self . assertEqual ( quo , units . PhysicalUnit ( { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT:g>' : - <NUM_LIT:1> } , <EOL> <NUM_LIT> , _get_powers ( ) , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( quo2 , units . PhysicalUnit ( { '<STR_LIT:s>' : - <NUM_LIT:1> , '<STR_LIT:g>' : <NUM_LIT:1> } , <EOL> <NUM_LIT> , <EOL> _get_powers ( mass = <NUM_LIT:1> , time = - <NUM_LIT:1> ) , <NUM_LIT:0> ) ) <EOL> quo = y . unit / <NUM_LIT> <EOL> self . assertEqual ( quo , units . PhysicalUnit ( { '<STR_LIT:s>' : <NUM_LIT:1> , "<STR_LIT>" : - <NUM_LIT:1> } , <EOL> <NUM_LIT> , _get_powers ( time = <NUM_LIT:1> ) , <NUM_LIT:0> ) ) <EOL> quo = <NUM_LIT> / y . unit <EOL> self . assertEqual ( quo , units . PhysicalUnit ( { '<STR_LIT:s>' : - <NUM_LIT:1> , "<STR_LIT>" : <NUM_LIT:1> } , <NUM_LIT:2> , <EOL> _get_powers ( time = - <NUM_LIT:1> ) , <NUM_LIT:0> ) ) <EOL> try : <EOL> x . unit / z . unit <EOL> except TypeError , err : <EOL> self . assertEqual ( str ( err ) , "<STR_LIT>" ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> known__pow__Values = ( ( '<STR_LIT>' , <NUM_LIT:3> ) , ( '<STR_LIT>' , <NUM_LIT:2> ) , ( '<STR_LIT>' , <NUM_LIT:2> ) ) <EOL> def test_pow ( self ) : <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> y = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> z = x ** <NUM_LIT:3> <EOL> self . assertEqual ( z . unit , units . PhysicalQuantity ( '<STR_LIT>' ) . unit ) <EOL> x = z ** ( <NUM_LIT:1.0> / <NUM_LIT> ) <EOL> self . assertEqual ( x . unit , units . PhysicalQuantity ( '<STR_LIT>' ) . unit ) <EOL> try : <EOL> y ** <NUM_LIT> <EOL> except TypeError , err : <EOL> self . assertEqual ( str ( err ) , '<STR_LIT>' ) <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) <EOL> try : <EOL> x ** <NUM_LIT> <EOL> except TypeError , err : <EOL> self . assertEqual ( str ( err ) , '<STR_LIT>' ) <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) <EOL> try : <EOL> x ** ( <NUM_LIT> / <NUM_LIT> ) <EOL> except TypeError , err : <EOL> self . assertEqual ( str ( err ) , '<STR_LIT>' ) <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) <EOL> known__conversion_factor_to__Values = ( ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:100> ) , ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:1000> ) , ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT> ) ) <EOL> def test_conversion_factor_to ( self ) : <EOL> w = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> y = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> z1 = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> z2 = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> self . assertEqual ( w . unit . conversion_factor_to ( x . unit ) , <NUM_LIT:1> / <NUM_LIT> ) <EOL> try : <EOL> w . unit . conversion_factor_to ( y . unit ) <EOL> except TypeError , err : <EOL> self . assertEqual ( str ( err ) , "<STR_LIT>" ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> self . assertEqual ( z1 . unit . conversion_factor_to ( z2 . unit ) , <NUM_LIT:1.0> ) <EOL> try : <EOL> y . unit . conversion_factor_to ( z2 . unit ) <EOL> except TypeError , err : <EOL> self . assertEqual ( str ( err ) , "<STR_LIT>" ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> known__conversion_tuple_to__Values = ( ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> def test_conversion_tuple_to ( self ) : <EOL> w = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> x = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> y = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> z1 = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> z2 = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> self . assertEqual ( w . unit . conversion_tuple_to ( x . unit ) , ( <NUM_LIT:1> / <NUM_LIT> , <NUM_LIT:0> ) ) <EOL> result = y . unit . conversion_tuple_to ( z1 . unit ) <EOL> self . assertAlmostEqual ( result [ <NUM_LIT:0> ] , <NUM_LIT> , <NUM_LIT:3> ) <EOL> self . assertAlmostEqual ( result [ <NUM_LIT:1> ] , - <NUM_LIT> , <NUM_LIT:3> ) <EOL> try : <EOL> x . unit . conversion_tuple_to ( z1 . unit ) <EOL> except TypeError , err : <EOL> self . assertEqual ( str ( err ) , "<STR_LIT>" ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_name ( self ) : <EOL> x1 = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> x2 = units . PhysicalQuantity ( '<STR_LIT>' ) <EOL> y = <NUM_LIT:1> / x1 <EOL> self . assertEqual ( y . unit . name ( ) , '<STR_LIT>' ) <EOL> y = <NUM_LIT:1> / x1 / x1 <EOL> self . assertEqual ( y . unit . name ( ) , '<STR_LIT>' ) <EOL> y = x1 ** <NUM_LIT:2> <EOL> self . assertEqual ( y . unit . name ( ) , '<STR_LIT>' ) <EOL> y = x2 / ( x1 ** <NUM_LIT:2> ) <EOL> self . assertEqual ( y . unit . name ( ) , '<STR_LIT>' ) <EOL> class test__moduleFunctions ( unittest . TestCase ) : <EOL> def test_add_unit ( self ) : <EOL> try : <EOL> units . add_unit ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> except KeyError , err : <EOL> self . assertEqual ( str ( err ) , "<STR_LIT>" ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> try : <EOL> units . add_offset_unit ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:20> , <NUM_LIT:10> ) <EOL> except KeyError , err : <EOL> self . assertEqual ( str ( err ) , "<STR_LIT>" ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
