Commits

Michele Lacchia committed bda6ac3

Now all tests pass

  • Participants
  • Parent commits 7db1771

Comments (0)

Files changed (4)

 ^dist/
 ^MANIFEST
 ^docs/_
+.*\.pyc
 # Internals
 #
 
-class _Flavour:
+class _Flavour(object):
     """A flavour implements a particular (platform-specific) set of path
     semantics."""
 
         return "<{}.parts: {!r}>".format(self._pathcls.__name__, self._parts)
 
 
-class PurePath:
+class PurePath(object):
     """PurePath represents a filesystem path and offers operations which
     don't imply any actual filesystem I/O.  Depending on your system,
     instantiating a PurePath will return either a PurePosixPath or a
 
     def __lt__(self, other):
         if self._flavour is not other._flavour:
-            return NotImplemented
+            raise TypeError
         return self._cparts < other._cparts
 
     def __le__(self, other):
     )
 
     _wrs = {}
-    _wr_id = count().__next__
+    _wr_id = count()
 
-    def __new__(cls, *args, use_openat=False):
+    def __new__(cls, *args, **kwargs):
+        use_openat = kwargs.get('use_openat', False)
         if cls is Path:
             cls = NTPath if os.name == 'nt' else PosixPath
         self = cls._from_parts(args, init=False)
             cleanup = type(self)._cleanup
             # We can't hash the weakref directly since distinct Path objects
             # can compare equal.
-            wr_id = self._wr_id()
+            wr_id = next(self._wr_id)
             wr = weakref.ref(self, lambda wr: cleanup(fds, wr_id))
             self._wrs[wr_id] = wr
         _add_fd_ref(fd)
     def __getattr__(self, name):
         if name.startswith('st_'):
             return getattr(self._stat, name)
-        return super().__getattribute__(name)
+        return super(Path, self).__getattribute__(name)
 
     def abspath(self):
         """Return an absolute version of this path.  This function works
 import sys
 from distutils.core import setup
 
-if sys.version_info <= (3, 2):
-    sys.exit("Python 3.2 or later required")
 
 setup(
     name='pathlib',

File test_pathlib.py

 import collections
 import io
+import os
 import errno
-import os
 import pathlib
 import sys
 import shutil
 import unittest
 from contextlib import contextmanager
 
-from test import support
+try:
+    from test import support
+except ImportError:
+    from test import test_support as support
 TESTFN = support.TESTFN
 
 
             self.assertEqual(P(pathstr).as_posix(), pathstr)
         # Other tests for as_posix() are in test_equivalences()
 
+    @unittest.skipIf(sys.version_info[:2] < (3, 2),
+                     'os.fsencode has been introduced in version 3.2')
     def test_as_bytes_common(self):
+        try:
+            sep = os.fsencode(self.sep)
+        except AttributeError:
+            sys.stdout.write('Skipping test_as_bytes_common, as os.fsencode ' \
+                             'has been introduced in version 3.2\n')
+            return
         P = self.cls
-        sep = os.fsencode(self.sep)
         self.assertEqual(P('a/b').as_bytes(), b'a' + sep + b'b')
         self.assertEqual(bytes(P('a/b')), b'a' + sep + b'b')
 
         q = pathlib.PureNTPath('a')
         self.assertNotEqual(p, q)
 
+    @unittest.skipIf(sys.version_info[:2] < (3, 0),
+                     'Most types are orderable in Python 2')
     def test_different_flavours_unordered(self):
         p = pathlib.PurePosixPath('a')
         q = pathlib.PureNTPath('a')
         p = P(BASE, 'dirB', 'linkD', 'fileB')
         self._check_resolve_relative(p, P(BASE, 'dirB', 'fileB'))
         # Now create absolute symlinks
-        with tempfile.TemporaryDirectory(suffix='-dirD') as d:
-            os.symlink(os.path.join(d), join('dirA', 'linkX'))
-            os.symlink(join('dirB'), os.path.join(d, 'linkY'))
-            p = P(BASE, 'dirA', 'linkX', 'linkY', 'fileB')
-            self._check_resolve_absolute(p, P(BASE, 'dirB', 'fileB'))
+        d = tempfile.mkdtemp(suffix='-dirD')
+        os.symlink(os.path.join(d), join('dirA', 'linkX'))
+        os.symlink(join('dirB'), os.path.join(d, 'linkY'))
+        p = P(BASE, 'dirA', 'linkX', 'linkY', 'fileB')
+        self._check_resolve_absolute(p, P(BASE, 'dirB', 'fileB'))
+        self.addCleanup(support.rmtree, d)
 
     def test_with(self):
         p = self.cls(BASE)