diff options
author | willmcgugan@gmail.com <willmcgugan@gmail.com@67cdc799-7952-0410-af00-57a81ceafa0f> | 2013-03-17 13:29:30 +0000 |
---|---|---|
committer | willmcgugan@gmail.com <willmcgugan@gmail.com@67cdc799-7952-0410-af00-57a81ceafa0f> | 2013-03-17 13:29:30 +0000 |
commit | b94987712fb161c78c75b8a7e1afcd44e10f61b0 (patch) | |
tree | 8b8fbc50a62129858e78d23d43338e5e6b5cd7c8 /fs/tests | |
parent | a054ee65a8b7484dac214491e90c8a9ca19161b9 (diff) | |
download | pyfilesystem-b94987712fb161c78c75b8a7e1afcd44e10f61b0.tar.gz |
Tests for mountfile
git-svn-id: http://pyfilesystem.googlecode.com/svn/trunk@849 67cdc799-7952-0410-af00-57a81ceafa0f
Diffstat (limited to 'fs/tests')
-rw-r--r-- | fs/tests/test_mountfs.py | 50 |
1 files changed, 46 insertions, 4 deletions
diff --git a/fs/tests/test_mountfs.py b/fs/tests/test_mountfs.py index ef3658c..bcb02c3 100644 --- a/fs/tests/test_mountfs.py +++ b/fs/tests/test_mountfs.py @@ -3,9 +3,9 @@ from fs.memoryfs import MemoryFS import unittest class TestMultiFS(unittest.TestCase): - + def test_auto_close(self): - """Test MultiFS auto close is working""" + """Test MultiFS auto close is working""" multi_fs = MountFS() m1 = MemoryFS() m2 = MemoryFS() @@ -16,7 +16,7 @@ class TestMultiFS(unittest.TestCase): multi_fs.close() self.assert_(m1.closed) self.assert_(m2.closed) - + def test_no_auto_close(self): """Test MultiFS auto close can be disabled""" multi_fs = MountFS(auto_close=False) @@ -29,4 +29,46 @@ class TestMultiFS(unittest.TestCase): multi_fs.close() self.assert_(not m1.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")) |