def testMinValue(self): """ Test behavior on min_value parameter. """ s = Range(9, MiB) self.assertEqual(s.components(), (Fraction(9, 1), MiB)) self.assertEqual( s.components(ValueConfig(min_value=10)), (Fraction(9216, 1), KiB) ) s = Range("0.5", GiB) self.assertEqual( s.components(ValueConfig(min_value=1)), (Fraction(512, 1), MiB) ) self.assertEqual( s.components(ValueConfig(min_value=Fraction(1, 10))), (Fraction(1, 2), GiB) ) self.assertEqual( s.components(ValueConfig(min_value=1)), (Fraction(512, 1), MiB) ) # when min_value is 10 and single digit on left of decimal, display # with smaller unit. s = Range('7.18', KiB) self.assertEqual(s.components(ValueConfig(min_value=10))[1], B) s = Range('9.68', TiB) self.assertEqual(s.components(ValueConfig(min_value=10))[1], GiB) s = Range('4.29', MiB) self.assertEqual(s.components(ValueConfig(min_value=10))[1], KiB) # when min value is 100 and two digits on left of decimal s = Range('14', MiB) self.assertEqual( s.components(ValueConfig(min_value=100)), (Fraction(14 * 1024, 1), KiB) )
def testNegative(self): """ Test construction of negative sizes. """ s = Range(-500, MiB) self.assertEqual(s.components(), (Fraction(-500, 1), MiB)) self.assertEqual(s.convertTo(B), -524288000)
def testRoundingToBytes(self): """ Test that second part is B when rounding to bytes. """ s = Range(500) self.assertEqual(s.components()[1], B)
def testSIUnits(self): """ Test binary_units param. """ s = Range(1000) self.assertEqual(s.components(ValueConfig(binary_units=False)), (1, KB))
def testExceptionValues(self): """ Test that exceptions are properly raised on bad params. """ s = Range(500) with self.assertRaises(RangeValueError): s.components(ValueConfig(min_value=-1))