def test_importlib(self):
     
     #check to make sure the import fucntion errors if not all required base_units are there
     unitLib_test_bad = resource_stream(units.__name__, 'test//unitLib_test_badbaseunits.ini')
     try:
         units.import_library(unitLib_test_bad)
     except ValueError,err:
         self.assertEqual(str(err),"Not all required base type were present in the config file. missing: ['mass', 'time'], at least ['length', 'mass', 'time', 'temperature', 'angle'] required")
    def test_importlib(self):

        #check to make sure the import fucntion errors if not all required base_units are there
        unitLib_test_bad = resource_stream(
            units.__name__, 'test//unitLib_test_badbaseunits.ini')
        try:
            units.import_library(unitLib_test_bad)
        except ValueError, err:
            self.assertEqual(
                str(err),
                "Not all required base type were present in the config file. missing: ['mass', 'time'], at least ['length', 'mass', 'time', 'temperature', 'angle'] required"
            )
 def tearDown(self):
     unitLib = resource_stream(units.__name__, 'unitLibdefault.ini')
     units.import_library(unitLib)
 def setUp(self):
     unitLib = resource_stream(units.__name__, 'unitLibdefault.ini')
     self.unitlib = units.import_library(unitLib)
        try:
            units.import_library(unitLib_test_bad)
        except ValueError, err:
            self.assertEqual(str(err),
                             "Not all required base type were present in the"
                             " config file. missing: ['mass', 'time'], at least"
                             " ['length', 'mass', 'time', 'temperature',"
                             " 'angle'] required")
        else:
            self.fail("ValueError expected")

        #check to make sure that bad units in the units list cause an error    
        unitLib_test_bad = resource_stream(units.__name__,
                                           'test/unitLib_test_badunit.ini')
        try:
            units.import_library(unitLib_test_bad)
        except ValueError, err:
            self.assertEqual(str(err),
                             "The following units were not defined because"
                             " they could not be resolved as a function of any"
                             " other defined units:['foo']")
        else:
            self.fail("ValueError expected")
            
    def test_update_library(self):
        # Show no existing support.
        x = units.PhysicalQuantity('1m/s')
        try:
            x.convert_to_unit('furlong/fortnight')
        except ValueError, exc:
            self.assertEqual(str(exc), "no unit named 'furlong' is defined")
Exemple #6
0
 def tearDown(self):
     unitLib = resource_stream(units.__name__, 'unitLibdefault.ini')
     units.import_library(unitLib)
Exemple #7
0
 def setUp(self):
     unitLib = resource_stream(units.__name__, 'unitLibdefault.ini')
     self.unitlib = units.import_library(unitLib)
Exemple #8
0
        try:
            units.import_library(unitLib_test_bad)
        except ValueError, err:
            self.assertEqual(str(err),
                             "Not all required base type were present in the"
                             " config file. missing: ['mass', 'time'], at least"
                             " ['length', 'mass', 'time', 'temperature',"
                             " 'angle'] required")
        else:
            self.fail("ValueError expected")

        #check to make sure that bad units in the units list cause an error    
        unitLib_test_bad = resource_stream(units.__name__,
                                           'test/unitLib_test_badunit.ini')
        try:
            units.import_library(unitLib_test_bad)
        except ValueError, err:
            self.assertEqual(str(err),
                             "The following units were not defined because"
                             " they could not be resolved as a function of any"
                             " other defined units:['foo']")
        else:
            self.fail("ValueError expected")
            
    def test_update_library(self):
        # Show no existing support.
        x = units.PhysicalQuantity('1m/s')
        try:
            x.convert_to_unit('furlong/fortnight')
        except ValueError, exc:
            self.assertEqual(str(exc), "no unit named 'furlong' is defined")
        units.import_library(unitLib)
        
    def test_importlib(self):
        
        #check to make sure the import fucntion errors if not all required base_units are there
        unitLib_test_bad = resource_stream(units.__name__, 'test//unitLib_test_badbaseunits.ini')
        try:
            units.import_library(unitLib_test_bad)
        except ValueError,err:
            self.assertEqual(str(err),"Not all required base type were present in the config file. missing: ['mass', 'time'], at least ['length', 'mass', 'time', 'temperature', 'angle'] required")
        except:
            self.fail("ValueError expected")
        #check to make sure that bad units in the units list cause an error    
        unitLib_test_bad = resource_stream(units.__name__, 'test//unitLib_test_badunit.ini')
        try:
            units.import_library(unitLib_test_bad)
        except ValueError,err:
            self.assertEqual(str(err),"The following units were not defined because they could not be resolved as a function of any other defined units:['foo']")
        except:
            self.fail("ValueError expected")
            
        
class test_NumberDict(unittest.TestCase):

    def test__UknownKeyGives0(self):
        """a NumberDict instance should initilize using integer and non-integer indices
        a NumberDict instance should initilize all entries with an initial value of 0"""
        x=units.NumberDict()
        #integer test
        self.assertEqual(x[0],0)
        #string test