Commits

Antoine Pitrou  committed 4926806 Merge

Merge bug fixes from default

  • Participants
  • Parent commits 6bfe379, ecbad9d
  • Branches pep428

Comments (0)

Files changed (3)

 Version 0.8
 ^^^^^^^^^^^
 
-- Add PurePath.name and PurePath.anchor
-- Add Path.owner and Path.group
-- Add Path.replace()
+- Add PurePath.name and PurePath.anchor.
+- Add Path.owner and Path.group.
+- Add Path.replace().
+- Issue #10: when creating a file with Path.open(), don't set the executable
+  bit.
+- Issue #11: fix comparisons with non-Path objects.
 
 Version 0.7
 ^^^^^^^^^^^
             return self._cached_cparts
 
     def __eq__(self, other):
+        if not isinstance(other, PurePath):
+            return NotImplemented
         return self._cparts == other._cparts and self._flavour is other._flavour
 
     def __ne__(self, other):
             return self._hash
 
     def __lt__(self, other):
-        if self._flavour is not other._flavour:
+        if not isinstance(other, PurePath) or self._flavour is not other._flavour:
             return NotImplemented
         return self._cparts < other._cparts
 
     def __le__(self, other):
-        if self._flavour is not other._flavour:
+        if not isinstance(other, PurePath) or self._flavour is not other._flavour:
             return NotImplemented
         return self._cparts <= other._cparts
 
     def __gt__(self, other):
-        if self._flavour is not other._flavour:
+        if not isinstance(other, PurePath) or self._flavour is not other._flavour:
             return NotImplemented
         return self._cparts > other._cparts
 
     def __ge__(self, other):
-        if self._flavour is not other._flavour:
+        if not isinstance(other, PurePath) or self._flavour is not other._flavour:
             return NotImplemented
         return self._cparts >= other._cparts
 
     def _raise_closed(self):
         raise ValueError("I/O operation on closed path")
 
-    def _opener(self, name, flags, mode=0o777):
+    def _opener(self, name, flags, mode=0o666):
         # A stub for the opener argument to built-in open()
         return self._accessor.open(self, flags, mode)
 
         else:
             return io.open(str(self), mode, buffering, encoding, errors, newline)
 
-    def touch(self, mode=0o777, exist_ok=True):
+    def touch(self, mode=0o666, exist_ok=True):
         """
         Create this file with the given access mode, if it doesn't exist.
         """

File test_pathlib.py

 import os
 import errno
 import pathlib
+import shutil
+import stat
 import sys
-import shutil
 import tempfile
 import unittest
 from contextlib import contextmanager
         self.assertNotEqual(P('a/b'), P())
         self.assertNotEqual(P('/a/b'), P('/'))
         self.assertNotEqual(P(), P('/'))
+        self.assertNotEqual(P(), "")
+        self.assertNotEqual(P(), {})
+        self.assertNotEqual(P(), int)
 
     def test_match_common(self):
         P = self.cls
         assertLess(a, d)
         assertLess(b, c)
         assertLess(c, d)
+        if sys.version_info > (3,):
+            with self.assertRaises(TypeError):
+                P() < {}
+        else:
+            P() < {}
 
     def test_parts_common(self):
         sep = self.sep
         self.assertIs(False, (p / 'foo').exists())
         self.assertIs(False, P('/xyzzy').exists())
 
-    def test_open(self):
+    def test_open_common(self):
         p = self.cls(BASE)
         with (p / 'fileA').open('r') as f:
             self.assertIsInstance(f, io.TextIOBase)
         self.assertEqual(os.stat(r).st_size, size)
         self.assertFileNotFound(q.restat)
 
-    def test_touch(self):
+    def test_touch_common(self):
         P = self.cls(BASE)
         p = P / 'newfileA'
         self.assertFalse(p.exists())
         p.touch(mode=0o700, exist_ok=False)
         self.assertTrue(p.exists())
         self.assertRaises(OSError, p.touch, exist_ok=False)
-        # XXX better test `mode` arg
 
     def test_mkdir(self):
         P = self.cls(BASE)
         with self.assertRaises(ValueError):
             print(path.resolve())
 
+    def test_open_mode(self):
+        old_mask = os.umask(0)
+        self.addCleanup(os.umask, old_mask)
+        p = self.cls(BASE)
+        with (p / 'new_file').open('wb'):
+            pass
+        st = os.stat(join('new_file'))
+        self.assertEqual(stat.S_IMODE(st.st_mode), 0o666)
+        os.umask(0o022)
+        with (p / 'other_new_file').open('wb'):
+            pass
+        st = os.stat(join('other_new_file'))
+        self.assertEqual(stat.S_IMODE(st.st_mode), 0o644)
+
+    def test_touch_mode(self):
+        old_mask = os.umask(0)
+        self.addCleanup(os.umask, old_mask)
+        p = self.cls(BASE)
+        (p / 'new_file').touch()
+        st = os.stat(join('new_file'))
+        self.assertEqual(stat.S_IMODE(st.st_mode), 0o666)
+        os.umask(0o022)
+        (p / 'other_new_file').touch()
+        st = os.stat(join('other_new_file'))
+        self.assertEqual(stat.S_IMODE(st.st_mode), 0o644)
+        (p / 'masked_new_file').touch(mode=0o750)
+        st = os.stat(join('masked_new_file'))
+        self.assertEqual(stat.S_IMODE(st.st_mode), 0o750)
+
     @with_symlinks
     def test_resolve_loop(self):
         # Loop detection for broken symlinks under POSIX