Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
228c6369
Commit
228c6369
authored
Jun 04, 2016
by
Ethan Furman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
issue27186: fix fsencode/fsdecode and update tests; patch by Jelle Zijlstra
parent
db780cff
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
8 deletions
+15
-8
Lib/os.py
Lib/os.py
+2
-2
Lib/test/test_os.py
Lib/test/test_os.py
+13
-6
No files found.
Lib/os.py
View file @
228c6369
...
@@ -889,7 +889,7 @@ def _fscodec():
...
@@ -889,7 +889,7 @@ def _fscodec():
return
filename
.
encode
(
encoding
,
errors
)
return
filename
.
encode
(
encoding
,
errors
)
else
:
else
:
raise
TypeError
(
"expected str, bytes or os.PathLike object, not "
raise
TypeError
(
"expected str, bytes or os.PathLike object, not "
+
path_type
.
__name__
)
+
type
(
filename
)
.
__name__
)
def
fsdecode
(
filename
):
def
fsdecode
(
filename
):
"""
"""
...
@@ -905,7 +905,7 @@ def _fscodec():
...
@@ -905,7 +905,7 @@ def _fscodec():
return
filename
.
decode
(
encoding
,
errors
)
return
filename
.
decode
(
encoding
,
errors
)
else
:
else
:
raise
TypeError
(
"expected str, bytes or os.PathLike object, not "
raise
TypeError
(
"expected str, bytes or os.PathLike object, not "
+
path_type
.
__name__
)
+
type
(
filename
)
.
__name__
)
return
fsencode
,
fsdecode
return
fsencode
,
fsdecode
...
...
Lib/test/test_os.py
View file @
228c6369
...
@@ -3107,29 +3107,36 @@ class TestPEP519(unittest.TestCase):
...
@@ -3107,29 +3107,36 @@ class TestPEP519(unittest.TestCase):
self
.
assertEqual
(
s
,
os
.
fspath
(
s
))
self
.
assertEqual
(
s
,
os
.
fspath
(
s
))
def
test_fsencode_fsdecode_return_pathlike
(
self
):
def
test_fsencode_fsdecode_return_pathlike
(
self
):
class
Path
l
ike
:
class
Path
L
ike
:
def
__init__
(
self
,
path
):
def
__init__
(
self
,
path
):
self
.
path
=
path
self
.
path
=
path
def
__fspath__
(
self
):
def
__fspath__
(
self
):
return
self
.
path
return
self
.
path
for
p
in
"path/like/object"
,
b"path/like/object"
:
for
p
in
"path/like/object"
,
b"path/like/object"
:
pathlike
=
Path
l
ike
(
p
)
pathlike
=
Path
L
ike
(
p
)
self
.
assertEqual
(
p
,
os
.
fspath
(
pathlike
))
self
.
assertEqual
(
p
,
os
.
fspath
(
pathlike
))
self
.
assertEqual
(
b"path/like/object"
,
os
.
fsencode
(
pathlike
))
self
.
assertEqual
(
b"path/like/object"
,
os
.
fsencode
(
pathlike
))
self
.
assertEqual
(
"path/like/object"
,
os
.
fsdecode
(
pathlike
))
self
.
assertEqual
(
"path/like/object"
,
os
.
fsdecode
(
pathlike
))
def
test_fspathlike
(
self
):
def
test_fspathlike
(
self
):
class
PathLike
(
object
):
class
PathLike
:
def
__init__
(
self
,
path
=
''
):
self
.
path
=
path
def
__fspath__
(
self
):
def
__fspath__
(
self
):
return
'#feelthegil'
return
self
.
path
self
.
assertEqual
(
'#feelthegil'
,
os
.
fspath
(
PathLike
()))
self
.
assertEqual
(
'#feelthegil'
,
os
.
fspath
(
PathLike
(
'#feelthegil'
)))
self
.
assertTrue
(
issubclass
(
PathLike
,
os
.
PathLike
))
self
.
assertTrue
(
issubclass
(
PathLike
,
os
.
PathLike
))
self
.
assertTrue
(
isinstance
(
PathLike
(),
os
.
PathLike
))
self
.
assertTrue
(
isinstance
(
PathLike
(),
os
.
PathLike
))
message
=
'expected str, bytes or os.PathLike object, not'
for
fn
in
(
os
.
fsencode
,
os
.
fsdecode
):
for
obj
in
PathLike
(
None
),
None
:
with
self
.
assertRaisesRegex
(
TypeError
,
message
):
fn
(
obj
)
def
test_garbage_in_exception_out
(
self
):
def
test_garbage_in_exception_out
(
self
):
vapor
=
type
(
'blah'
,
(),
{})
vapor
=
type
(
'blah'
,
(),
{})
for
o
in
int
,
type
,
os
,
vapor
():
for
o
in
int
,
type
,
os
,
vapor
():
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment