1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
-*- rst -*-
===========
treeshape
===========
treeshape allows you to quickly make file and directory structures on disk.
For example::
from treeshape import (
CONTENT,
make_tree,
PERMISSIONS,
)
make_tree('.', {
'logs/': None,
'README': {CONTENT: "A simple directory layout\n"},
'data/input': {CONTENT: "All of our input data\n"},
'bin/script': {CONTENT: "#!/bin/sh\necho 'Hello'\n", PERMISSIONS: 0755},
})
Will create a directory structure that looks like this::
$ find .
.
./logs
./data
./data/input
./README
$ cat README
A simple directory layout
$ cat data/input
All of our input data
This is particularly useful for tests that touch the disk.
If being explicit isn't really your thing, you can also create the same
directory structure from a rough specification::
from treeshape import (
from_rough_spec,
make_tree,
)
make_tree('.', from_rough_spec([
'logs/',
('README', "A simple directory layout\n"),
('data/input', "All of our input data\n"),
('bin/script', "#!/bin/sh\necho 'Hello'\n", 0755),
]))
This is also provided as a ``Fixture`` (see python-fixtures_). Thus, if you
are using testtools_, then you can also do this during your tests::
def test_a_thing(self):
self.useFixture(FileTree(from_rough_spec([
'logs/',
('README', "A simple directory layout\n"),
('data/input', "All of our input data\n"),
])))
# your test here
.. _python-fixtures: http://pypi.python.org/pypi/fixtures
.. _testtools: http://pypi.python.org/pypi/testtools
|