Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pyfs
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
pyfs
Commits
41f626a4
Commit
41f626a4
authored
Sep 04, 2008
by
willmcgugan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added more tests
parent
44ecace3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
0 deletions
+71
-0
fs/fs.py
+6
-0
fs/memoryfs.py
+3
-0
fs/tests.py
+62
-0
No files found.
fs/fs.py
View file @
41f626a4
...
...
@@ -351,6 +351,7 @@ class FS(object):
raise
UnsupportedError
(
"UNSUPPORTED"
)
def
safeopen
(
self
,
*
args
,
**
kwargs
):
"""Like 'open', but will return a NullFile if the file could not be opened."""
try
:
f
=
self
.
open
(
*
args
,
**
kwargs
)
except
ResourceNotFoundError
:
...
...
@@ -358,6 +359,11 @@ class FS(object):
return
f
def
exists
(
self
,
path
):
"""Returns True if the path references a valid resource.
path -- A path to test
"""
raise
UnsupportedError
(
"UNSUPPORTED"
)
def
isdir
(
self
,
path
):
...
...
fs/memoryfs.py
View file @
41f626a4
...
...
@@ -153,6 +153,8 @@ class MemoryFS(FS):
try
:
current_dir
=
self
.
root
for
path_component
in
_iteratepath
(
dirpath
):
if
current_dir
.
contents
is
None
:
return
None
dir_entry
=
current_dir
.
contents
.
get
(
path_component
,
None
)
if
dir_entry
is
None
:
return
None
...
...
@@ -410,6 +412,7 @@ class MemoryFS(FS):
if
dir_entry
is
None
:
raise
ResourceNotFoundError
(
"NO_DIR"
,
path
)
paths
=
dir_entry
.
contents
.
keys
()
print
"Listdir"
,
paths
return
self
.
_listdir_helper
(
path
,
paths
,
wildcard
,
full
,
absolute
,
hidden
,
dirs_only
,
files_only
)
finally
:
...
...
fs/tests.py
View file @
41f626a4
...
...
@@ -188,6 +188,50 @@ class TestOSFS(unittest.TestCase):
self
.
assert_
(
not
check
(
"foo/bar"
))
self
.
assert_
(
not
check
(
"foo"
))
def
test_listdir
(
self
):
def
makefile
(
fname
):
f
=
self
.
fs
.
open
(
fname
,
"wb"
)
f
.
write
(
"*"
)
f
.
close
()
makefile
(
"a"
)
makefile
(
"b"
)
makefile
(
"foo"
)
makefile
(
"bar"
)
d1
=
self
.
fs
.
listdir
()
self
.
assertEqual
(
len
(
d1
),
4
)
self
.
assertEqual
(
sorted
(
d1
),
[
"a"
,
"b"
,
"bar"
,
"foo"
])
d2
=
self
.
fs
.
listdir
(
absolute
=
True
)
self
.
assertEqual
(
len
(
d2
),
4
)
self
.
assertEqual
(
sorted
(
d2
),
[
"/a"
,
"/b"
,
"/bar"
,
"/foo"
])
self
.
fs
.
makedir
(
"p/1/2/3"
,
recursive
=
True
)
makefile
(
"p/1/2/3/a"
)
makefile
(
"p/1/2/3/b"
)
makefile
(
"p/1/2/3/foo"
)
makefile
(
"p/1/2/3/bar"
)
self
.
fs
.
makedir
(
"q"
)
dirs_only
=
self
.
fs
.
listdir
(
dirs_only
=
True
)
files_only
=
self
.
fs
.
listdir
(
files_only
=
True
)
self
.
assertEqual
(
sorted
(
dirs_only
),
[
"p"
,
"q"
])
self
.
assertEqual
(
sorted
(
files_only
),
[
"a"
,
"b"
,
"bar"
,
"foo"
])
d3
=
self
.
fs
.
listdir
(
"p/1/2/3"
)
self
.
assertEqual
(
len
(
d3
),
4
)
self
.
assertEqual
(
sorted
(
d3
),
[
"a"
,
"b"
,
"bar"
,
"foo"
])
d4
=
self
.
fs
.
listdir
(
"p/1/2/3"
,
absolute
=
True
)
self
.
assertEqual
(
len
(
d4
),
4
)
self
.
assertEqual
(
sorted
(
d4
),
[
"/p/1/2/3/a"
,
"/p/1/2/3/b"
,
"/p/1/2/3/bar"
,
"/p/1/2/3/foo"
])
d4
=
self
.
fs
.
listdir
(
"p/1/2/3"
,
full
=
True
)
self
.
assertEqual
(
len
(
d4
),
4
)
self
.
assertEqual
(
sorted
(
d4
),
[
"p/1/2/3/a"
,
"p/1/2/3/b"
,
"p/1/2/3/bar"
,
"p/1/2/3/foo"
])
def
test_rename
(
self
):
check
=
self
.
check
self
.
fs
.
open
(
"foo.txt"
,
'wt'
)
.
write
(
"Hello, World!"
)
...
...
@@ -195,6 +239,24 @@ class TestOSFS(unittest.TestCase):
self
.
fs
.
rename
(
"foo.txt"
,
"bar.txt"
)
self
.
assert_
(
check
(
"bar.txt"
))
def
test_info
(
self
):
test_str
=
"Hello, World!"
f
=
self
.
fs
.
open
(
"info.txt"
,
'wb'
)
f
.
write
(
test_str
)
f
.
close
()
info
=
self
.
fs
.
getinfo
(
"info.txt"
)
self
.
assertEqual
(
info
[
'size'
],
len
(
test_str
))
def
test_getsize
(
self
):
test_str
=
"*"
*
23
f
=
self
.
fs
.
open
(
"info.txt"
,
'wb'
)
f
.
write
(
test_str
)
f
.
close
()
info
=
self
.
fs
.
getinfo
(
"info.txt"
)
self
.
assertEqual
(
info
[
'size'
],
len
(
test_str
))
class
TestSubFS
(
TestOSFS
):
def
setUp
(
self
):
...
...
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