Esempio n. 1
0
 def testConstructor_004(self):
     """
   Test assignment of maxPercentage attribute, valid value.
   """
     capacity = CapacityConfig()
     self.failUnlessEqual(None, capacity.maxPercentage)
     capacity.maxPercentage = PercentageQuantity("63.2")
     self.failUnlessEqual(PercentageQuantity("63.2"),
                          capacity.maxPercentage)
Esempio n. 2
0
 def testConstructor_002(self):
     """
   Test constructor with all values filled in, with valid values.
   """
     capacity = CapacityConfig(PercentageQuantity("63.2"),
                               ByteQuantity("2.0", UNIT_KBYTES))
     self.failUnlessEqual(PercentageQuantity("63.2"),
                          capacity.maxPercentage)
     self.failUnlessEqual(ByteQuantity("2.0", UNIT_KBYTES),
                          capacity.minBytes)
Esempio n. 3
0
 def testConstructor_003(self):
     """
   Test assignment of quantity attribute, None value.
   """
     quantity = PercentageQuantity(quantity="1.0")
     self.failUnlessEqual("1.0", quantity.quantity)
     self.failUnlessEqual(1.0, quantity.percentage)
     quantity.quantity = None
     self.failUnlessEqual(None, quantity.quantity)
     self.failUnlessEqual(0.0, quantity.percentage)
Esempio n. 4
0
 def testComparison_002(self):
     """
   Test comparison of two identical objects, all attributes non-None.
   """
     quantity1 = PercentageQuantity("12")
     quantity2 = PercentageQuantity("12")
     self.failUnlessEqual(quantity1, quantity2)
     self.failUnless(quantity1 == quantity2)
     self.failUnless(not quantity1 < quantity2)
     self.failUnless(quantity1 <= quantity2)
     self.failUnless(not quantity1 > quantity2)
     self.failUnless(quantity1 >= quantity2)
     self.failUnless(not quantity1 != quantity2)
Esempio n. 5
0
 def testComparison_004(self):
     """
   Test comparison of two differing objects, quantity differs.
   """
     quantity1 = PercentageQuantity("10")
     quantity2 = PercentageQuantity("12")
     self.failIfEqual(quantity1, quantity2)
     self.failUnless(not quantity1 == quantity2)
     self.failUnless(quantity1 < quantity2)
     self.failUnless(quantity1 <= quantity2)
     self.failUnless(not quantity1 > quantity2)
     self.failUnless(not quantity1 >= quantity2)
     self.failUnless(quantity1 != quantity2)
Esempio n. 6
0
 def testConstructor_004(self):
     """
   Test assignment of quantity attribute, valid values.
   """
     quantity = PercentageQuantity()
     self.failUnlessEqual(None, quantity.quantity)
     self.failUnlessEqual(0.0, quantity.percentage)
     quantity.quantity = "1.0"
     self.failUnlessEqual("1.0", quantity.quantity)
     self.failUnlessEqual(1.0, quantity.percentage)
     quantity.quantity = ".1"
     self.failUnlessEqual(".1", quantity.quantity)
     self.failUnlessEqual(0.1, quantity.percentage)
     quantity.quantity = "12"
     self.failUnlessEqual("12", quantity.quantity)
     self.failUnlessEqual(12.0, quantity.percentage)
     quantity.quantity = "0.5"
     self.failUnlessEqual("0.5", quantity.quantity)
     self.failUnlessEqual(0.5, quantity.percentage)
     quantity.quantity = "0.25E2"
     self.failUnlessEqual("0.25E2", quantity.quantity)
     self.failUnlessEqual(0.25e2, quantity.percentage)
     if hexFloatLiteralAllowed():
         # Some interpreters allow this, some don't
         quantity.quantity = "0x0C"
         self.failUnlessEqual("0x0C", quantity.quantity)
         self.failUnlessEqual(12.0, quantity.percentage)
Esempio n. 7
0
 def testComparison_002(self):
     """
   Test comparison of two identical objects, all attributes non-None.
   """
     capacity1 = CapacityConfig(PercentageQuantity("63.2"),
                                ByteQuantity("1.00", UNIT_MBYTES))
     capacity2 = CapacityConfig(PercentageQuantity("63.2"),
                                ByteQuantity("1.00", UNIT_MBYTES))
     self.failUnlessEqual(capacity1, capacity2)
     self.failUnless(capacity1 == capacity2)
     self.failUnless(not capacity1 < capacity2)
     self.failUnless(capacity1 <= capacity2)
     self.failUnless(not capacity1 > capacity2)
     self.failUnless(capacity1 >= capacity2)
     self.failUnless(not capacity1 != capacity2)
Esempio n. 8
0
 def testComparison_006(self):
     """
   Test comparison of two differing objects, minBytes differs.
   """
     capacity1 = CapacityConfig(PercentageQuantity("63.2"),
                                ByteQuantity("0.5", UNIT_MBYTES))
     capacity2 = CapacityConfig(PercentageQuantity("63.2"),
                                ByteQuantity("1.00", UNIT_MBYTES))
     self.failIfEqual(capacity1, capacity2)
     self.failUnless(not capacity1 == capacity2)
     self.failUnless(capacity1 < capacity2)
     self.failUnless(capacity1 <= capacity2)
     self.failUnless(not capacity1 > capacity2)
     self.failUnless(not capacity1 >= capacity2)
     self.failUnless(capacity1 != capacity2)
Esempio n. 9
0
 def testConstructor_001(self):
     """
   Test constructor with no values filled in.
   """
     quantity = PercentageQuantity()
     self.failUnlessEqual(None, quantity.quantity)
     self.failUnlessEqual(0.0, quantity.percentage)
Esempio n. 10
0
 def testParse_002(self):
     """
   Parse config document that configures max percentage.
   """
     path = self.resources["capacity.conf.2"]
     contents = open(path).read()
     config = LocalConfig(xmlPath=path, validate=False)
     self.failIfEqual(None, config.capacity)
     self.failUnlessEqual(PercentageQuantity("63.2"),
                          config.capacity.maxPercentage)
     self.failUnlessEqual(None, config.capacity.minBytes)
     config = LocalConfig(xmlData=contents, validate=False)
     self.failIfEqual(None, config.capacity)
     self.failUnlessEqual(PercentageQuantity("63.2"),
                          config.capacity.maxPercentage)
     self.failUnlessEqual(None, config.capacity.minBytes)
Esempio n. 11
0
 def testConstructor_002(self):
     """
   Test constructor with all values filled in, with valid values.
   """
     quantity = PercentageQuantity("6")
     self.failUnlessEqual("6", quantity.quantity)
     self.failUnlessEqual(6.0, quantity.percentage)
Esempio n. 12
0
 def testValidate_004(self):
     """
   Test validate on a non-empty capacity section with both max percentage and min bytes filled in.
   """
     config = LocalConfig()
     config.capacity = CapacityConfig(PercentageQuantity("63.2"),
                                      ByteQuantity("1.00", UNIT_MBYTES))
     self.failUnlessRaises(ValueError, config.validate)
Esempio n. 13
0
 def testValidate_005(self):
     """
   Test validate on a non-empty capacity section with only max percentage filled in.
   """
     config = LocalConfig()
     config.capacity = CapacityConfig(
         maxPercentage=PercentageQuantity("63.2"))
     config.validate()
Esempio n. 14
0
 def testConstructor_006(self):
     """
   Test assignment of quantity attribute, invalid value (not a floating point number).
   """
     quantity = PercentageQuantity()
     self.failUnlessEqual(None, quantity.quantity)
     self.failUnlessAssignRaises(ValueError, quantity, "quantity", "blech")
     self.failUnlessEqual(None, quantity.quantity)
Esempio n. 15
0
 def testConstructor_005(self):
     """
   Test assignment of quantity attribute, invalid value (empty).
   """
     quantity = PercentageQuantity()
     self.failUnlessEqual(None, quantity.quantity)
     self.failUnlessAssignRaises(ValueError, quantity, "quantity", "")
     self.failUnlessEqual(None, quantity.quantity)
Esempio n. 16
0
 def testAddConfig_002(self):
     """
   Test with max percentage value set.
   """
     capacity = CapacityConfig(
         maxPercentage=PercentageQuantity("63.29128310980123"))
     config = LocalConfig()
     config.capacity = capacity
     self.validateAddConfig(config)
Esempio n. 17
0
 def testStringFuncs_001(self):
     """
   Just make sure that the string functions don't have errors (i.e. bad variable names).
   """
     obj = PercentageQuantity()
     obj.__repr__()
     obj.__str__()
Esempio n. 18
0
 def testConstructor_008(self):
     """
   Test assignment of quantity attribute, invalid value (larger than 100%).
   """
     quantity = PercentageQuantity()
     self.failUnlessEqual(None, quantity.quantity)
     self.failUnlessAssignRaises(ValueError, quantity, "quantity",
                                 "100.0001")
     self.failUnlessEqual(None, quantity.quantity)
     self.failUnlessAssignRaises(ValueError, quantity, "quantity", "101")
     self.failUnlessEqual(None, quantity.quantity)
     self.failUnlessAssignRaises(ValueError, quantity, "quantity", "1e6")
     self.failUnlessEqual(None, quantity.quantity)
Esempio n. 19
0
 def testComparison_003(self):
     """
   Test comparison of two differing objects, maxPercentage differs (one None).
   """
     capacity1 = CapacityConfig()
     capacity2 = CapacityConfig(maxPercentage=PercentageQuantity("63.2"))
     self.failIfEqual(capacity1, capacity2)
     self.failUnless(not capacity1 == capacity2)
     self.failUnless(capacity1 < capacity2)
     self.failUnless(capacity1 <= capacity2)
     self.failUnless(not capacity1 > capacity2)
     self.failUnless(not capacity1 >= capacity2)
     self.failUnless(capacity1 != capacity2)
Esempio n. 20
0
 def testConstructor_007(self):
     """
   Test assignment of quantity attribute, invalid value (negative number).
   """
     quantity = PercentageQuantity()
     self.failUnlessEqual(None, quantity.quantity)
     self.failUnlessAssignRaises(ValueError, quantity, "quantity", "-3")
     self.failUnlessEqual(None, quantity.quantity)
     self.failUnlessAssignRaises(ValueError, quantity, "quantity", "-6.8")
     self.failUnlessEqual(None, quantity.quantity)
     self.failUnlessAssignRaises(ValueError, quantity, "quantity", "-0.2")
     self.failUnlessEqual(None, quantity.quantity)
     self.failUnlessAssignRaises(ValueError, quantity, "quantity", "-.1")
     self.failUnlessEqual(None, quantity.quantity)