예제 #1
0
파일: size_test.py 프로젝트: jwg4/justbytes
    def testMinValue(self):
        """ Test behavior on min_value parameter. """
        s = Size(9, MiB)
        self.assertEqual(s.components(), (Fraction(9, 1), MiB))
        self.assertEqual(
           s.components(StrConfig(min_value=10)),
           (Fraction(9216, 1), KiB)
        )

        s = Size("0.5", GiB)
        self.assertEqual(
           s.components(StrConfig(min_value=1)),
           (Fraction(512, 1), MiB)
        )
        self.assertEqual(
           s.components(StrConfig(min_value=Decimal("0.1"))),
           (Fraction(1, 2), GiB)
        )
        self.assertEqual(
           s.components(StrConfig(min_value=Decimal(1))),
           (Fraction(512, 1), MiB)
        )

        # when min_value is 10 and single digit on left of decimal, display
        # with smaller unit.
        s = Size('7.18', KiB)
        self.assertEqual(s.components(StrConfig(min_value=10))[1], B)
        s = Size('9.68', TiB)
        self.assertEqual(s.components(StrConfig(min_value=10))[1], GiB)
        s = Size('4.29', MiB)
        self.assertEqual(s.components(StrConfig(min_value=10))[1], KiB)

        # when min value is 100 and two digits on left of decimal
        s = Size('14', MiB)
        self.assertEqual(
           s.components(StrConfig(min_value=100)),
           (Fraction(14 * 1024, 1), KiB)
        )
예제 #2
0
파일: size_test.py 프로젝트: jwg4/justbytes
 def testNegative(self):
     """ Test construction of negative sizes. """
     s = Size(-500, MiB)
     self.assertEqual(s.components(), (Fraction(-500, 1), MiB))
     self.assertEqual(s.convertTo(B), -524288000)
예제 #3
0
파일: size_test.py 프로젝트: jwg4/justbytes
 def testRoundingToBytes(self):
     """ Test that second part is B when rounding to bytes. """
     s = Size(500)
     self.assertEqual(s.components()[1], B)
예제 #4
0
파일: size_test.py 프로젝트: jwg4/justbytes
 def testSIUnits(self):
     """ Test binary_units param. """
     s = Size(1000)
     self.assertEqual(s.components(StrConfig(binary_units=False)), (1, KB))
예제 #5
0
파일: size_test.py 프로젝트: jwg4/justbytes
 def testExceptionValues(self):
     """ Test that exceptions are properly raised on bad params. """
     s = Size(500)
     with self.assertRaises(SizeValueError):
         s.components(StrConfig(min_value=-1))