~ubuntu-branches/ubuntu/lucid/python2.6/lucid

« back to all changes in this revision

Viewing changes to Lib/test/test_posixpath.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2010-03-11 13:30:19 UTC
  • mto: (10.1.13 sid)
  • mto: This revision was merged to the branch mainline in revision 44.
  • Revision ID: james.westby@ubuntu.com-20100311133019-sblbooa3uqrkoe70
Tags: upstream-2.6.5~rc2
ImportĀ upstreamĀ versionĀ 2.6.5~rc2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
import unittest
2
2
from test import test_support
3
3
 
4
 
import posixpath, os
5
 
from posixpath import realpath, abspath, join, dirname, basename, relpath
 
4
import posixpath, os, sys
 
5
from posixpath import realpath, abspath, dirname, basename
6
6
 
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.
89
89
 
90
90
        self.assertRaises(TypeError, posixpath.isabs)
91
91
 
92
 
    def test_splitdrive(self):
93
 
        self.assertEqual(posixpath.splitdrive("/foo/bar"), ("", "/foo/bar"))
94
 
 
95
 
        self.assertRaises(TypeError, posixpath.splitdrive)
96
 
 
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")
387
382
 
 
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')
 
387
 
388
388
        self.assertRaises(TypeError, posixpath.normpath)
389
389
 
390
390
    def test_abspath(self):
391
391
        self.assert_("foo" in posixpath.abspath("foo"))
392
392
 
 
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()
 
396
        cwds = ['cwd']
 
397
        try:
 
398
            cwds.append(u'\xe7w\xf0'.encode(sys.getfilesystemencoding()
 
399
                                            or 'ascii'))
 
400
        except UnicodeEncodeError:
 
401
            pass # the cwd can't be encoded -- test with ascii cwd only
 
402
        for cwd in cwds:
 
403
            try:
 
404
                os.mkdir(cwd)
 
405
                os.chdir(cwd)
 
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))
 
410
            finally:
 
411
                os.chdir(saved_cwd)
 
412
                os.rmdir(cwd)
 
413
 
393
414
        self.assertRaises(TypeError, posixpath.abspath)
394
415
 
395
416
    def test_realpath(self):