~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils.py

  • Committer: John Arbash Meinel
  • Date: 2006-04-27 17:13:19 UTC
  • mto: This revision was merged to the branch mainline in revision 1752.
  • Revision ID: john@arbash-meinel.com-20060427171319-2ca1ae1bbba4465a
Adding tests for the rest of the _win32 functions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
141
141
        self.assertRaises(InvalidURL, from_url, 'file:///path/to/foo')
142
142
 
143
143
 
 
144
class TestWin32Funcs(TestCase):
 
145
    """Test that the _win32 versions of os utilities return appropriate paths."""
 
146
 
 
147
    def test_abspath(self):
 
148
        self.assertEqual('C:/foo', osutils._win32_abspath('C:\\foo'))
 
149
        self.assertEqual('C:/foo', osutils._win32_abspath('C:/foo'))
 
150
 
 
151
    def test_realpath(self):
 
152
        self.assertEqual('C:/foo', osutils._win32_realpath('C:\\foo'))
 
153
        self.assertEqual('C:/foo', osutils._win32_realpath('C:/foo'))
 
154
 
 
155
    def test_pathjoin(self):
 
156
        self.assertEqual('path/to/foo', osutils._win32_pathjoin('path', 'to', 'foo'))
 
157
        self.assertEqual('C:/foo', osutils._win32_pathjoin('path\\to', 'C:\\foo'))
 
158
        self.assertEqual('C:/foo', osutils._win32_pathjoin('path/to', 'C:/foo'))
 
159
        self.assertEqual('path/to/foo', osutils._win32_pathjoin('path/to/', 'foo'))
 
160
        self.assertEqual('/foo', osutils._win32_pathjoin('C:/path/to/', '/foo'))
 
161
        self.assertEqual('/foo', osutils._win32_pathjoin('C:\\path\\to\\', '\\foo'))
 
162
 
 
163
    def test_normpath(self):
 
164
        self.assertEqual('path/to/foo', osutils._win32_normpath(r'path\\from\..\to\.\foo'))
 
165
        self.assertEqual('path/to/foo', osutils._win32_normpath('path//from/../to/./foo'))
 
166
 
 
167
    def test_getcwd(self):
 
168
        self.assertEqual(os.getcwdu().replace('\\', '/'), osutils._win32_getcwd())
 
169
 
 
170
 
 
171
class TestWin32FuncsDirs(TestCaseInTempDir):
 
172
    """Test win32 functions that create files."""
 
173
    
 
174
    def test_getcwd(self):
 
175
        # Make sure getcwd can handle unicode filenames
 
176
        try:
 
177
            os.mkdir(u'B\xe5gfors')
 
178
        except UnicodeError:
 
179
            raise TestSkipped("Unable to create Unicode filename")
 
180
 
 
181
        os.chdir(u'B\xe5gfors')
 
182
        # TODO: jam 20060427 This will probably fail on Mac OSX because
 
183
        #       it will change the normalization of B\xe5gfors
 
184
        #       Consider using a different unicode character, or make
 
185
        #       osutils.getcwd() renormalize the path.
 
186
        self.assertTrue(osutils._win32_getcwd().endswith(u'/B\xe5gfors'))
 
187
 
 
188
    def test_mkdtemp(self):
 
189
        tmpdir = osutils._win32_mkdtemp(dir='.')
 
190
        self.assertFalse('\\' in tmpdir)
 
191
 
 
192
    def test_rename(self):
 
193
        a = open('a', 'wb')
 
194
        a.write('foo\n')
 
195
        a.close()
 
196
        b = open('b', 'wb')
 
197
        b.write('baz\n')
 
198
        b.close()
 
199
 
 
200
        osutils._win32_rename('b', 'a')
 
201
        self.failUnlessExists('a')
 
202
        self.failIfExists('b')
 
203
        self.assertFileEqual('baz\n', 'a')
 
204
 
 
205
 
144
206
class TestSplitLines(TestCase):
145
207
 
146
208
    def test_split_unicode(self):