def testSizeNotAvailable(self): from zope.size import DefaultSized sized = DefaultSized(object()) self.assertEqual(sized.sizeForSorting(), (None, None)) self.assertEqual(sized.sizeForDisplay(), u'not-available')
def testVariousSizes(self): from zope.size import DefaultSized sized = DefaultSized(DummyObject(0)) self.assertEqual(sized.sizeForSorting(), ('byte', 0)) self.assertEqual(sized.sizeForDisplay(), u'0 KB') sized = DefaultSized(DummyObject(1)) self.assertEqual(sized.sizeForSorting(), ('byte', 1)) self.assertEqual(sized.sizeForDisplay(), u'1 KB') sized = DefaultSized(DummyObject(2048)) self.assertEqual(sized.sizeForSorting(), ('byte', 2048)) self.assertEqual(sized.sizeForDisplay(), u'${size} KB') self.assertEqual(sized.sizeForDisplay().mapping, {'size': '2'}) sized = DefaultSized(DummyObject(2000000)) self.assertEqual(sized.sizeForSorting(), ('byte', 2000000)) self.assertEqual(sized.sizeForDisplay(), u'${size} MB') self.assertEqual(sized.sizeForDisplay().mapping, {'size': '1.91'})
def testSizeWithBytes(self): from zope.size import DefaultSized obj = DummyObject(1023) sized = DefaultSized(obj) self.assertEqual(sized.sizeForSorting(), ('byte', 1023)) self.assertEqual(sized.sizeForDisplay(), u'1 KB')
def testSizeWithNone(self): from zope.size import DefaultSized obj = DummyObject(None) sized = DefaultSized(obj) self.assertEqual(sized.sizeForSorting(), (None, None)) self.assertEqual(sized.sizeForDisplay(), u'not-available')
def testVariousSizes(self): from zope.size import DefaultSized sized = DefaultSized(DummyObject(0)) self.assertEqual(sized.sizeForSorting(), ('byte', 0)) self.assertEqual(sized.sizeForDisplay(), '0 KB') sized = DefaultSized(DummyObject(1)) self.assertEqual(sized.sizeForSorting(), ('byte', 1)) self.assertEqual(sized.sizeForDisplay(), '1 KB') sized = DefaultSized(DummyObject(2048)) self.assertEqual(sized.sizeForSorting(), ('byte', 2048)) self.assertEqual(sized.sizeForDisplay(), '${size} KB') self.assertEqual(sized.sizeForDisplay().mapping, {'size': '2'}) sized = DefaultSized(DummyObject(2000000)) self.assertEqual(sized.sizeForSorting(), ('byte', 2000000)) self.assertEqual(sized.sizeForDisplay(), '${size} MB') self.assertEqual(sized.sizeForDisplay().mapping, {'size': '1.91'})
def testSizeNotAvailable(self): from zope.size import DefaultSized sized = DefaultSized(object()) self.assertEqual(sized.sizeForSorting(), (None, None)) self.assertEqual(sized.sizeForDisplay(), 'not-available')
def testSizeWithNone(self): from zope.size import DefaultSized obj = DummyObject(None) sized = DefaultSized(obj) self.assertEqual(sized.sizeForSorting(), (None, None)) self.assertEqual(sized.sizeForDisplay(), 'not-available')
def testSizeWithBytes(self): from zope.size import DefaultSized obj = DummyObject(1023) sized = DefaultSized(obj) self.assertEqual(sized.sizeForSorting(), ('byte', 1023)) self.assertEqual(sized.sizeForDisplay(), '1 KB')
def testImplementsISized(self): from zope.size import DefaultSized sized = DefaultSized(object()) self.assertTrue(ISized.providedBy(sized))