summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Lange <jml@canonical.com>2012-07-05 10:37:37 +0100
committerJonathan Lange <jml@canonical.com>2012-07-05 10:37:37 +0100
commita1ed4d043ec95e93cf7d90b15e2c024612c8e691 (patch)
tree9ea1f882af50c20dafab5d211262b5433c25dbae
parent6f22ef9078aa1653d0139d44c6c97b743c50785a (diff)
downloadfixtures-a1ed4d043ec95e93cf7d90b15e2c024612c8e691.tar.gz
Start writing stuff to disk
-rw-r--r--lib/fixtures/_fixtures/filetree.py19
-rw-r--r--lib/fixtures/tests/_fixtures/test_filetree.py25
2 files changed, 42 insertions, 2 deletions
diff --git a/lib/fixtures/_fixtures/filetree.py b/lib/fixtures/_fixtures/filetree.py
index 7b09e5d..188ef44 100644
--- a/lib/fixtures/_fixtures/filetree.py
+++ b/lib/fixtures/_fixtures/filetree.py
@@ -17,8 +17,23 @@ __all__ = [
'FileTree',
]
+import os
-class FileTree(object):
+from fixtures import Fixture
+from fixtures._fixtures.tempdir import TempDir
+
+
+class FileTree(Fixture):
def __init__(self, shape):
- pass
+ super(FileTree, self).__init__()
+ self._shape = shape
+
+ def setUp(self):
+ super(FileTree, self).setUp()
+ tempdir = self.useFixture(TempDir())
+ self.path = path = tempdir.path
+ for filename, contents in self._shape:
+ f = open(os.path.join(path, filename), 'w')
+ f.write(contents)
+ f.close()
diff --git a/lib/fixtures/tests/_fixtures/test_filetree.py b/lib/fixtures/tests/_fixtures/test_filetree.py
index 9e9a5cd..c6cecd6 100644
--- a/lib/fixtures/tests/_fixtures/test_filetree.py
+++ b/lib/fixtures/tests/_fixtures/test_filetree.py
@@ -13,7 +13,15 @@
# license you chose for the specific language governing permissions and
# limitations under that license.
+import os
+
from testtools import TestCase
+from testtools.matchers import (
+ DirContains,
+ DirExists,
+ FileContains,
+ Not,
+ )
from fixtures import FileTree
from fixtures.tests.helpers import NotHasattr
@@ -24,3 +32,20 @@ class TestFileTree(TestCase):
def test_no_path_at_start(self):
fixture = FileTree([])
self.assertThat(fixture, NotHasattr('path'))
+
+ def test_creates_directory(self):
+ fixture = FileTree([])
+ fixture.setUp()
+ try:
+ self.assertThat(fixture.path, DirExists())
+ finally:
+ fixture.cleanUp()
+ self.assertThat(fixture.path, Not(DirExists()))
+
+ def test_creates_files(self):
+ fixture = FileTree([('a', 'foo'), ('b', 'bar')])
+ with fixture:
+ path = fixture.path
+ self.assertThat(path, DirContains(['a', 'b']))
+ self.assertThat(os.path.join(path, 'a'), FileContains('foo'))
+ self.assertThat(os.path.join(path, 'b'), FileContains('bar'))