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
3d949d57
Commit
3d949d57
authored
Jan 26, 2011
by
rfkelly0
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
merge walk-related tests into core FSTestCases class
parent
99dd8521
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
33 deletions
+59
-33
fs/tests/__init__.py
+59
-1
fs/tests/test_walk.py
+0
-32
No files found.
fs/tests/__init__.py
View file @
3d949d57
...
...
@@ -137,7 +137,6 @@ class FSTestCases(object):
self
.
assertEquals
(
self
.
fs
.
getcontents
(
"hello"
),
"to you, good sir!"
)
def
test_setcontents_async
(
self
):
# setcontents() should accept both a string...
self
.
fs
.
setcontents_async
(
"hello"
,
"world"
)
.
wait
()
...
...
@@ -293,6 +292,65 @@ class FSTestCases(object):
self
.
assertRaises
(
ResourceNotFoundError
,
self
.
fs
.
listdirinfo
,
"zebra"
)
self
.
assertRaises
(
ResourceInvalidError
,
self
.
fs
.
listdirinfo
,
"foo"
)
def
test_walk
(
self
):
self
.
fs
.
setcontents
(
'a.txt'
,
'hello'
)
self
.
fs
.
setcontents
(
'b.txt'
,
'world'
)
self
.
fs
.
makeopendir
(
'foo'
)
.
setcontents
(
'c'
,
'123'
)
sorted_walk
=
sorted
([(
d
,
sorted
(
fs
))
for
(
d
,
fs
)
in
self
.
fs
.
walk
()])
self
.
assertEquals
(
sorted_walk
,
[(
"/"
,[
"a.txt"
,
"b.txt"
]),
(
"/foo"
,[
"c"
])])
# When searching breadth-first, shallow entries come first
found_a
=
False
for
_
,
files
in
self
.
fs
.
walk
(
search
=
"breadth"
):
if
"a.txt"
in
files
:
found_a
=
True
if
"c"
in
files
:
break
assert
found_a
,
"breadth search order was wrong"
# When searching deth-first, deep entries come first
found_c
=
False
for
_
,
files
in
self
.
fs
.
walk
(
search
=
"depth"
):
if
"c"
in
files
:
found_c
=
True
if
"a.txt"
in
files
:
break
assert
found_c
,
"depth search order was wrong"
def
test_walk_wildcard
(
self
):
self
.
fs
.
setcontents
(
'a.txt'
,
'hello'
)
self
.
fs
.
setcontents
(
'b.txt'
,
'world'
)
self
.
fs
.
makeopendir
(
'foo'
)
.
setcontents
(
'c'
,
'123'
)
self
.
fs
.
makeopendir
(
'.svn'
)
.
setcontents
(
'ignored'
,
''
)
for
dir_path
,
paths
in
self
.
fs
.
walk
(
wildcard
=
'*.txt'
):
for
path
in
paths
:
self
.
assert_
(
path
.
endswith
(
'.txt'
))
for
dir_path
,
paths
in
self
.
fs
.
walk
(
wildcard
=
lambda
fn
:
fn
.
endswith
(
'.txt'
)):
for
path
in
paths
:
self
.
assert_
(
path
.
endswith
(
'.txt'
))
def
test_walk_dir_wildcard
(
self
):
self
.
fs
.
setcontents
(
'a.txt'
,
'hello'
)
self
.
fs
.
setcontents
(
'b.txt'
,
'world'
)
self
.
fs
.
makeopendir
(
'foo'
)
.
setcontents
(
'c'
,
'123'
)
self
.
fs
.
makeopendir
(
'.svn'
)
.
setcontents
(
'ignored'
,
''
)
for
dir_path
,
paths
in
self
.
fs
.
walk
(
dir_wildcard
=
lambda
fn
:
not
fn
.
endswith
(
'.svn'
)):
for
path
in
paths
:
self
.
assert_
(
'.svn'
not
in
path
)
def
test_walkfiles
(
self
):
self
.
fs
.
makeopendir
(
'bar'
)
.
setcontents
(
'a.txt'
,
'123'
)
self
.
fs
.
makeopendir
(
'foo'
)
.
setcontents
(
'b'
,
'123'
)
self
.
assertEquals
(
sorted
(
self
.
fs
.
walkfiles
()),[
"/bar/a.txt"
,
"/foo/b"
])
self
.
assertEquals
(
sorted
(
self
.
fs
.
walkfiles
(
dir_wildcard
=
"*foo*"
)),[
"/foo/b"
])
self
.
assertEquals
(
sorted
(
self
.
fs
.
walkfiles
(
wildcard
=
"*.txt"
)),[
"/bar/a.txt"
])
def
test_walkdirs
(
self
):
self
.
fs
.
makeopendir
(
'bar'
)
.
setcontents
(
'a.txt'
,
'123'
)
self
.
fs
.
makeopendir
(
'foo'
)
.
makeopendir
(
"baz"
)
.
setcontents
(
'b'
,
'123'
)
self
.
assertEquals
(
sorted
(
self
.
fs
.
walkdirs
()),[
"/"
,
"/bar"
,
"/foo"
,
"/foo/baz"
])
self
.
assertEquals
(
sorted
(
self
.
fs
.
walkdirs
(
wildcard
=
"*foo*"
)),[
"/"
,
"/foo"
,
"/foo/baz"
])
def
test_unicode
(
self
):
alpha
=
u"
\N{GREEK SMALL LETTER ALPHA}
"
beta
=
u"
\N{GREEK SMALL LETTER BETA}
"
...
...
fs/tests/test_walk.py
deleted
100644 → 0
View file @
99dd8521
"""
Test the walk function and related code
"""
import
unittest
from
fs.memoryfs
import
MemoryFS
class
TestWalk
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
fs
=
MemoryFS
()
self
.
fs
.
setcontents
(
'a.txt'
,
'hello'
)
self
.
fs
.
setcontents
(
'b.txt'
,
'world'
)
self
.
fs
.
makeopendir
(
'foo'
)
.
setcontents
(
'c'
,
'123'
)
self
.
fs
.
makeopendir
(
'.svn'
)
.
setcontents
(
'ignored'
,
''
)
def
test_wildcard
(
self
):
for
dir_path
,
paths
in
self
.
fs
.
walk
(
wildcard
=
'*.txt'
):
for
path
in
paths
:
self
.
assert_
(
path
.
endswith
(
'.txt'
))
for
dir_path
,
paths
in
self
.
fs
.
walk
(
wildcard
=
lambda
fn
:
fn
.
endswith
(
'.txt'
)):
for
path
in
paths
:
self
.
assert_
(
path
.
endswith
(
'.txt'
))
def
test_dir_wildcard
(
self
):
for
dir_path
,
paths
in
self
.
fs
.
walk
(
dir_wildcard
=
lambda
fn
:
not
fn
.
endswith
(
'.svn'
)):
for
path
in
paths
:
self
.
assert_
(
'.svn'
not
in
path
)
\ No newline at end of file
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