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
9d5d0fed
Commit
9d5d0fed
authored
Mar 17, 2013
by
willmcgugan@gmail.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tests for mountfile
parent
0eb346d0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
4 deletions
+46
-4
fs/tests/test_mountfs.py
+46
-4
No files found.
fs/tests/test_mountfs.py
View file @
9d5d0fed
...
@@ -3,9 +3,9 @@ from fs.memoryfs import MemoryFS
...
@@ -3,9 +3,9 @@ from fs.memoryfs import MemoryFS
import
unittest
import
unittest
class
TestMultiFS
(
unittest
.
TestCase
):
class
TestMultiFS
(
unittest
.
TestCase
):
def
test_auto_close
(
self
):
def
test_auto_close
(
self
):
"""Test MultiFS auto close is working"""
"""Test MultiFS auto close is working"""
multi_fs
=
MountFS
()
multi_fs
=
MountFS
()
m1
=
MemoryFS
()
m1
=
MemoryFS
()
m2
=
MemoryFS
()
m2
=
MemoryFS
()
...
@@ -16,7 +16,7 @@ class TestMultiFS(unittest.TestCase):
...
@@ -16,7 +16,7 @@ class TestMultiFS(unittest.TestCase):
multi_fs
.
close
()
multi_fs
.
close
()
self
.
assert_
(
m1
.
closed
)
self
.
assert_
(
m1
.
closed
)
self
.
assert_
(
m2
.
closed
)
self
.
assert_
(
m2
.
closed
)
def
test_no_auto_close
(
self
):
def
test_no_auto_close
(
self
):
"""Test MultiFS auto close can be disabled"""
"""Test MultiFS auto close can be disabled"""
multi_fs
=
MountFS
(
auto_close
=
False
)
multi_fs
=
MountFS
(
auto_close
=
False
)
...
@@ -29,4 +29,46 @@ class TestMultiFS(unittest.TestCase):
...
@@ -29,4 +29,46 @@ class TestMultiFS(unittest.TestCase):
multi_fs
.
close
()
multi_fs
.
close
()
self
.
assert_
(
not
m1
.
closed
)
self
.
assert_
(
not
m1
.
closed
)
self
.
assert_
(
not
m2
.
closed
)
self
.
assert_
(
not
m2
.
closed
)
def
test_mountfile
(
self
):
"""Test mounting a file"""
quote
=
"""If you wish to make an apple pie from scratch, you must first invent the universe."""
mem_fs
=
MemoryFS
()
mem_fs
.
makedir
(
'foo'
)
mem_fs
.
setcontents
(
'foo/bar.txt'
,
quote
)
foo_dir
=
mem_fs
.
opendir
(
'foo'
)
mount_fs
=
MountFS
()
mount_fs
.
mountfile
(
'bar.txt'
,
foo_dir
.
open
,
foo_dir
.
getinfo
)
self
.
assert_
(
mount_fs
.
isdir
(
'/'
))
self
.
assert_
(
mount_fs
.
isdir
(
'./'
))
self
.
assert_
(
mount_fs
.
isdir
(
''
))
# Check we can see the mounted file in the dir list
self
.
assertEqual
(
mount_fs
.
listdir
(),
[
"bar.txt"
])
self
.
assert_
(
not
mount_fs
.
exists
(
'nobodyhere.txt'
))
self
.
assert_
(
mount_fs
.
exists
(
'bar.txt'
))
self
.
assert_
(
mount_fs
.
isfile
(
'bar.txt'
))
self
.
assert_
(
not
mount_fs
.
isdir
(
'bar.txt'
))
# Check open and getinfo callables
self
.
assertEqual
(
mount_fs
.
getcontents
(
'bar.txt'
),
quote
)
self
.
assertEqual
(
mount_fs
.
getsize
(
'bar.txt'
),
len
(
quote
))
# Check changes are written back
mem_fs
.
setcontents
(
'foo/bar.txt'
,
'baz'
)
self
.
assertEqual
(
mount_fs
.
getcontents
(
'bar.txt'
),
'baz'
)
self
.
assertEqual
(
mount_fs
.
getsize
(
'bar.txt'
),
len
(
'baz'
))
# Check changes are written to the original fs
self
.
assertEqual
(
mem_fs
.
getcontents
(
'foo/bar.txt'
),
'baz'
)
self
.
assertEqual
(
mem_fs
.
getsize
(
'foo/bar.txt'
),
len
(
'baz'
))
# Check unmount
self
.
assert_
(
mount_fs
.
unmount
(
"bar.txt"
))
self
.
assertEqual
(
mount_fs
.
listdir
(),
[])
self
.
assert_
(
not
mount_fs
.
exists
(
'bar.txt'
))
# Check unount a second time is a null op, and returns False
self
.
assertFalse
(
mount_fs
.
unmount
(
"bar.txt"
))
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