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
aab21a9f
Commit
aab21a9f
authored
Aug 20, 2008
by
willmcgugan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enhancements to objecttree, and added objecttree test suite
parent
82f7a054
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
2 deletions
+48
-2
fs/objecttree.py
+9
-2
fs/tests.py
+39
-0
No files found.
fs/objecttree.py
View file @
aab21a9f
...
...
@@ -12,6 +12,12 @@ class ObjectTree(object):
def
__init__
(
self
):
self
.
root
=
_ObjectDict
()
def
_split
(
self
,
path
):
if
'/'
not
in
path
:
return
""
,
path
else
:
return
path
.
rsplit
(
'/'
,
1
)
def
_splitpath
(
self
,
path
):
return
[
p
for
p
in
path
.
split
(
'/'
)
if
p
]
...
...
@@ -30,7 +36,7 @@ class ObjectTree(object):
if
not
path
:
raise
IndexError
(
"No path supplied"
)
current
=
self
.
root
path
,
name
=
path
.
rsplit
(
'/'
,
1
)
path
,
name
=
self
.
_split
(
path
)
for
path_component
in
self
.
_splitpath
(
path
):
node
=
current
.
get
(
path_component
,
None
)
if
type
(
node
)
is
not
_ObjectDict
:
...
...
@@ -48,7 +54,7 @@ class ObjectTree(object):
return
node
def
__delitem__
(
self
,
path
):
path
,
name
=
path
.
rsplit
(
'/'
,
1
)
path
,
name
=
self
.
_split
(
path
)
node
=
self
.
_locate
(
path
)
if
node
is
None
or
type
(
node
)
is
not
_ObjectDict
:
raise
IndexError
(
"Path does not exist"
)
...
...
@@ -98,6 +104,7 @@ class ObjectTree(object):
def
iteritems
(
self
):
return
self
.
root
.
iteritems
()
if
__name__
==
"__main__"
:
ot
=
ObjectTree
()
...
...
fs/tests.py
View file @
aab21a9f
...
...
@@ -101,6 +101,45 @@ class TestHelpers(unittest.TestCase):
self
.
assertEqual
(
fs
.
pathsplit
(
path
),
result
)
import
objecttree
class
TestObjectTree
(
unittest
.
TestCase
):
def
test_getset
(
self
):
"""objecttree.ObjectTree tests"""
ot
=
objecttree
.
ObjectTree
()
ot
[
'foo'
]
=
"bar"
self
.
assertEqual
(
ot
[
'foo'
],
'bar'
)
ot
=
objecttree
.
ObjectTree
()
ot
[
'foo/bar'
]
=
"baz"
self
.
assertEqual
(
ot
[
'foo'
],
{
'bar'
:
'baz'
})
self
.
assertEqual
(
ot
[
'foo/bar'
],
'baz'
)
del
ot
[
'foo/bar'
]
self
.
assertEqual
(
ot
[
'foo'
],
{})
ot
=
objecttree
.
ObjectTree
()
ot
[
'a/b/c'
]
=
"A"
ot
[
'a/b/d'
]
=
"B"
ot
[
'a/b/e'
]
=
"C"
ot
[
'a/b/f'
]
=
"D"
self
.
assertEqual
(
sorted
(
ot
[
'a/b'
]
.
values
()),
[
'A'
,
'B'
,
'C'
,
'D'
])
self
.
assert_
(
ot
.
get
(
'a/b/x'
,
None
)
is
None
)
self
.
assert_
(
'a/b/c'
in
ot
)
self
.
assert_
(
'a/b/x'
not
in
ot
)
self
.
assert_
(
ot
.
isobject
(
'a/b/c'
))
self
.
assert_
(
ot
.
isobject
(
'a/b/d'
))
self
.
assert_
(
not
ot
.
isobject
(
'a/b'
))
left
,
object
,
right
=
ot
.
partialget
(
'a/b/e/f/g'
)
self
.
assertEqual
(
left
,
"a/b/e"
)
self
.
assertEqual
(
object
,
"C"
)
self
.
assertEqual
(
right
,
"f/g"
)
import
tempfile
import
osfs
import
os
...
...
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