Mercurial > hg > MakeItSo
changeset 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 | c20277dbf8fa |
children | 7821c82772f5 |
files | examples/doctest.txt makeitso/template.py |
diffstat | 2 files changed, 22 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/examples/doctest.txt Thu Jan 06 18:04:58 2011 -0800 +++ b/examples/doctest.txt Fri Jan 07 10:17:48 2011 -0800 @@ -35,7 +35,7 @@ 'Hello fleem' >>> os.remove(buffer) -Directory case: +Directory case:: >>> exampledir = os.path.join(here, 'directory-example') >>> tempdir = tempfile.mkdtemp() @@ -53,14 +53,14 @@ 'It' >>> shutil.rmtree(tempdir) -Mixed case: +Mixed case:: >>> template = makeitso.PolyTemplate([example, exampledir], interactive=False) >>> variables = sorted(template.missing()) >>> variables ['bar', 'foo', 'name', 'subdir'] -You need to provide output for mixing files and directory templates: +You need to provide output for mixing files and directory templates:: >>> variables = dict([(i, i.title()) for i in variables]) >>> try: @@ -70,10 +70,19 @@ >>> e AssertionError('Must specify output ... -Provide an output: +Provide an output:: >>> template = makeitso.PolyTemplate([example, exampledir], output=tempdir, interactive=False) >>> template.substitute(**variables) >>> sorted(os.listdir(tempdir)) ['Subdir', 'example.txt', 'foo.txt'] >>> shutil.rmtree(tempdir) + +Test API templates:: + + >>> from makeitso.template import MakeItSoTemplate, Variable + >>> class MyTemplate(MakeItSoTemplate): + ... name = 'foo' + ... templates = ['example.txt'] + ... vars = [Variable(name='name', default='bar')] + >>> apitemplate = MyTemplate()
--- a/makeitso/template.py Thu Jan 06 18:04:58 2011 -0800 +++ b/makeitso/template.py Fri Jan 07 10:17:48 2011 -0800 @@ -9,8 +9,8 @@ class Undefined(object): """marker class for variables""" - def __int__(self): - return 0 + def __nonzero__(self): + return False Undefined = Undefined() # singleton class Variable(object): @@ -75,6 +75,7 @@ # boilerplate assert self.templates + variables = variables or {} self.output = output self.interactive = interactive self.location = os.path.dirname(os.path.abspath(__file__)) @@ -87,14 +88,17 @@ self.vardict[i.name] = i # ensure all of these templates exist + self._templates = [] for template in self.templates: if template.startswith('http://') or template.startswith('https://'): + self._templates.append(template) continue if os.path.isabs(template): path = template else: path = os.path.join(self.location, template) - assert os.path.exists(template) + assert os.path.exists(path), "%s does not exist" % path + self._templates.append(path) def get_variables(self, **variables): # XXX could do this in the ctor @@ -127,6 +131,7 @@ def substitute(self, **variables): """do the substitution""" + vars = self.get_variables(**variables) self.pre(**vars) self.check_missing(vars) @@ -135,8 +140,7 @@ PolyTemplate(self.templates, output=self.output, interactive=self.interactive, - variables = vars - + variables=vars) self.post(**variables)