コード例 #1
0
 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")
コード例 #2
0
    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"
            )
コード例 #3
0
 def tearDown(self):
     unitLib = resource_stream(units.__name__, 'unitLibdefault.ini')
     units.import_library(unitLib)
コード例 #4
0
 def setUp(self):
     unitLib = resource_stream(units.__name__, 'unitLibdefault.ini')
     self.unitlib = units.import_library(unitLib)
コード例 #5
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")
コード例 #6
0
 def tearDown(self):
     unitLib = resource_stream(units.__name__, 'unitLibdefault.ini')
     units.import_library(unitLib)
コード例 #7
0
 def setUp(self):
     unitLib = resource_stream(units.__name__, 'unitLibdefault.ini')
     self.unitlib = units.import_library(unitLib)
コード例 #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")
コード例 #9
0
        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