Skip to content

Commit

Permalink
Merge pull request #108 from tigarmo/fix-unicode-fspath-py27
Browse files Browse the repository at this point in the history
Fix fspath() for python2 unicode paths

fixes #106
  • Loading branch information
RonnyPfannschmidt committed Jan 19, 2017
2 parents c8da012 + 3307661 commit a441d0d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
- avoid imports in calls to py.path.local().fnmatch(). Thanks Andreas Pelme for
the PR.

- fix issue106: Naive unicode encoding when calling fspath() in python2. Thanks Tiago Nobrega for the PR.

1.4.32
====================================================================

Expand Down
2 changes: 1 addition & 1 deletion py/_path/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ def samefile(self, other):
return self.strpath == str(other)

def __fspath__(self):
return str(self)
return self.strpath

class Visitor:
def __init__(self, fil, rec, ignore, bf, sort):
Expand Down
15 changes: 15 additions & 0 deletions testing/path/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ def test_eq_with_strings(self, path1):
def test_eq_with_none(self, path1):
assert path1 != None

def test_eq_non_ascii_unicode(self, path1):
path2 = path1.join(u'temp')
path3 = path1.join(u'ação')
path4 = path1.join(u'ディレクトリ')

assert path2 != path3
assert path2 != path4
assert path4 != path3

def test_gt_with_strings(self, path1):
path2 = path1.join('sampledir')
path3 = str(path1.join("ttt"))
Expand Down Expand Up @@ -249,6 +258,12 @@ def test_ensure_dirpath(self, tmpdir):
assert t == newfile
assert newfile.check(dir=1)

def test_ensure_non_ascii_unicode(self, tmpdir):
newfile = tmpdir.join(u'ação',u'ディレクトリ')
t = newfile.ensure(dir=1)
assert t == newfile
assert newfile.check(dir=1)

def test_init_from_path(self, tmpdir):
l = local()
l2 = local(l)
Expand Down

0 comments on commit a441d0d

Please sign in to comment.