Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added more tests for more chainable methods

  • Loading branch information...
commit fe951770b71b6b90c20fcd8a1e47033f55c91731 1 parent 574885f
Jason R. Coombs authored
Showing with 14 additions and 1 deletion.
  1. +3 −0  path.py
  2. +11 −1 test_path.py
3  path.py
View
@@ -932,6 +932,7 @@ def renames(self, new):
def mkdir(self, mode=0777):
os.mkdir(self, mode)
+ return self
def mkdir_p(self, mode=0777):
try:
@@ -939,6 +940,7 @@ def mkdir_p(self, mode=0777):
except OSError, e:
if e.errno != errno.EEXIST:
raise
+ return self
def makedirs(self, mode=0777):
os.makedirs(self, mode)
@@ -981,6 +983,7 @@ def touch(self):
fd = os.open(self, os.O_WRONLY | os.O_CREAT, 0666)
os.close(fd)
os.utime(self, None)
+ return self
def remove(self):
os.remove(self)
12 test_path.py
View
@@ -176,7 +176,7 @@ def testExplicitModuleClasses(self):
class ReturnSelfTestCase(unittest.TestCase):
"""
- Some methods don't necessarily return any value (i.e. makedirs,
+ Some methods don't necessarily return any value (e.g. makedirs,
makedirs_p, rename, mkdir, touch, chroot). These methods should return
self anyhow to allow methods to be chained.
"""
@@ -211,6 +211,16 @@ def testRenameReturnsSelf(self):
ret = p.rename(target)
self.assertEquals(target, ret)
+ def testMkdirReturnsSelf(self):
+ p = path(self.tempdir) / "newdir"
+ ret = p.mkdir()
+ self.assertEquals(p, ret)
+
+ def testTouchReturnsSelf(self):
+ p = path(self.tempdir) / "empty file"
+ ret = p.touch()
+ 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.