14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Tests for the osutils wrapper.
17
"""Tests for the osutils wrapper."""
27
from bzrlib.errors import BzrBadParameterNotUnicode
26
from bzrlib.errors import BzrBadParameterNotUnicode, InvalidURL
28
27
import bzrlib.osutils as osutils
29
from bzrlib.tests import TestCaseInTempDir, TestCase
28
from bzrlib.tests import TestCaseInTempDir, TestCase, TestSkipped
32
31
class TestOSUtils(TestCaseInTempDir):
150
class TestWin32Funcs(TestCase):
151
"""Test that the _win32 versions of os utilities return appropriate paths."""
153
def test_abspath(self):
154
self.assertEqual('C:/foo', osutils._win32_abspath('C:\\foo'))
155
self.assertEqual('C:/foo', osutils._win32_abspath('C:/foo'))
157
def test_realpath(self):
158
self.assertEqual('C:/foo', osutils._win32_realpath('C:\\foo'))
159
self.assertEqual('C:/foo', osutils._win32_realpath('C:/foo'))
161
def test_pathjoin(self):
162
self.assertEqual('path/to/foo', osutils._win32_pathjoin('path', 'to', 'foo'))
163
self.assertEqual('C:/foo', osutils._win32_pathjoin('path\\to', 'C:\\foo'))
164
self.assertEqual('C:/foo', osutils._win32_pathjoin('path/to', 'C:/foo'))
165
self.assertEqual('path/to/foo', osutils._win32_pathjoin('path/to/', 'foo'))
166
self.assertEqual('/foo', osutils._win32_pathjoin('C:/path/to/', '/foo'))
167
self.assertEqual('/foo', osutils._win32_pathjoin('C:\\path\\to\\', '\\foo'))
169
def test_normpath(self):
170
self.assertEqual('path/to/foo', osutils._win32_normpath(r'path\\from\..\to\.\foo'))
171
self.assertEqual('path/to/foo', osutils._win32_normpath('path//from/../to/./foo'))
173
def test_getcwd(self):
174
self.assertEqual(os.getcwdu().replace('\\', '/'), osutils._win32_getcwd())
177
class TestWin32FuncsDirs(TestCaseInTempDir):
178
"""Test win32 functions that create files."""
180
def test_getcwd(self):
181
# Make sure getcwd can handle unicode filenames
183
os.mkdir(u'B\xe5gfors')
185
raise TestSkipped("Unable to create Unicode filename")
187
os.chdir(u'B\xe5gfors')
188
# TODO: jam 20060427 This will probably fail on Mac OSX because
189
# it will change the normalization of B\xe5gfors
190
# Consider using a different unicode character, or make
191
# osutils.getcwd() renormalize the path.
192
self.assertTrue(osutils._win32_getcwd().endswith(u'/B\xe5gfors'))
194
def test_mkdtemp(self):
195
tmpdir = osutils._win32_mkdtemp(dir='.')
196
self.assertFalse('\\' in tmpdir)
198
def test_rename(self):
206
osutils._win32_rename('b', 'a')
207
self.failUnlessExists('a')
208
self.failIfExists('b')
209
self.assertFileEqual('baz\n', 'a')
151
212
class TestSplitLines(TestCase):
153
214
def test_split_unicode(self):