Commit 94706ac7 authored by Julien Muchembled's avatar Julien Muchembled

Add support for Python 3

parent 40270cb5
......@@ -46,7 +46,7 @@ And according Jinja2 template (kept simple, control structures are possible)::
We run buildout::
>>> print system(join('bin', 'buildout')),
>>> run_buildout()
Installing template.
And the template has been rendered::
......@@ -177,7 +177,7 @@ Use jinja2 extensions
... extensions = jinja2.ext.do jinja2.ext.loopcontrols
... jinja2.ext.with_
... ''')
>>> print system(join('bin', 'buildout')),
>>> run_buildout()
Uninstalling template.
Installing template.
......@@ -190,8 +190,9 @@ Check file integrity
Compute template's MD5 sum::
>>> write('foo.in', '{{bar}}')
>>> import md5
>>> md5sum = md5.new(open('foo.in', 'r').read()).hexdigest()
>>> from hashlib import md5
>>> with open('foo.in', 'rb') as f:
... md5sum = md5(f.read()).hexdigest()
>>> write('buildout.cfg',
... '''
... [buildout]
......@@ -204,7 +205,7 @@ Compute template's MD5 sum::
... context = key bar buildout:parts
... md5sum = ''' + md5sum + '''
... ''')
>>> print system(join('bin', 'buildout')),
>>> run_buildout()
Uninstalling template.
Installing template.
......@@ -225,7 +226,7 @@ If the md5sum doesn't match, the buildout fail::
... context = key bar buildout:parts
... md5sum = 0123456789abcdef0123456789abcdef
... ''')
>>> print system(join('bin', 'buildout')),
>>> run_buildout()
Uninstalling template.
Installing template.
While:
......@@ -251,14 +252,13 @@ You can specify the mode for rendered file::
... context = key bar buildout:parts
... mode = 205
... ''')
>>> print system(join('bin', 'buildout')),
>>> run_buildout()
Installing template.
And the generated file with have the right permissions::
>>> import stat
>>> import os
>>> print oct(stat.S_IMODE(os.stat('foo').st_mode))
>>> import os, stat
>>> print("0%o" % stat.S_IMODE(os.stat('foo').st_mode))
0205
Note that Buildout will not allow you to have write permission for others
......@@ -288,7 +288,7 @@ imported::
... rendered = bar
... import-list = rawfile library library.in
... ''')
>>> print system(join('bin', 'buildout')),
>>> run_buildout()
Uninstalling template.
Installing template.
>>> cat('bar')
......@@ -309,7 +309,7 @@ Just like context definition, it also works with indirect values::
... rendered = bar
... import-list = file library template-library:path
... ''')
>>> print system(join('bin', 'buildout')),
>>> run_buildout()
Uninstalling template.
Installing template.
>>> cat('bar')
......@@ -353,7 +353,7 @@ All templates can be accessed inside both folders::
... rawfolder dir_a a
... rawfolder dir_b b
... ''')
>>> print system(join('bin', 'buildout')),
>>> run_buildout()
Uninstalling template.
Installing template.
>>> cat('bar')
......@@ -391,7 +391,7 @@ path)::
... rawfolder dir_a a
... rawfolder dir_b b
... ''')
>>> print system(join('bin', 'buildout')),
>>> run_buildout()
Uninstalling template.
Installing template.
>>> cat('bar')
......@@ -421,7 +421,7 @@ will be installed as dependency::
... recipe = zc.buildout:debug
... ''')
>>> print system(join('bin', 'buildout')),
>>> run_buildout()
Uninstalling template.
Installing dependency.
foobar='dependency content'
......@@ -474,7 +474,7 @@ Let's just use ``buildout.cfg`` using this egg::
... [sample]
... recipe = samplerecipe
... ''')
>>> print system(join('bin', 'buildout')),
>>> run_buildout()
Develop: '/sample-buildout/.'
Uninstalling template.
Uninstalling dependency.
......@@ -504,7 +504,7 @@ rendering.
... rendered = foo_once
... once = foo_flag
... ''')
>>> print system(join('bin', 'buildout')), # doctest: +ELLIPSIS
>>> run_buildout() # doctest: +ELLIPSIS
Uninstalling template.
Uninstalling sample.
Getting distribution for 'samplerecipe'.
......@@ -529,8 +529,9 @@ Remove rendered file and re-render::
>>> import os
>>> os.unlink('foo_once')
>>> open('buildout.cfg', 'a').writelines(['extra = useless'])
>>> print system(join('bin', 'buildout')),
>>> with open('buildout.cfg', 'a') as f:
... f.writelines(['extra = useless'])
>>> run_buildout()
Uninstalling template.
Installing template.
The template install returned None. A path or iterable os paths should be returned.
......@@ -544,8 +545,9 @@ Template was not rendered::
Removing the canary allows template to be re-rendered::
>>> os.unlink('foo_flag')
>>> open('buildout.cfg', 'a').writelines(['moreextra = still useless'])
>>> print system(join('bin', 'buildout')),
>>> with open('buildout.cfg', 'a') as f:
... f.writelines(['moreextra = still useless'])
>>> run_buildout()
Uninstalling template.
Installing template.
The template install returned None. A path or iterable os paths should be returned.
......
......@@ -26,7 +26,7 @@ And a simple template::
We run buildout::
>>> print system(join('bin', 'buildout')),
>>> run_buildout()
Installing template.
And the output file has been parsed by buildout itself::
......@@ -54,8 +54,8 @@ Let's write a file template::
Compute its MD5 sum::
>>> import md5
>>> md5sum = md5.new(open('template.in', 'r').read()).hexdigest()
>>> from hashlib import md5
>>> md5sum = md5(open('template.in', 'rb').read()).hexdigest()
Write the ``buildout.cfg`` using slapos.recipe.template::
......@@ -73,7 +73,7 @@ Write the ``buildout.cfg`` using slapos.recipe.template::
And run buildout, and see the result::
>>> print system(join('bin', 'buildout')),
>>> run_buildout()
Uninstalling template.
Installing template.
......@@ -93,7 +93,7 @@ If the md5sum doesn't match, the buildout fail::
... output = template.out
... md5sum = 0123456789abcdef0123456789abcdef
... ''')
>>> print system(join('bin', 'buildout')),
>>> run_buildout()
While:
Installing.
Getting section template.
......@@ -120,15 +120,14 @@ You can specify the mode of the written file::
... mode = 0627
... ''')
>>> print system(join('bin', 'buildout')),
>>> run_buildout()
Uninstalling template.
Installing template.
And the generated file with have the right permissions::
>>> import stat
>>> import os
>>> print oct(stat.S_IMODE(os.stat('template.out').st_mode))
>>> import os, stat
>>> print("0%o" % stat.S_IMODE(os.stat('template.out').st_mode))
0627
Section dependency
......@@ -152,7 +151,7 @@ will be installed as dependency::
... recipe = zc.buildout:debug
... ''')
>>> print system(join('bin', 'buildout')),
>>> run_buildout()
Uninstalling template.
Installing dependency.
foobar='dependency content'
......@@ -204,7 +203,7 @@ Let's just use ``buildout.cfg`` using this egg::
... [sample]
... recipe = samplerecipe
... ''')
>>> print system(join('bin', 'buildout')),
>>> run_buildout()
Develop: '/sample-buildout/.'
Uninstalling template.
Uninstalling dependency.
......
......@@ -92,7 +92,7 @@ class RecipeBaseLoader(BaseLoader):
if path is None or not os.path.exists(path):
raise TemplateNotFound(template)
mtime = os.path.getmtime(path)
with file(path) as f:
with open(path, 'rb') as f:
source = f.read().decode(self.encoding)
return source, path, lambda: mtime == os.path.getmtime(path)
......@@ -211,7 +211,7 @@ class Recipe(object):
os.makedirs(outdir)
mode = self.mode
fd = os.open(self.rendered, os.O_CREAT | os.O_EXCL | os.O_WRONLY,
(0777 if rendered.startswith('#!') else 0666)
(0o777 if rendered.startswith(b'#!') else 0o666)
if mode is None else 0)
try:
os.write(fd, rendered)
......@@ -220,7 +220,7 @@ class Recipe(object):
finally:
os.close(fd)
if self.once:
open(self.once, 'w').close()
open(self.once, 'wb').close()
return
return self.rendered
......
......@@ -24,6 +24,7 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from __future__ import print_function
import doctest
import unittest
from zc.buildout import testing
......@@ -32,6 +33,9 @@ from zope.testing import renormalizing
def setUp(test):
testing.buildoutSetUp(test)
testing.install_develop('slapos.recipe.template', test)
(lambda system, buildout, **kw: test.globs.update(
run_buildout = lambda: print(system(buildout), end='')
))(**test.globs)
def test_suite():
return unittest.TestSuite([
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment