[Python-checkins] python/nondist/sandbox/path path.py, 1.1, 1.2 test_path.py, 1.1, 1.2

birkenfeld@users.sourceforge.net birkenfeld at users.sourceforge.net
Sat Jul 23 11:27:42 CEST 2005


Update of /cvsroot/python/python/nondist/sandbox/path
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18577

Modified Files:
	path.py test_path.py 
Log Message:
Path inherits from str or unicode again.



Index: path.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/path/path.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- path.py	18 Jul 2005 12:09:26 -0000	1.1
+++ path.py	23 Jul 2005 09:27:40 -0000	1.2
@@ -38,14 +38,12 @@
 if hasattr(file, 'newlines'):
     _textmode = 'U'
 
-# helper function: if given string/unicode, return it
-#                  if given path, return path string
-def _strpath(thing):
-    if isinstance(thing, Path):
-        return thing._p
-    return thing
+if os.path.supports_unicode_filenames:
+    _base = unicode
+else:
+    _base = str
 
-class Path(object):
+class Path(_base):
     """ Represents a filesystem path.
 
     Path is an immutable object.
@@ -56,35 +54,40 @@
 
     # --- Special Python methods.
 
-    def __init__(self, path=os.curdir):
+    def __new__(typ, *args):
         """ Initialize a Path instance.
 
-        The path argument can be either a string or an existing Path object.
+        The argument can be either a string or an existing Path object.
         """
-        if isinstance(path, Path):
-            self._p = path._p
-        else:
-            self._p = path
+        if not args:
+            return Path(os.curdir)
+        return _base.__new__(typ, *args)
 
     def __repr__(self):
-        return 'Path(%s)' % repr(self._p)
+        return 'Path(%s)' % repr(_base(self))
 
     def __str__(self):
-        return str(self._p)
+        if _base is unicode:
+            return str(self[:])
+        else:
+            return self[:]
+
+    def __unicode__(self):
+        if _base is unicode:
+            return self[:]
+        else:
+            return unicode(self[:])
 
     # Adding path and string yields a path
+    # Caution: this is not a join!
     def __add__(self, other):
-        if isinstance(other, (str, unicode)):
-            return Path(self._p + other)
-        elif isinstance(other, Path):
-            return Path(self._p + other._p)
+        if isinstance(other, basestring):
+            return Path(_base(self) + other)
         return NotImplemented
 
     def __radd__(self, other):
-        if isinstance(other, (str, unicode)):
-            return Path(other + self._p)
-        elif isinstance(other, Path):
-            return Path(other._p + self._p)
+        if isinstance(other, basestring):
+            return Path(other + _base(self))
         return NotImplemented
 
     # The / joins paths
@@ -95,32 +98,28 @@
     
     # Rich comparison
     def __eq__(self, other):
-        return isinstance(other, Path) and (self._p == other._p)
+        return isinstance(other, Path) and _base.__eq__(self, other)
     
     def __ne__(self, other):
-        return (not isinstance(other, Path)) or (self._p != other._p)
+        return (not isinstance(other, Path)) or _base.__ne__(self, other)
 
     def __lt__(self, other):
         if isinstance(other, Path):
-            return self._p < other._p
+            return _base.__lt__(self, other)
         return NotImplemented
     def __le__(self, other):
         if isinstance(other, Path):
-            return self._p <= other._p
+            return _base.__le__(self, other)
         return NotImplemented
     def __gt__(self, other):
         if isinstance(other, Path):
-            return self._p > other._p
+            return _base.__gt__(self, other)
         return NotImplemented
     def __ge__(self, other):
         if isinstance(other, Path):
-            return self._p >= other._p
+            return _base.__ge__(self, other)
         return NotImplemented
 
-    # Hash like strings
-    def __hash__(self):
-        return hash(self._p) + 1
-
     # Alternative constructor.
     
     @staticmethod
@@ -132,30 +131,27 @@
             return Path(os.getcwd())
 
 
-    # --- Operations which yield strings
+    # --- Operations which return strings
+
+    basename = property(
+        os.path.basename, None, None,
+        """ The name of this file or directory without the full path.
+
+        For example, path('/usr/local/lib/libpython.so').basename == 'libpython.so'
+        """)
 
-    def _get_basename(self):
-        return os.path.basename(self._p)
-    
     def _get_namebase(self):
         base, ext = os.path.splitext(self.basename)
         return base
 
     def _get_ext(self):
-        f, ext = os.path.splitext(self._p)
+        f, ext = os.path.splitext(self)
         return ext
 
     def _get_drive(self):
-        drive, r = os.path.splitdrive(self._p)
+        drive, r = os.path.splitdrive(self)
         return drive
 
-    basename = property(
-        _get_basename, None, None,
-        """ The name of this file or directory without the full path.
-
-        For example, path('/usr/local/lib/libpython.so').basename == 'libpython.so'
-        """)
-
     namebase = property(
         _get_namebase, None, None,
         """ The same as Path.basename, but with one file extension stripped off.
@@ -174,25 +170,25 @@
         This is always empty on systems that don't use drive specifiers.
         """)
 
-    # --- Operations which yield Path objects
+    # --- Operations which return Path objects
 
     def abspath(self):
-        return Path(os.path.abspath(self._p))
+        return Path(os.path.abspath(self))
     
     def normcase(self):
-        return Path(os.path.normcase(self._p))
+        return Path(os.path.normcase(self))
     
     def normpath(self):
-        return Path(os.path.normpath(self._p))
+        return Path(os.path.normpath(self))
     
     def realpath(self):
-        return Path(os.path.realpath(self._p))
+        return Path(os.path.realpath(self))
     
     def expanduser(self):
-        return Path(os.path.expanduser(self._p))
+        return Path(os.path.expanduser(self))
     
     def expandvars(self):
-        return Path(os.path.expandvars(self._p))
+        return Path(os.path.expandvars(self))
     
     def expand(self):
         """ Clean up a filename by calling expandvars(),
@@ -204,7 +200,7 @@
         return self.expandvars().expanduser().normpath()
 
     def _get_directory(self):
-        return Path(os.path.dirname(self._p))
+        return Path(os.path.dirname(self))
 
     directory = property(
         _get_directory, None, None,
@@ -221,11 +217,11 @@
         """
         return self.splitext()[0]
 
-    # --- Operations which yield Paths and strings
+    # --- Operations which return Paths and strings
     
     def splitpath(self):
         """ p.splitpath() -> Return (p.directory, p.basename). """
-        parent, child = os.path.split(self._p)
+        parent, child = os.path.split(self)
         return Path(parent), child
 
     def splitdrive(self):
@@ -235,7 +231,7 @@
         no drive specifier, p.drive is empty, so the return value
         is simply (Path(''), p).  This is always the case on Unix.
         """
-        drive, rel = os.path.splitdrive(self._p)
+        drive, rel = os.path.splitdrive(self)
         return Path(drive), rel
 
     def splitext(self):
@@ -247,16 +243,16 @@
         The extension is everything from '.' to the end of the
         last path segment.
         """
-        filename, ext = os.path.splitext(self._p)
+        filename, ext = os.path.splitext(self)
         return Path(filename), ext
 
     if hasattr(os.path, 'splitunc'):
         def splitunc(self):
-            unc, rest = os.path.splitunc(self._p)
+            unc, rest = os.path.splitunc(self)
             return Path(unc), rest
 
         def _get_uncshare(self):
-            unc, r = os.path.splitunc(self._p)
+            unc, r = os.path.splitunc(self)
             return Path(unc)
 
         uncshare = property(
@@ -275,7 +271,9 @@
         character (os.sep) if needed.  Returns a new path
         object.
         """
-        return Path(os.path.join(self._p, *map(str, args)))
+        return Path(os.path.join(self, *map(_base, args)))
+
+    joinpath = joinwith
 
     def parts(self):
         """ Return a list of the path components in this path.
@@ -346,7 +344,7 @@
     # --- Listing, searching, walking, and matching
 
     def listdir(self):
-        return [Path(p) for p in os.listdir(self._p)]
+        return [Path(p) for p in os.listdir(self)]
     
     def children(self, pattern=None):
         """ D.children() -> List of items in this directory,
@@ -360,7 +358,7 @@
         With the optional 'pattern' argument, this only lists
         items whose names match the given pattern.
         """
-        names = os.listdir(self._p)
+        names = os.listdir(self)
         if pattern is not None:
             names = fnmatch.filter(names, pattern)
         return [self / child for child in names]
@@ -454,16 +452,16 @@
         For example, path('/users').glob('*/bin/*') returns a list
         of all the files users have in their bin directories.
         """
-        return map(Path, glob.glob((self / pattern)._p))
+        return map(Path, glob.glob(self / pattern))
 
 
     # --- Reading or writing an entire file at once.
 
     def open(self, mode='r'):
         """ Open this file.  Return a file object. """
-        return file(self._p, mode)
+        return file(self, mode)
 
-    def get_file_bytes(self):
+    def read_file_bytes(self):
         """ Open this file, read all bytes, return them as a string. """
         f = self.open('rb')
         try:
@@ -487,7 +485,7 @@
         finally:
             f.close()
 
-    def get_file_text(self, encoding=None, errors='strict'):
+    def read_file_text(self, encoding=None, errors='strict'):
         """ Open this file, read it in, return the content as a string.
 
         This uses 'U' mode in Python 2.3 and later, so '\r\n' and '\r'
@@ -511,7 +509,7 @@
                 f.close()
         else:
             # Unicode
-            f = codecs.open(self._p, 'r', encoding, errors)
+            f = codecs.open(self, 'r', encoding, errors)
             # (Note - Can't use 'U' mode here, since codecs.open
             # doesn't support 'U' mode, even in Python 2.3.)
             try:
@@ -613,7 +611,7 @@
 
         self.write_file_bytes(bytes, append)
 
-    def get_file_lines(self, encoding=None, errors='strict', retain=True):
+    def read_file_lines(self, encoding=None, errors='strict', retain=True):
         """ Open this file, read all lines, return them in a list.
 
         Optional arguments:
@@ -637,7 +635,7 @@
             finally:
                 f.close()
         else:
-            return self.get_file_text(encoding, errors).splitlines(retain)
+            return self.read_file_text(encoding, errors).splitlines(retain)
 
     def write_file_lines(self, lines, encoding=None, errors='strict',
                          linesep=os.linesep, append=False):
@@ -707,40 +705,27 @@
 
     # --- Methods for querying the filesystem.
 
-    def exists(self):
-        return os.path.exists(self._p)
-    
-    def isabs(self):
-        return os.path.isabs(self._p)
+    exists  = os.path.exists
+    isabs   = os.path.isabs
+    isdir   = os.path.isdir
+    isfile  = os.path.isfile
+    islink  = os.path.islink
+    ismount = os.path.ismount
     
-    def isdir(self):
-        return os.path.isdir(self._p)
-
-    def isfile(self):
-        return os.path.isfile(self._p)
-
-    def islink(self):
-        return os.path.islink(self._p)
-
-    def ismount(self):
-        return os.path.ismount(self._p)
-
     if hasattr(os.path, 'samefile'):
-        def samefile(self):
-            return os.path.samefile(self._p)
+        samefile = os.path.samefile
 
     def atime(self):
-        return os.path.getatime(self._p)
+        return os.path.getatime(self)
     
     def mtime(self):
-        return os.path.getmtime(self._p)
+        return os.path.getmtime(self)
 
     if hasattr(os.path, 'getctime'):
         def ctime(self):
-            return os.path.getctime(self._p)
+            return os.path.getctime(self)
 
-    def getsize(self):
-        return os.path.getsize(self._p)
+    getsize = os.path.getsize
 
     if hasattr(os, 'access'):
         def access(self, mode):
@@ -748,59 +733,58 @@
 
             mode - One of the constants os.F_OK, os.R_OK, os.W_OK, os.X_OK
             """
-            return os.access(self._p, mode)
+            return os.access(self, mode)
 
     def stat(self):
         """ Perform a stat() system call on this path. """
-        return os.stat(self._p)
+        return os.stat(self)
 
     def lstat(self):
         """ Like path.stat(), but do not follow symbolic links. """
-        return os.lstat(self._p)
+        return os.lstat(self)
 
     if hasattr(os, 'statvfs'):
         def statvfs(self):
             """ Perform a statvfs() system call on this path. """
-            return os.statvfs(self._p)
+            return os.statvfs(self)
 
     if hasattr(os, 'pathconf'):
         def pathconf(self, name):
-            return os.pathconf(self._p, name)
-
+            return os.pathconf(self, name)
 
     # --- Modifying operations on files and directories
 
     def utime(self, times):
         """ Set the access and modified times of this file. """
-        os.utime(self._p, times)
+        os.utime(self, times)
 
     def chmod(self, mode):
-        os.chmod(self._p, mode)
+        os.chmod(self, mode)
 
     if hasattr(os, 'chown'):
         def chown(self, uid, gid):
-            os.chown(self._p, uid, gid)
+            os.chown(self, uid, gid)
 
     def rename(self, new):
-        os.rename(self._p, _strpath(new))
+        os.rename(self, new)
 
     def renames(self, new):
-        os.renames(self._p, _strpath(new))
+        os.renames(self, new)
 
 
     # --- Create/delete operations on directories
 
     def mkdir(self, mode=0777):
-        os.mkdir(self._p, mode)
+        os.mkdir(self, mode)
 
     def makedirs(self, mode=0777):
-        os.makedirs(self._p, mode)
+        os.makedirs(self, mode)
 
     def rmdir(self):
-        os.rmdir(self._p)
+        os.rmdir(self)
 
     def removedirs(self):
-        os.removedirs(self._p)
+        os.removedirs(self)
 
 
     # --- Modifying operations on files
@@ -816,15 +800,15 @@
             mode = os.umask(0)
             os.umask(mode)
             mode = mode ^ 0777
-        fd = os.open(self._p, os.O_WRONLY | os.O_CREAT, mode)
+        fd = os.open(self, os.O_WRONLY | os.O_CREAT, mode)
         os.close(fd)
         self.utime(None)
-
+    
     def remove(self):
-        os.remove(self._p)
+        os.remove(self)
 
     def unlink(self):
-        os.unlink(self._p)
+        os.unlink(self)
 
 
     # --- Links
@@ -832,12 +816,12 @@
     if hasattr(os, 'link'):
         def link(self, newpath):
             """ Create a hard link at 'newpath', pointing to this file. """
-            os.link(self._p, _strpath(newpath))
+            os.link(self, newpath)
 
     if hasattr(os, 'symlink'):
         def symlink(self, newlink):
             """ Create a symbolic link at 'newlink', pointing here. """
-            os.symlink(self._p, _strpath(newlink))
+            os.symlink(self, newlink)
 
     if hasattr(os, 'readlink'):
         def readlink(self):
@@ -845,7 +829,7 @@
 
             The result may be an absolute or a relative path.
             """
-            return Path(os.readlink(self._p))
+            return Path(os.readlink(self))
 
         def readlinkabs(self):
             """ Return the path to which this symbolic link points.
@@ -858,39 +842,25 @@
             else:
                 return (self.directory / p).abspath()
 
-    # --- High-level shutils functions
-
-    def copyfile(self, dst):
-        return shutil.copyfile(self._p, _strpath(dst))
-
-    def copymode(self, dst):
-        return shutil.copymode(self._p, _strpath(dst))
-
-    def copystat(self, dst):
-        return shutil.copystat(self._p, _strpath(dst))
-
-    def copy(self, dst):
-        return shutil.copy(self._p, _strpath(dst))
-
-    def copy2(self, dst):
-        return shutil.copy2(self._p, _strpath(dst))
-
-    def copytree(self, dst, symlinks=False):
-        return shutil.copytree(self._p, _strpath(dst), symlinks)
-
-    def rmtree(self, ignore_errors=False, onerror=None):
-        return shutil.rmtree(self._p, ignore_errors, onerror)
+    # --- High-level functions from shutil
 
-    def move(self, dst):
-        return shutil.move(self._p, _strpath(dst))
+    copyfile = shutil.copyfile
+    copymode = shutil.copymode
+    copystat = shutil.copystat
+    copy = shutil.copy
+    copy2 = shutil.copy2
+    copytree = shutil.copytree
+    if hasattr(shutil, 'move'):
+        move = shutil.move
+    rmtree = shutil.rmtree
     
     # --- Special stuff from os
 
     if hasattr(os, 'chroot'):
         def chroot(self):
-            os.chroot(self._p)
+            os.chroot(self)
 
     if hasattr(os, 'startfile'):
         def startfile(self):
-            os.startfile(self._p)
+            os.startfile(self)
 

Index: test_path.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/path/test_path.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- test_path.py	18 Jul 2005 12:09:26 -0000	1.1
+++ test_path.py	23 Jul 2005 09:27:40 -0000	1.2
@@ -21,14 +21,15 @@
 import codecs, os, random, shutil, tempfile, time
 from path import Path
 
+
 def p(**choices):
     """ Choose a value from several possible values, based on os.name """
-    return Path(choices[os.name])
+    return choices[os.name]
 
 class BasicTestCase(unittest.TestCase):
     def testRelpath(self):
-        root = p(nt='C:\\', posix='/')
-        
+        root = Path(p(nt='C:\\',
+                      posix='/'))
         foo = root / 'foo'
         quux =        foo / 'quux'
         bar =         foo / 'bar'
@@ -57,34 +58,59 @@
             d = Path('D:\\')
             self.assertEqual(d.relpathto(boz), boz)
 
+    ## this isn't going to work cause Paths won't compare
+    ## with ordinary strings
+    '''
+    def testStringCompatibility(self):
+        """ Test compatibility with ordinary strings. """
+        #x = Path('xyzzy')
+        #self.assertEqual(x, 'xyzzy')
+        #self.assertEqual(x, u'xyzzy')
+
+        # sorting
+        items = [Path('fhj'),
+                 Path('fgh'),
+                 'E',
+                 Path('d'),
+                 'A',
+                 Path('B'),
+                 'c']
+        items.sort()
+        self.assert_(items == ['A', 'B', 'E', 'c', 'd', 'fgh', 'fhj'])
+    '''
+
     def testProperties(self):
         # Create sample Path object.
         f = p(nt='C:\\Program Files\\Python\\Lib\\xyzzy.py',
               posix='/usr/local/python/lib/xyzzy.py')
+        f = Path(f)
 
         # .directory
-        self.assertEqual(f.directory, p(nt='C:\\Program Files\\Python\\Lib',
-                                     posix='/usr/local/python/lib'))
+        self.assertEqual(f.directory, Path(p(nt='C:\\Program Files\\Python\\Lib',
+                                             posix='/usr/local/python/lib')))
 
         # .basename
         self.assertEqual(f.basename, 'xyzzy.py')
-        self.assertEqual(f.directory.basename, str(p(nt='Lib', posix='lib')))
+        self.assertEqual(f.directory.basename, p(nt='Lib', posix='lib'))
 
         # .ext
         self.assertEqual(f.ext, '.py')
         self.assertEqual(f.directory.ext, '')
 
         # .drive
-        self.assertEqual(f.drive, str(p(nt='C:', posix='')))
+        self.assertEqual(f.drive, p(nt='C:', posix=''))
 
     def testMethods(self):
         # .abspath()
         self.assertEqual(Path().abspath(), Path.cwd())
 
-        # .getcwd()
+        # .cwd()
         cwd = Path.cwd()
         self.assert_(isinstance(cwd, Path))
-        self.assertEqual(cwd, Path.cwd())
+        if os.path.supports_unicode_filenames:
+            self.assertEqual(unicode(cwd), os.getcwdu())
+        else:
+            self.assertEqual(str(cwd), os.getcwd())
 
     def testUNC(self):
         if hasattr(os.path, 'splitunc'):
@@ -126,12 +152,12 @@
                 ct = f.ctime()
                 self.assert_(t0 <= ct <= t1)
 
-            time.sleep(4)
-            fobj = f.open('ab')
+            time.sleep(5)
+            fobj = file(f, 'ab')
             fobj.write('some bytes')
             fobj.close()
 
-            time.sleep(4)
+            time.sleep(5)
             t2 = time.time() - 3
             f.touch()
             t3 = time.time() + 3
@@ -161,12 +187,12 @@
         
         f = 'testfile.txt'
         af = d / f
-        self.assertEqual(str(af), os.path.join(str(d), f))
+        self.assertEqual(af, os.path.join(d, f))
         af.touch()
         try:
             self.assert_(af.exists())
 
-            self.assertEqual(d.listdir(), [Path(f)])
+            self.assertEqual(d.children(), [af])
 
             # .glob()
             self.assertEqual(d.glob('testfile.txt'), [af])
@@ -182,7 +208,7 @@
         # Try a test with 20 files
         files = [d / ('%d.txt' % i) for i in range(20)]
         for f in files:
-            fobj = f.open('w')
+            fobj = file(f, 'w')
             fobj.write('some text\n')
             fobj.close()
         try:
@@ -224,7 +250,7 @@
             self.failIf(foo.exists())
             self.assert_(d.exists())
         finally:
-            os.remove(str(tempf))
+            os.remove(tempf)
 
     def assertSetsEqual(self, a, b):
         ad = {}
@@ -253,20 +279,20 @@
         testA.mkdir()
         testB.mkdir()
 
-        f = testFile.open('w')
+        f = open(testFile, 'w')
         f.write('x' * 10000)
         f.close()
 
         # Test simple file copying.
         testFile.copyfile(testCopy)
         self.assert_(testCopy.isfile())
-        self.assert_(testFile.get_file_bytes() == testCopy.get_file_bytes())
+        self.assert_(testFile.read_file_bytes() == testCopy.read_file_bytes())
 
         # Test copying into a directory.
         testCopy2 = testA / testFile.basename
         testFile.copy(testA)
         self.assert_(testCopy2.isfile())
-        self.assert_(testFile.get_file_bytes() == testCopy2.get_file_bytes())
+        self.assert_(testFile.read_file_bytes() == testCopy2.read_file_bytes())
 
         # Make a link for the next test to use.
         if hasattr(os, 'symlink'):
@@ -375,16 +401,16 @@
                 u'hanging']
 
             # write bytes manually to file
-            f = codecs.open(str(p), 'w', enc)
+            f = codecs.open(p, 'w', enc)
             f.write(given)
             f.close()
 
-            # test all 3 path read-fully functions, including
-            # Path.lines() in unicode mode.
-            self.assertEqual(p.get_file_bytes(), given.encode(enc))
-            self.assertEqual(p.get_file_text(enc), clean)
-            self.assertEqual(p.get_file_lines(enc), expectedLines)
-            self.assertEqual(p.get_file_lines(enc, retain=False), expectedLines2)
+            # test all 3 Path read-fully functions, including
+            # Path.read_file_lines() in unicode mode.
+            self.assertEqual(p.read_file_bytes(), given.encode(enc))
+            self.assertEqual(p.read_file_text(enc), clean)
+            self.assertEqual(p.read_file_lines(enc), expectedLines)
+            self.assertEqual(p.read_file_lines(enc, retain=False), expectedLines2)
 
             # If this is UTF-16, that's enough.
             # The rest of these will unfortunately fail because append=True mode
@@ -393,7 +419,7 @@
             if enc == 'UTF-16':
                 return
 
-            # Write Unicode to file using Path.write_text().
+            # Write Unicode to file using Path.write_file_text().
             cleanNoHanging = clean + u'\n'  # This test doesn't work with a hanging line.
             p.write_file_text(cleanNoHanging, enc)
             p.write_file_text(cleanNoHanging, enc, append=True)
@@ -401,17 +427,17 @@
             expectedBytes = 2 * cleanNoHanging.replace('\n', os.linesep).encode(enc)
             expectedLinesNoHanging = expectedLines[:]
             expectedLinesNoHanging[-1] += '\n'
-            self.assertEqual(p.get_file_bytes(), expectedBytes)
-            self.assertEqual(p.get_file_text(enc), 2 * cleanNoHanging)
-            self.assertEqual(p.get_file_lines(enc), 2 * expectedLinesNoHanging)
-            self.assertEqual(p.get_file_lines(enc, retain=False), 2 * expectedLines2)
+            self.assertEqual(p.read_file_bytes(), expectedBytes)
+            self.assertEqual(p.read_file_text(enc), 2 * cleanNoHanging)
+            self.assertEqual(p.read_file_lines(enc), 2 * expectedLinesNoHanging)
+            self.assertEqual(p.read_file_lines(enc, retain=False), 2 * expectedLines2)
 
             # Write Unicode to file using Path.write_file_lines().
             # The output in the file should be exactly the same as last time.
             p.write_file_lines(expectedLines, enc)
             p.write_file_lines(expectedLines2, enc, append=True)
             # Check the result.
-            self.assertEqual(p.get_file_bytes(), expectedBytes)
+            self.assertEqual(p.read_file_bytes(), expectedBytes)
 
             # Now: same test, but using various newline sequences.
             # If linesep is being properly applied, these will be converted
@@ -419,7 +445,7 @@
             p.write_file_lines(givenLines, enc)
             p.write_file_lines(givenLines, enc, append=True)
             # Check the result.
-            self.assertEqual(p.get_file_bytes(), expectedBytes)
+            self.assertEqual(p.read_file_bytes(), expectedBytes)
 
             # Same test, using newline sequences that are different
             # from the platform default.
@@ -427,7 +453,7 @@
                 p.write_file_lines(givenLines, enc, linesep=eol)
                 p.write_file_lines(givenLines, enc, linesep=eol, append=True)
                 expected = 2 * cleanNoHanging.replace(u'\n', eol).encode(enc)
-                self.assertEqual(p.get_file_bytes(), expected)
+                self.assertEqual(p.read_file_bytes(), expected)
 
             testLinesep(u'\n')
             testLinesep(u'\r')
@@ -440,12 +466,12 @@
             p.write_file_lines(givenLines, enc, linesep=None, append=True)
             # Check the result.
             expectedBytes = 2 * given.encode(enc)
-            self.assertEqual(p.get_file_bytes(), expectedBytes)
-            self.assertEqual(p.get_file_text(enc), 2 * clean)
+            self.assertEqual(p.read_file_bytes(), expectedBytes)
+            self.assertEqual(p.read_file_text(enc), 2 * clean)
             expectedResultLines = expectedLines[:]
             expectedResultLines[-1] += expectedLines[0]
             expectedResultLines += expectedLines[1:]
-            self.assertEqual(p.get_file_lines(enc), expectedResultLines)
+            self.assertEqual(p.read_file_lines(enc), expectedResultLines)
 
         test('UTF-8')
         test('UTF-16BE')



More information about the Python-checkins mailing list