2
2
from test import test_support
5
from posixpath import realpath, abspath, join, dirname, basename, relpath
4
import posixpath, os, sys
5
from posixpath import realpath, abspath, dirname, basename
7
7
# An absolute path to a temporary filename for testing. We can't rely on TESTFN
8
8
# being an absolute path, so we need this.
90
90
self.assertRaises(TypeError, posixpath.isabs)
92
def test_splitdrive(self):
93
self.assertEqual(posixpath.splitdrive("/foo/bar"), ("", "/foo/bar"))
95
self.assertRaises(TypeError, posixpath.splitdrive)
97
92
def test_basename(self):
98
93
self.assertEqual(posixpath.basename("/foo/bar"), "bar")
99
94
self.assertEqual(posixpath.basename("/"), "")
385
380
self.assertEqual(posixpath.normpath("///foo/.//bar//.//..//.//baz"), "/foo/baz")
386
381
self.assertEqual(posixpath.normpath("///..//./foo/.//bar"), "/foo/bar")
383
# Issue 5827: Make sure normpath preserves unicode
384
for path in (u'', u'.', u'/', u'\\', u'///foo/.//bar//'):
385
self.assertTrue(isinstance(posixpath.normpath(path), unicode),
386
'normpath() returned str instead of unicode')
388
388
self.assertRaises(TypeError, posixpath.normpath)
390
390
def test_abspath(self):
391
391
self.assert_("foo" in posixpath.abspath("foo"))
393
# Issue 3426: check that abspath retuns unicode when the arg is unicode
394
# and str when it's str, with both ASCII and non-ASCII cwds
395
saved_cwd = os.getcwd()
398
cwds.append(u'\xe7w\xf0'.encode(sys.getfilesystemencoding()
400
except UnicodeEncodeError:
401
pass # the cwd can't be encoded -- test with ascii cwd only
406
for path in ('', 'foo', 'f\xf2\xf2', '/foo', 'C:\\'):
407
self.assertTrue(isinstance(posixpath.abspath(path), str))
408
for upath in (u'', u'fuu', u'f\xf9\xf9', u'/fuu', u'U:\\'):
409
self.assertTrue(isinstance(posixpath.abspath(upath), unicode))
393
414
self.assertRaises(TypeError, posixpath.abspath)
395
416
def test_realpath(self):