Commits

Antoine Pitrou  committed c255872

Add tests for Path('.').ext

  • Participants
  • Parent commits 107bf33
  • Branches pathlib

Comments (0)

Files changed (2)

File Lib/pathlib.py

         if len(parts) == (1 if (self._drv or self._root) else 0):
             return ''
         basename = parts[-1]
+        if basename == '.':
+            return ''
         i = basename.find('.')
-        return basename[i:] if i != -1 else ''
+        if i == -1:
+            return ''
+        return basename[i:]
 
     def relative(self):
         """Return a new path without any drive and root.
             return self
         # FIXME this must defer to the specific flavour (and, under Windows,
         # use nt._getfullpathname())
-        obj = self._from_parts((os.getcwd(),) + self._parts, init=False)
+        obj = self._from_parts([os.getcwd()] + self._parts, init=False)
         obj._init(template=self, parent_fd=self._parent_fd, fd=self._cached_fd)
         return obj
 

File Lib/test/test_pathlib.py

     def test_ext_common(self):
         P = self.cls
         self.assertEqual(P('').ext, '')
+        self.assertEqual(P('.').ext, '')
         self.assertEqual(P('/').ext, '')
         self.assertEqual(P('a/b').ext, '')
         self.assertEqual(P('/a/b').ext, '')
+        self.assertEqual(P('/a/b/.').ext, '')
         self.assertEqual(P('a/b.py').ext, '.py')
         self.assertEqual(P('/a/b.py').ext, '.py')
         self.assertEqual(P('a/b.tar.gz').ext, '.tar.gz')