Exemple #1
0
 def testSizeNotAvailable(self):
     from zope.size import DefaultSized
     sized = DefaultSized(object())
     self.assertEqual(sized.sizeForSorting(), (None, None))
     self.assertEqual(sized.sizeForDisplay(), u'not-available')
Exemple #2
0
    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'})
Exemple #3
0
 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')
Exemple #4
0
 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')
Exemple #5
0
    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'})
Exemple #6
0
 def testSizeNotAvailable(self):
     from zope.size import DefaultSized
     sized = DefaultSized(object())
     self.assertEqual(sized.sizeForSorting(), (None, None))
     self.assertEqual(sized.sizeForDisplay(), 'not-available')
Exemple #7
0
 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')
Exemple #8
0
 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')
Exemple #9
0
 def testImplementsISized(self):
     from zope.size import DefaultSized
     sized = DefaultSized(object())
     self.assertTrue(ISized.providedBy(sized))