~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils.py

resolve conflicts against trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
103
103
class TestContainsWhitespace(tests.TestCase):
104
104
 
105
105
    def test_contains_whitespace(self):
106
 
        self.failUnless(osutils.contains_whitespace(u' '))
107
 
        self.failUnless(osutils.contains_whitespace(u'hello there'))
108
 
        self.failUnless(osutils.contains_whitespace(u'hellothere\n'))
109
 
        self.failUnless(osutils.contains_whitespace(u'hello\nthere'))
110
 
        self.failUnless(osutils.contains_whitespace(u'hello\rthere'))
111
 
        self.failUnless(osutils.contains_whitespace(u'hello\tthere'))
 
106
        self.assertTrue(osutils.contains_whitespace(u' '))
 
107
        self.assertTrue(osutils.contains_whitespace(u'hello there'))
 
108
        self.assertTrue(osutils.contains_whitespace(u'hellothere\n'))
 
109
        self.assertTrue(osutils.contains_whitespace(u'hello\nthere'))
 
110
        self.assertTrue(osutils.contains_whitespace(u'hello\rthere'))
 
111
        self.assertTrue(osutils.contains_whitespace(u'hello\tthere'))
112
112
 
113
113
        # \xa0 is "Non-breaking-space" which on some python locales thinks it
114
114
        # is whitespace, but we do not.
115
 
        self.failIf(osutils.contains_whitespace(u''))
116
 
        self.failIf(osutils.contains_whitespace(u'hellothere'))
117
 
        self.failIf(osutils.contains_whitespace(u'hello\xa0there'))
 
115
        self.assertFalse(osutils.contains_whitespace(u''))
 
116
        self.assertFalse(osutils.contains_whitespace(u'hellothere'))
 
117
        self.assertFalse(osutils.contains_whitespace(u'hello\xa0there'))
118
118
 
119
119
 
120
120
class TestRename(tests.TestCaseInTempDir):
134
134
        # This should work everywhere
135
135
        self.create_file('a', 'something in a\n')
136
136
        self._fancy_rename('a', 'b')
137
 
        self.failIfExists('a')
138
 
        self.failUnlessExists('b')
 
137
        self.assertPathDoesNotExist('a')
 
138
        self.assertPathExists('b')
139
139
        self.check_file_contents('b', 'something in a\n')
140
140
 
141
141
        self.create_file('a', 'new something in a\n')
148
148
        self.create_file('target', 'data in target\n')
149
149
        self.assertRaises((IOError, OSError), self._fancy_rename,
150
150
                          'missingsource', 'target')
151
 
        self.failUnlessExists('target')
 
151
        self.assertPathExists('target')
152
152
        self.check_file_contents('target', 'data in target\n')
153
153
 
154
154
    def test_fancy_rename_fails_if_source_and_target_missing(self):
159
159
        # Rename should be semi-atomic on all platforms
160
160
        self.create_file('a', 'something in a\n')
161
161
        osutils.rename('a', 'b')
162
 
        self.failIfExists('a')
163
 
        self.failUnlessExists('b')
 
162
        self.assertPathDoesNotExist('a')
 
163
        self.assertPathExists('b')
164
164
        self.check_file_contents('b', 'something in a\n')
165
165
 
166
166
        self.create_file('a', 'new something in a\n')
231
231
            self.assertFalse(osutils.is_inside_or_parent_of_any(dirs, fn))
232
232
 
233
233
 
 
234
class TestLstat(tests.TestCaseInTempDir):
 
235
 
 
236
    def test_lstat_matches_fstat(self):
 
237
        # On Windows, lstat and fstat don't always agree, primarily in the
 
238
        # 'st_ino' and 'st_dev' fields. So we force them to be '0' in our
 
239
        # custom implementation.
 
240
        if sys.platform == 'win32':
 
241
            # We only have special lstat/fstat if we have the extension.
 
242
            # Without it, we may end up re-reading content when we don't have
 
243
            # to, but otherwise it doesn't effect correctness.
 
244
            self.requireFeature(test__walkdirs_win32.win32_readdir_feature)
 
245
        f = open('test-file.txt', 'wb')
 
246
        self.addCleanup(f.close)
 
247
        f.write('some content\n')
 
248
        f.flush()
 
249
        self.assertEqualStat(osutils.fstat(f.fileno()),
 
250
                             osutils.lstat('test-file.txt'))
 
251
 
 
252
 
234
253
class TestRmTree(tests.TestCaseInTempDir):
235
254
 
236
255
    def test_rmtree(self):
248
267
 
249
268
        osutils.rmtree('dir')
250
269
 
251
 
        self.failIfExists('dir/file')
252
 
        self.failIfExists('dir')
 
270
        self.assertPathDoesNotExist('dir/file')
 
271
        self.assertPathDoesNotExist('dir')
253
272
 
254
273
 
255
274
class TestDeleteAny(tests.TestCaseInTempDir):
469
488
        f = file('MixedCaseName', 'w')
470
489
        f.close()
471
490
        actual = osutils.canonical_relpath(self.test_base_dir, 'mixedcasename')
472
 
        self.failUnlessEqual('work/MixedCaseName', actual)
 
491
        self.assertEqual('work/MixedCaseName', actual)
473
492
 
474
493
    def test_canonical_relpath_missing_tail(self):
475
494
        os.mkdir('MixedCaseParent')
476
495
        actual = osutils.canonical_relpath(self.test_base_dir,
477
496
                                           'mixedcaseparent/nochild')
478
 
        self.failUnlessEqual('work/MixedCaseParent/nochild', actual)
 
497
        self.assertEqual('work/MixedCaseParent/nochild', actual)
479
498
 
480
499
 
481
500
class Test_CICPCanonicalRelpath(tests.TestCaseWithTransport):
905
924
        b.close()
906
925
 
907
926
        osutils._win32_rename('b', 'a')
908
 
        self.failUnlessExists('a')
909
 
        self.failIfExists('b')
 
927
        self.assertPathExists('a')
 
928
        self.assertPathDoesNotExist('b')
910
929
        self.assertFileEqual('baz\n', 'a')
911
930
 
912
931
    def test_rename_missing_file(self):
1595
1614
                          ('d', 'source/b', 'target/b'),
1596
1615
                          ('f', 'source/b/c', 'target/b/c'),
1597
1616
                         ], processed_files)
1598
 
        self.failIfExists('target')
 
1617
        self.assertPathDoesNotExist('target')
1599
1618
        if osutils.has_symlinks():
1600
1619
            self.assertEqual([('source/lnk', 'target/lnk')], processed_links)
1601
1620
 
1647
1666
        old = osutils.set_or_unset_env('BZR_TEST_ENV_VAR', None)
1648
1667
        self.assertEqual('foo', old)
1649
1668
        self.assertEqual(None, os.environ.get('BZR_TEST_ENV_VAR'))
1650
 
        self.failIf('BZR_TEST_ENV_VAR' in os.environ)
 
1669
        self.assertFalse('BZR_TEST_ENV_VAR' in os.environ)
1651
1670
 
1652
1671
 
1653
1672
class TestSizeShaFile(tests.TestCaseInTempDir):
1878
1897
        os.symlink(self.target, self.link)
1879
1898
 
1880
1899
    def test_os_readlink_link_encoding(self):
1881
 
        if sys.version_info < (2, 6):
1882
 
            self.assertRaises(UnicodeEncodeError, os.readlink, self.link)
1883
 
        else:
1884
 
            self.assertEquals(self.target,  os.readlink(self.link))
 
1900
        self.assertEquals(self.target,  os.readlink(self.link))
1885
1901
 
1886
1902
    def test_os_readlink_link_decoding(self):
1887
1903
        self.assertEquals(self.target.encode(osutils._fs_enc),