Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #10 from xentac/master

Make makedirs_p and makedirs return self partially fixes Issue #7
  • Loading branch information...
commit 996a3fa9be383e774ef1b1b799d3cbdf1afa1aca 2 parents dd5d16a + 6032fcf
Jason R. Coombs authored
Showing with 24 additions and 0 deletions.
  1. +2 −0  path.py
  2. +22 −0 test_path.py
2  path.py
View
@@ -913,6 +913,7 @@ def mkdir_p(self, mode=0777):
def makedirs(self, mode=0777):
os.makedirs(self, mode)
+ return self
def makedirs_p(self, mode=0777):
try:
@@ -920,6 +921,7 @@ def makedirs_p(self, mode=0777):
except OSError, e:
if e.errno != errno.EEXIST:
raise
+ return self
def rmdir(self):
os.rmdir(self)
22 test_path.py
View
@@ -127,6 +127,28 @@ def testUNC(self):
self.assert_(p.uncshare == r'\\python1\share1')
self.assert_(p.splitunc() == os.path.splitunc(str(p)))
+class ReturnSelfTestCase(unittest.TestCase):
+ def setUp(self):
+ # Create a temporary directory.
+ f = tempfile.mktemp()
+ system_tmp_dir = os.path.dirname(f)
+ my_dir = 'testpath_tempdir_' + str(random.random())[2:]
+ self.tempdir = os.path.join(system_tmp_dir, my_dir)
+ os.mkdir(self.tempdir)
+
+ def tearDown(self):
+ shutil.rmtree(self.tempdir)
+
+ def testMakedirs_pReturnsSelf(self):
+ p = path(self.tempdir) / "newpath"
+ ret = p.makedirs_p()
+ self.assertEquals(p, ret)
+
+ def testMakedirs_pReturnsSelfEvenIfExists(self):
+ p = path(self.tempdir)
+ ret = p.makedirs_p()
+ self.assertEquals(p, ret)
+
class TempDirTestCase(unittest.TestCase):
def setUp(self):
# Create a temporary directory.
Please sign in to comment.
Something went wrong with that request. Please try again.