Ignore:
Timestamp:
12 Feb 2011, 15:33:43 (14 years ago)
Author:
uli
Message:

Add tests for removeFileOrDirectory. Here we also use unittests
instead of doctests in docstrings, because it would not be very
interesting to developers to see how file removal works. We can tell
that this function removes files and developers will know what that
means even without examples.

The unittest, however, checks that the funtion really removes files
when called.

Test coverage for waeup.sirp.utils.helpers now at 100% :)

File:
1 edited

Legend:

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

    r5737 r5739  
    3333class FakeObject(object):
    3434    implements(IFakeObject)
     35
     36class RemoveFileOrDirectoryTestCase(unittest.TestCase):
     37
     38    def setUp(self):
     39        self.dirpath = tempfile.mkdtemp()
     40        self.filepath = os.path.join(self.dirpath, 'somefile')
     41        self.non_file = os.path.join(self.dirpath, 'nonfile')
     42        open(self.filepath, 'wb').write('Hi!')
     43        return
     44
     45    def tearDown(self):
     46        if os.path.exists(self.dirpath):
     47            shutil.rmtree(self.dirpath)
     48        return
     49
     50    def test_handle_not_existing_path(self):
     51        result = helpers.removeFileOrDirectory(self.non_file)
     52        self.assertTrue(result is None)
     53        return
     54
     55    def test_handle_dir(self):
     56        helpers.removeFileOrDirectory(self.dirpath)
     57        self.assertFalse(
     58            os.path.exists(self.dirpath)
     59            )
     60        return
     61
     62    def test_handle_file(self):
     63        helpers.removeFileOrDirectory(self.filepath)
     64        self.assertFalse(
     65            os.path.exists(self.filepath)
     66            )
     67        return
    3568
    3669class CopyFileSystemTreeTestCase(unittest.TestCase):
     
    117150        FactoryBaseTestCase,
    118151        CopyFileSystemTreeTestCase,
     152        RemoveFileOrDirectoryTestCase,
    119153        ]:
    120154        suite.addTests(
Note: See TracChangeset for help on using the changeset viewer.