~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils.py

MergeĀ upstream.

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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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
22
23
import socket
23
24
import stat
24
25
import sys
376
377
class TestPumpFile(TestCase):
377
378
    """Test pumpfile method."""
378
379
    def setUp(self):
 
380
        TestCase.setUp(self)
379
381
        # create a test datablock
380
382
        self.block_size = 512
381
383
        pattern = '0123456789ABCDEF'
1474
1476
        self.assertTrue(-eighteen_hours < offset < eighteen_hours)
1475
1477
 
1476
1478
 
 
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
 
1477
1501
class TestShaFileByName(TestCaseInTempDir):
1478
1502
 
1479
1503
    def test_sha_empty(self):
1502
1526
            'yyy.xx')
1503
1527
        # test unknown resource
1504
1528
        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))