comparison examples/doctest.txt @ 65:0152741621c1

check in a failing test wrt location
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 07 Jan 2011 10:17:48 -0800
parents 9a0014a760d1
children a0f7bfa98755
comparison
equal deleted inserted replaced
64:c20277dbf8fa 65:0152741621c1
33 >>> template.substitute(name='fleem') 33 >>> template.substitute(name='fleem')
34 >>> file(buffer).read().strip() 34 >>> file(buffer).read().strip()
35 'Hello fleem' 35 'Hello fleem'
36 >>> os.remove(buffer) 36 >>> os.remove(buffer)
37 37
38 Directory case: 38 Directory case::
39 39
40 >>> exampledir = os.path.join(here, 'directory-example') 40 >>> exampledir = os.path.join(here, 'directory-example')
41 >>> tempdir = tempfile.mkdtemp() 41 >>> tempdir = tempfile.mkdtemp()
42 >>> template = makeitso.PolyTemplate([exampledir], output=tempdir, interactive=False) 42 >>> template = makeitso.PolyTemplate([exampledir], output=tempdir, interactive=False)
43 >>> sorted(template.missing()) 43 >>> sorted(template.missing())
51 ['life.txt'] 51 ['life.txt']
52 >>> file(os.path.join(tempdir, 'mysubdir', 'life.txt')).read().strip() 52 >>> file(os.path.join(tempdir, 'mysubdir', 'life.txt')).read().strip()
53 'It' 53 'It'
54 >>> shutil.rmtree(tempdir) 54 >>> shutil.rmtree(tempdir)
55 55
56 Mixed case: 56 Mixed case::
57 57
58 >>> template = makeitso.PolyTemplate([example, exampledir], interactive=False) 58 >>> template = makeitso.PolyTemplate([example, exampledir], interactive=False)
59 >>> variables = sorted(template.missing()) 59 >>> variables = sorted(template.missing())
60 >>> variables 60 >>> variables
61 ['bar', 'foo', 'name', 'subdir'] 61 ['bar', 'foo', 'name', 'subdir']
62 62
63 You need to provide output for mixing files and directory templates: 63 You need to provide output for mixing files and directory templates::
64 64
65 >>> variables = dict([(i, i.title()) for i in variables]) 65 >>> variables = dict([(i, i.title()) for i in variables])
66 >>> try: 66 >>> try:
67 ... template.substitute(**variables) 67 ... template.substitute(**variables)
68 ... except AssertionError, e: 68 ... except AssertionError, e:
69 ... pass 69 ... pass
70 >>> e 70 >>> e
71 AssertionError('Must specify output ... 71 AssertionError('Must specify output ...
72 72
73 Provide an output: 73 Provide an output::
74 74
75 >>> template = makeitso.PolyTemplate([example, exampledir], output=tempdir, interactive=False) 75 >>> template = makeitso.PolyTemplate([example, exampledir], output=tempdir, interactive=False)
76 >>> template.substitute(**variables) 76 >>> template.substitute(**variables)
77 >>> sorted(os.listdir(tempdir)) 77 >>> sorted(os.listdir(tempdir))
78 ['Subdir', 'example.txt', 'foo.txt'] 78 ['Subdir', 'example.txt', 'foo.txt']
79 >>> shutil.rmtree(tempdir) 79 >>> shutil.rmtree(tempdir)
80
81 Test API templates::
82
83 >>> from makeitso.template import MakeItSoTemplate, Variable
84 >>> class MyTemplate(MakeItSoTemplate):
85 ... name = 'foo'
86 ... templates = ['example.txt']
87 ... vars = [Variable(name='name', default='bar')]
88 >>> apitemplate = MyTemplate()