Skip to content
Permalink
Browse files

Merge pull request #538 from michelboaventura/master

Implements suffix argument to File::basename
  • Loading branch information
alex committed Mar 21, 2013
2 parents f80a646 + eb45983 commit e6071fa131a1a6e37aebcf4d7e2f2e6f0143d5b2
Showing with 10 additions and 3 deletions.
  1. +2 −0 tests/objects/test_fileobject.py
  2. +8 −3 topaz/objects/fileobject.py
@@ -256,6 +256,8 @@ def test_basename(self, space):
assert space.str_w(space.execute("return File.basename('ab')")) == "ab"
assert space.str_w(space.execute("return File.basename('/ab')")) == "ab"
assert space.str_w(space.execute("return File.basename('/foo/bar/ab')")) == "ab"
assert space.str_w(space.execute("return File.basename('ab.rb', '.rb')")) == "ab"
assert space.str_w(space.execute("return File.basename('ab.rb', 'b.rb')")) == "a"

def test_truncate(self, space, tmpdir):
f = tmpdir.join("file.txt")
@@ -199,11 +199,16 @@ def method_identicalp(self, space, file, other):
return space.newbool(file_stat.st_dev == other_stat.st_dev and
file_stat.st_ino == other_stat.st_ino)

@classdef.singleton_method("basename", filename="path")
def method_basename(self, space, filename):
@classdef.singleton_method("basename", filename="path", suffix="path")
def method_basename(self, space, filename, suffix=None):
i = filename.rfind("/") + 1
assert i >= 0
return space.newstr_fromstr(filename[i:])
filename = filename[i:]
if suffix is not None and filename.endswith(suffix):
end = len(filename) - len(suffix)
assert end >= 0
filename = filename[:end]
return space.newstr_fromstr(filename)

@classdef.singleton_method("umask", mask="int")
def method_umask(self, space, mask=-1):

0 comments on commit e6071fa

Please sign in to comment.
You can’t perform that action at this time.