def testExceptions(self): self.assertRaises(SizeParamsError, Size) self.assertRaises(SizeParamsError, Size, bytes=500, spec="45GB") self.assertRaises(SizeNotPositiveError, Size, bytes=-1) self.assertRaises(SizeNotPositiveError, Size, spec="0") self.assertRaises(SizeNotPositiveError, Size, spec="-1 TB") self.assertRaises(SizeNotPositiveError, Size, spec="-47kb") s = Size(bytes=500) self.assertRaises(SizePlacesError, s.humanReadable, places=0)
def _prefixTestHelper(self, bytes, factor, prefix, abbr): c = bytes * factor s = Size(bytes=c) self.assertEquals(s, c) if prefix: u = "%sbytes" % prefix s = Size(spec="%ld %s" % (bytes, u)) self.assertEquals(s, c) self.assertEquals(s.convertTo(spec=u), bytes) if abbr: u = "%sb" % abbr s = Size(spec="%ld %s" % (bytes, u)) self.assertEquals(s, c) self.assertEquals(s.convertTo(spec=u), bytes) if not prefix and not abbr: s = Size(spec="%ld" % bytes) self.assertEquals(s, c) self.assertEquals(s.convertTo(), bytes)
def testHumanReadable(self): s = Size(bytes=58929971L) self.assertEquals(s.humanReadable(), "58.9 Mb") s = Size(bytes=478360371L) self.assertEquals(s.humanReadable(), "0.48 Gb")