Permalink
Browse files

Merge pull request #10 from xentac/master

Make makedirs_p and makedirs return self partially fixes Issue #7
  • Loading branch information...
2 parents dd5d16a + 6032fcf commit 996a3fa9be383e774ef1b1b799d3cbdf1afa1aca @jaraco committed Nov 13, 2012
Showing with 24 additions and 0 deletions.
  1. +2 −0 path.py
  2. +22 −0 test_path.py
View
2 path.py
@@ -913,13 +913,15 @@ def mkdir_p(self, mode=0777):
def makedirs(self, mode=0777):
os.makedirs(self, mode)
+ return self
def makedirs_p(self, mode=0777):
try:
self.makedirs(mode)
except OSError, e:
if e.errno != errno.EEXIST:
raise
+ return self
def rmdir(self):
os.rmdir(self)
View
22 test_path.py
@@ -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.

0 comments on commit 996a3fa

Please sign in to comment.