~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-03-06 06:48:25 UTC
  • mfrom: (4070.8.6 debug-config)
  • Revision ID: pqm@pqm.ubuntu.com-20090306064825-kbpwggw21dygeix6
(mbp) debug_flags configuration option

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Tests for the osutils wrapper."""
18
18
 
19
19
from cStringIO import StringIO
20
20
import errno
21
21
import os
22
 
import re
23
22
import socket
24
23
import stat
25
24
import sys
41
40
        canonical_relpath,
42
41
        )
43
42
from bzrlib.tests import (
 
43
        adapt_tests,
44
44
        Feature,
45
45
        probe_unicode_in_user_encoding,
 
46
        split_suite_by_re,
46
47
        StringIOWrapper,
47
48
        SymlinkFeature,
48
49
        CaseInsCasePresFilenameFeature,
49
50
        TestCase,
50
51
        TestCaseInTempDir,
 
52
        TestScenarioApplier,
51
53
        TestSkipped,
52
54
        )
53
55
from bzrlib.tests.file_utils import (
377
379
class TestPumpFile(TestCase):
378
380
    """Test pumpfile method."""
379
381
    def setUp(self):
380
 
        TestCase.setUp(self)
381
382
        # create a test datablock
382
383
        self.block_size = 512
383
384
        pattern = '0123456789ABCDEF'
881
882
        self.assertEqual(expected_dirblocks[1:],
882
883
            [(dirinfo, [line[0:3] for line in block]) for dirinfo, block in result])
883
884
 
884
 
    def test_walkdirs_os_error(self):
885
 
        # <https://bugs.edge.launchpad.net/bzr/+bug/338653>
886
 
        # Pyrex readdir didn't raise useful messages if it had an error
887
 
        # reading the directory
888
 
        if sys.platform == 'win32':
889
 
            raise tests.TestNotApplicable(
890
 
                "readdir IOError not tested on win32")
891
 
        os.mkdir("test-unreadable")
892
 
        os.chmod("test-unreadable", 0000)
893
 
        # must chmod it back so that it can be removed
894
 
        self.addCleanup(lambda: os.chmod("test-unreadable", 0700))
895
 
        # The error is not raised until the generator is actually evaluated.
896
 
        # (It would be ok if it happened earlier but at the moment it
897
 
        # doesn't.)
898
 
        e = self.assertRaises(OSError, list, osutils._walkdirs_utf8("."))
899
 
        self.assertEquals('./test-unreadable', e.filename)
900
 
        self.assertEquals(errno.EACCES, e.errno)
901
 
        # Ensure the message contains the file name
902
 
        self.assertContainsRe(str(e), "\./test-unreadable")
903
 
 
904
885
    def test__walkdirs_utf8(self):
905
886
        tree = [
906
887
            '.bzr',
1476
1457
        self.assertTrue(-eighteen_hours < offset < eighteen_hours)
1477
1458
 
1478
1459
 
1479
 
class TestSizeShaFile(TestCaseInTempDir):
1480
 
 
1481
 
    def test_sha_empty(self):
1482
 
        self.build_tree_contents([('foo', '')])
1483
 
        expected_sha = osutils.sha_string('')
1484
 
        f = open('foo')
1485
 
        self.addCleanup(f.close)
1486
 
        size, sha = osutils.size_sha_file(f)
1487
 
        self.assertEqual(0, size)
1488
 
        self.assertEqual(expected_sha, sha)
1489
 
 
1490
 
    def test_sha_mixed_endings(self):
1491
 
        text = 'test\r\nwith\nall\rpossible line endings\r\n'
1492
 
        self.build_tree_contents([('foo', text)])
1493
 
        expected_sha = osutils.sha_string(text)
1494
 
        f = open('foo')
1495
 
        self.addCleanup(f.close)
1496
 
        size, sha = osutils.size_sha_file(f)
1497
 
        self.assertEqual(38, size)
1498
 
        self.assertEqual(expected_sha, sha)
1499
 
 
1500
 
 
1501
1460
class TestShaFileByName(TestCaseInTempDir):
1502
1461
 
1503
1462
    def test_sha_empty(self):
1526
1485
            'yyy.xx')
1527
1486
        # test unknown resource
1528
1487
        self.assertRaises(IOError, osutils.resource_string, 'bzrlib', 'yyy.xx')
1529
 
 
1530
 
 
1531
 
class TestReCompile(TestCase):
1532
 
 
1533
 
    def test_re_compile_checked(self):
1534
 
        r = osutils.re_compile_checked(r'A*', re.IGNORECASE)
1535
 
        self.assertTrue(r.match('aaaa'))
1536
 
        self.assertTrue(r.match('aAaA'))
1537
 
 
1538
 
    def test_re_compile_checked_error(self):
1539
 
        # like https://bugs.launchpad.net/bzr/+bug/251352
1540
 
        err = self.assertRaises(
1541
 
            errors.BzrCommandError,
1542
 
            osutils.re_compile_checked, '*', re.IGNORECASE, 'test case')
1543
 
        self.assertEqual(
1544
 
            "Invalid regular expression in test case: '*': "
1545
 
            "nothing to repeat",
1546
 
            str(err))