Example #1
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.assertEqual(PercentageQuantity("63.2"), capacity.maxPercentage)
     self.assertEqual(ByteQuantity("2.0", UNIT_KBYTES), capacity.minBytes)
Example #2
0
 def testConstructor_004(self):
     """
     Test assignment of maxPercentage attribute, valid value.
     """
     capacity = CapacityConfig()
     self.assertEqual(None, capacity.maxPercentage)
     capacity.maxPercentage = PercentageQuantity("63.2")
     self.assertEqual(PercentageQuantity("63.2"), capacity.maxPercentage)
Example #3
0
 def testConstructor_003(self):
     """
     Test assignment of quantity attribute, None value.
     """
     quantity = PercentageQuantity(quantity="1.0")
     self.assertEqual("1.0", quantity.quantity)
     self.assertEqual(1.0, quantity.percentage)
     quantity.quantity = None
     self.assertEqual(None, quantity.quantity)
     self.assertEqual(0.0, quantity.percentage)
Example #4
0
 def testComparison_002(self):
     """
     Test comparison of two identical objects, all attributes non-None.
     """
     quantity1 = PercentageQuantity("12")
     quantity2 = PercentageQuantity("12")
     self.assertEqual(quantity1, quantity2)
     self.assertTrue(quantity1 == quantity2)
     self.assertTrue(not quantity1 < quantity2)
     self.assertTrue(quantity1 <= quantity2)
     self.assertTrue(not quantity1 > quantity2)
     self.assertTrue(quantity1 >= quantity2)
     self.assertTrue(not quantity1 != quantity2)
Example #5
0
 def testComparison_004(self):
     """
     Test comparison of two differing objects, quantity differs.
     """
     quantity1 = PercentageQuantity("10")
     quantity2 = PercentageQuantity("12")
     self.assertNotEqual(quantity1, quantity2)
     self.assertTrue(not quantity1 == quantity2)
     self.assertTrue(quantity1 < quantity2)
     self.assertTrue(quantity1 <= quantity2)
     self.assertTrue(not quantity1 > quantity2)
     self.assertTrue(not quantity1 >= quantity2)
     self.assertTrue(quantity1 != quantity2)
Example #6
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.assertEqual(capacity1, capacity2)
     self.assertTrue(capacity1 == capacity2)
     self.assertTrue(not capacity1 < capacity2)
     self.assertTrue(capacity1 <= capacity2)
     self.assertTrue(not capacity1 > capacity2)
     self.assertTrue(capacity1 >= capacity2)
     self.assertTrue(not capacity1 != capacity2)
Example #7
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.assertNotEqual(capacity1, capacity2)
     self.assertTrue(not capacity1 == capacity2)
     self.assertTrue(capacity1 < capacity2)
     self.assertTrue(capacity1 <= capacity2)
     self.assertTrue(not capacity1 > capacity2)
     self.assertTrue(not capacity1 >= capacity2)
     self.assertTrue(capacity1 != capacity2)
Example #8
0
 def testConstructor_001(self):
     """
     Test constructor with no values filled in.
     """
     quantity = PercentageQuantity()
     self.assertEqual(None, quantity.quantity)
     self.assertEqual(0.0, quantity.percentage)
Example #9
0
 def testConstructor_002(self):
     """
     Test constructor with all values filled in, with valid values.
     """
     quantity = PercentageQuantity("6")
     self.assertEqual("6", quantity.quantity)
     self.assertEqual(6.0, quantity.percentage)
Example #10
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.assertRaises(ValueError, config.validate)
Example #11
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()
Example #12
0
 def testConstructor_006(self):
     """
     Test assignment of quantity attribute, invalid value (not a floating point number).
     """
     quantity = PercentageQuantity()
     self.assertEqual(None, quantity.quantity)
     self.failUnlessAssignRaises(ValueError, quantity, "quantity", "blech")
     self.assertEqual(None, quantity.quantity)
Example #13
0
 def testConstructor_005(self):
     """
     Test assignment of quantity attribute, invalid value (empty).
     """
     quantity = PercentageQuantity()
     self.assertEqual(None, quantity.quantity)
     self.failUnlessAssignRaises(ValueError, quantity, "quantity", "")
     self.assertEqual(None, quantity.quantity)
Example #14
0
 def testParse_002(self):
     """
     Parse config document that configures max percentage.
     """
     path = self.resources["capacity.conf.2"]
     with open(path) as f:
         contents = f.read()
     config = LocalConfig(xmlPath=path, validate=False)
     self.assertNotEqual(None, config.capacity)
     self.assertEqual(PercentageQuantity("63.2"),
                      config.capacity.maxPercentage)
     self.assertEqual(None, config.capacity.minBytes)
     config = LocalConfig(xmlData=contents, validate=False)
     self.assertNotEqual(None, config.capacity)
     self.assertEqual(PercentageQuantity("63.2"),
                      config.capacity.maxPercentage)
     self.assertEqual(None, config.capacity.minBytes)
Example #15
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)
Example #16
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__()
Example #17
0
 def testConstructor_008(self):
     """
     Test assignment of quantity attribute, invalid value (larger than 100%).
     """
     quantity = PercentageQuantity()
     self.assertEqual(None, quantity.quantity)
     self.failUnlessAssignRaises(ValueError, quantity, "quantity",
                                 "100.0001")
     self.assertEqual(None, quantity.quantity)
     self.failUnlessAssignRaises(ValueError, quantity, "quantity", "101")
     self.assertEqual(None, quantity.quantity)
     self.failUnlessAssignRaises(ValueError, quantity, "quantity", "1e6")
     self.assertEqual(None, quantity.quantity)
Example #18
0
 def testComparison_003(self):
     """
     Test comparison of two differing objects, maxPercentage differs (one None).
     """
     capacity1 = CapacityConfig()
     capacity2 = CapacityConfig(maxPercentage=PercentageQuantity("63.2"))
     self.assertNotEqual(capacity1, capacity2)
     self.assertTrue(not capacity1 == capacity2)
     self.assertTrue(capacity1 < capacity2)
     self.assertTrue(capacity1 <= capacity2)
     self.assertTrue(not capacity1 > capacity2)
     self.assertTrue(not capacity1 >= capacity2)
     self.assertTrue(capacity1 != capacity2)
Example #19
0
 def testConstructor_007(self):
     """
     Test assignment of quantity attribute, invalid value (negative number).
     """
     quantity = PercentageQuantity()
     self.assertEqual(None, quantity.quantity)
     self.failUnlessAssignRaises(ValueError, quantity, "quantity", "-3")
     self.assertEqual(None, quantity.quantity)
     self.failUnlessAssignRaises(ValueError, quantity, "quantity", "-6.8")
     self.assertEqual(None, quantity.quantity)
     self.failUnlessAssignRaises(ValueError, quantity, "quantity", "-0.2")
     self.assertEqual(None, quantity.quantity)
     self.failUnlessAssignRaises(ValueError, quantity, "quantity", "-.1")
     self.assertEqual(None, quantity.quantity)
Example #20
0
 def testConstructor_004(self):
     """
     Test assignment of quantity attribute, valid values.
     """
     quantity = PercentageQuantity()
     self.assertEqual(None, quantity.quantity)
     self.assertEqual(0.0, quantity.percentage)
     quantity.quantity = "1.0"
     self.assertEqual("1.0", quantity.quantity)
     self.assertEqual(1.0, quantity.percentage)
     quantity.quantity = ".1"
     self.assertEqual(".1", quantity.quantity)
     self.assertEqual(0.1, quantity.percentage)
     quantity.quantity = "12"
     self.assertEqual("12", quantity.quantity)
     self.assertEqual(12.0, quantity.percentage)
     quantity.quantity = "0.5"
     self.assertEqual("0.5", quantity.quantity)
     self.assertEqual(0.5, quantity.percentage)
     quantity.quantity = "0.25E2"
     self.assertEqual("0.25E2", quantity.quantity)
     self.assertEqual(0.25e2, quantity.percentage)