summaryrefslogtreecommitdiff
path: root/lib/fixtures
diff options
context:
space:
mode:
authorJonathan Lange <jml@canonical.com>2012-07-05 10:55:55 +0100
committerJonathan Lange <jml@canonical.com>2012-07-05 10:55:55 +0100
commit49541275b335027bdc84766165a6a2c7ea6b88cb (patch)
tree7bb9929819758eb13273a774c2e0ff27ed6169ed /lib/fixtures
parent41def54ba477c4b2a714e7c1c06fb0a765153980 (diff)
downloadfixtures-git-49541275b335027bdc84766165a6a2c7ea6b88cb.tar.gz
Refactoring.
Some comments in the tests.
Diffstat (limited to 'lib/fixtures')
-rw-r--r--lib/fixtures/_fixtures/filetree.py7
-rw-r--r--lib/fixtures/tests/_fixtures/test_filetree.py8
2 files changed, 10 insertions, 5 deletions
diff --git a/lib/fixtures/_fixtures/filetree.py b/lib/fixtures/_fixtures/filetree.py
index 3c9bc3a..5fee966 100644
--- a/lib/fixtures/_fixtures/filetree.py
+++ b/lib/fixtures/_fixtures/filetree.py
@@ -45,14 +45,11 @@ class FileTree(Fixture):
if isinstance(description, basestring):
name = description
else:
- try:
- name, contents = description
- except ValueError:
- name = description[0]
+ name = description[0]
name = os.path.join(path, name)
if name[-1] == '/':
os.mkdir(name)
else:
f = open(name, 'w')
- f.write(contents)
+ f.write(description[1])
f.close()
diff --git a/lib/fixtures/tests/_fixtures/test_filetree.py b/lib/fixtures/tests/_fixtures/test_filetree.py
index fdbfd28..aab1fb2 100644
--- a/lib/fixtures/tests/_fixtures/test_filetree.py
+++ b/lib/fixtures/tests/_fixtures/test_filetree.py
@@ -30,10 +30,13 @@ from fixtures.tests.helpers import NotHasattr
class TestFileTree(TestCase):
def test_no_path_at_start(self):
+ # FileTree fixture doesn't create a path at the beginning.
fixture = FileTree([])
self.assertThat(fixture, NotHasattr('path'))
def test_creates_directory(self):
+ # It creates a temporary directory once set up. That directory is
+ # removed at cleanup.
fixture = FileTree([])
fixture.setUp()
try:
@@ -43,6 +46,8 @@ class TestFileTree(TestCase):
self.assertThat(fixture.path, Not(DirExists()))
def test_creates_files(self):
+ # When given a list of file specifications, it creates those files
+ # underneath the temporary directory.
fixture = FileTree([('a', 'foo'), ('b', 'bar')])
with fixture:
path = fixture.path
@@ -51,6 +56,7 @@ class TestFileTree(TestCase):
self.assertThat(os.path.join(path, 'b'), FileContains('bar'))
def test_creates_directories(self):
+ # When given directory specifications, it creates those directories.
fixture = FileTree([('a/', None), ('b/',)])
with fixture:
path = fixture.path
@@ -59,6 +65,8 @@ class TestFileTree(TestCase):
self.assertThat(os.path.join(path, 'b'), DirExists())
def test_simpler_directory_syntax(self):
+ # Directory specifications don't have to be tuples. They can be single
+ # strings.
fixture = FileTree(['a/'])
with fixture:
path = fixture.path