view bitten/tests/slave.py @ 296:1d01273abcb0

* Applied patch by Sven Reimers to fix the `<java:ant>` task on Windows. Closes #69. * The tests for `bitten.slave` left temporary files around. No longer.
author cmlenz
date Wed, 26 Oct 2005 22:05:57 +0000
parents 9d93e622f963
children d4b59f1dc7f1
line wrap: on
line source
# -*- coding: iso8859-1 -*-
#
# Copyright (C) 2005 Christopher Lenz <cmlenz@gmx.de>
# All rights reserved.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
# are also available at http://bitten.cmlenz.net/wiki/License.

import os
import shutil
import tempfile
import unittest
import zipfile

from trac.test import Mock
from bitten.slave import Slave, OrchestrationProfileHandler
from bitten.util import beep


class OrchestrationProfileHandlerTestCase(unittest.TestCase):

    def setUp(self):
        self.work_dir = tempfile.mkdtemp(prefix='bitten_test')
        self.slave = Slave(None, None, work_dir=self.work_dir)
        self.handler = OrchestrationProfileHandler(Mock(session=self.slave))

    def tearDown(self):
        shutil.rmtree(self.work_dir)

    def _create_file(self, *path):
        filename = os.path.join(self.work_dir, *path)
        fd = file(filename, 'w')
        fd.close()
        return filename

    def test_unpack_invalid_zip_1(self):
        """
        Verify handling of `IOError` exceptions when trying to unpack an
        invalid ZIP file.

        The `zipfile` module will actually raise an `IOError` instead of a
        `zipfile.error` here because it'll try to seek past the beginning of
        the file.
        """
        path = self._create_file('invalid.zip')
        zip = file(path, 'w')
        zip.write('INVALID')
        zip.close()
        self.assertRaises(beep.ProtocolError, self.handler.unpack_snapshot, 0,
                          os.path.dirname(path), 'invalid.zip')

    def test_unpack_invalid_zip_2(self):
        """
        Verify handling of `zip.error` exceptions when trying to unpack an
        invalid ZIP file.
        """
        path = self._create_file('invalid.zip')
        zip = file(path, 'w')
        zip.write('INVALIDINVALIDINVALIDINVALIDINVALIDINVALID')
        zip.close()
        self.assertRaises(beep.ProtocolError, self.handler.unpack_snapshot, 0,
                          os.path.dirname(path), 'invalid.zip')

def suite():
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(OrchestrationProfileHandlerTestCase,
                                     'test'))
    return suite

if __name__ == '__main__':
    unittest.main(defaultTest='suite')
Copyright (C) 2012-2017 Edgewall Software