6
from twisted.trial import unittest
8
from twisted.vfs.backends import osfs, inmem
9
from twisted.vfs.ivfs import IFileSystemContainer, IFileSystemLeaf
12
class OSVFSTest(unittest.TestCase):
15
self.tmpdir = self.mktemp()
17
os.mkdir(os.path.join(self.tmpdir, 'ned'))
18
open(os.path.join(self.tmpdir, 'file.txt'), 'w').write('wobble\n')
19
self.root = osfs.OSDirectory(self.tmpdir)
22
shutil.rmtree(self.tmpdir)
24
def test_listdir(self):
25
nodes = self.root.children()
26
paths = [path for (path, node) in nodes]
28
self.assertEquals(paths, ['.', '..', 'file.txt', 'ned'])
31
new = self.root.createDirectory('fred')
32
nodes = new.children()
33
self.assertEquals([path for (path, node) in nodes], ['.', '..'])
36
self.root.child('ned').remove()
37
nodes = self.root.children()
38
paths = [path for (path, node) in nodes]
40
self.assertEquals(paths, ['.', '..', 'file.txt'])
42
def test_rmfile(self):
43
self.root.child('file.txt').remove()
44
nodes = self.root.children()
45
paths = [path for (path, node) in nodes]
47
self.assertEquals(paths, ['.', '..', 'ned'])
49
def test_rename(self):
50
self.root.child('ned').rename('sed')
51
nodes = self.root.children()
52
paths = [path for (path, node) in nodes]
54
self.assertEquals(paths, ['.', '..', 'file.txt', 'sed'])
56
def test_mkfile(self):
57
new = self.root.createFile('fred.txt')
58
nodes = self.root.children()
59
paths = [path for (path, node) in nodes]
61
self.assertEquals(paths, ['.', '..', 'file.txt', 'fred.txt', 'ned'])
63
def test_writefile(self):
64
new = self.root.createFile('fred.txt')
66
new.writeChunk(0, 'roar')
69
text = new.readChunk(0, 100)
71
self.assertEquals(text, 'roar')
73
def test_readfile(self):
74
fh = self.root.child('file.txt')
76
text = fh.readChunk(0, 100)
78
self.assertEquals(text, 'wobble\n')
80
def test_exists(self):
81
self.failUnless(self.root.exists('file.txt'))
82
self.failIf(self.root.exists('noodle'))
86
class InMemVFSTest(OSVFSTest):
89
root = inmem.FakeDirectory()
90
ned = inmem.FakeDirectory('ned', root)
91
f = inmem.FakeFile('file.txt', root, 'wobble\n')
92
root._children = { 'ned' : ned, 'file.txt' : f }