Ignore:
Timestamp:
11 Nov 2011, 10:02:30 (13 years ago)
Author:
uli
Message:

Add tests for new helper.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/utils/tests/test_helpers.py

    r6502 r7080  
    2727import unittest
    2828import doctest
     29from cStringIO import StringIO
    2930from zope.security.testing import Principal, Participation
    3031from zope.security.management import newInteraction, endInteraction
     
    219220        f2 = open(p2, 'wb').write('Ho!')
    220221        assert helpers.cmp_files(open(p1, 'r'), open(p2, 'r')) is False
     222
     223class FileSizeTestCase(unittest.TestCase):
     224
     225    def setUp(self):
     226        self.workdir = tempfile.mkdtemp()
     227
     228    def tearDown(self):
     229        shutil.rmtree(self.workdir)
     230
     231    def test_real_file(self):
     232        # we can get the size of real files
     233        path = os.path.join(self.workdir, 'sample.txt')
     234        open(path, 'wb').write('My content')
     235        self.assertEqual(
     236            int(helpers.file_size(open(path, 'rb'))), 10)
     237        return
     238
     239    def test_stringio_file(self):
     240        # we can get the size of file-like objects
     241        self.assertEqual(
     242            helpers.file_size(StringIO('my sample content')), 17)
    221243
    222244def test_suite():
     
    230252        CurrentPrincipalTestCase,
    231253        CmpFilesTestCase,
     254        FileSizeTestCase,
    232255        ]:
    233256        suite.addTests(
Note: See TracChangeset for help on using the changeset viewer.