Commit f84536b8 authored by Bryton Lacquement's avatar Bryton Lacquement 🚪 Committed by Julien Muchembled

More Py3 fixes

parent 9c49c425
......@@ -69,7 +69,7 @@ For example::
recipe = slapos.recipe.build
example = foobar's one
script =
print '%%s' %% self.options['example']
print('%%s' %% self.options['example'])
# will print “foobar's one”
[no-escaping]
......@@ -78,9 +78,9 @@ For example::
foo = bar
format = no
script =
print '%s' % self.options['example']
print('%s' % self.options['example'])
# will print “foobar's one”
print '%(foo)s'
print('%(foo)s')
# will print “%(foo)s”
Pure download
......@@ -150,7 +150,7 @@ the recipe will pick up the latest commit on the remote master branch::
This will clone the git repository in `parts/git-clone` directory.
Then let's run the buildout::
>>> print system(buildout)
>>> print(system(buildout))
Installing git-clone.
Cloning into '/sample-buildout/parts/git-clone'...
......@@ -161,7 +161,7 @@ Let's take a look at the buildout parts directory now::
When updating, it will do a "git fetch; git reset @{upstream}"::
>>> print system(buildout)
>>> print(system(buildout))
Updating git-clone.
Fetching origin
HEAD is now at ...
......@@ -185,7 +185,7 @@ run it will take the latest commit on this remote branch::
Then let's run the buildout::
>>> print system(buildout)
>>> print(system(buildout))
Uninstalling git-clone.
Running uninstall recipe.
Installing git-clone.
......@@ -200,13 +200,13 @@ And let's see that current branch is "build"::
>>> import subprocess
>>> cd('parts', 'git-clone')
>>> print subprocess.check_output(['git', 'branch'])
>>> print(subprocess.check_output(['git', 'branch'], universal_newlines=True))
* build
When updating, it will do a "git fetch; git reset build"::
>>> cd(sample_buildout)
>>> print system(buildout)
>>> print(system(buildout))
Updating git-clone.
Fetching origin
HEAD is now at ...
......@@ -231,7 +231,7 @@ This option has priority over the "branch" option::
Then let's run the buildout::
>>> print system(buildout)
>>> print(system(buildout))
Uninstalling git-clone.
Running uninstall recipe.
Installing git-clone.
......@@ -246,13 +246,13 @@ And let's see that current revision is "2566127"::
>>> import subprocess
>>> cd(sample_buildout, 'parts', 'git-clone')
>>> print subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD'])
>>> print(subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD'], universal_newlines=True))
2566127
When updating, it will do a "git fetch; git reset revision"::
>>> cd(sample_buildout)
>>> print system(buildout)
>>> print(system(buildout))
Updating git-clone.
...
HEAD is now at 2566127 ...
......@@ -283,14 +283,14 @@ extend an existing section specifying a branch)::
... branch = master
... """)
>>> print system(buildout)
>>> print(system(buildout))
Uninstalling git-clone.
Running uninstall recipe.
Installing git-clone.
Cloning into '/sample-buildout/parts/git-clone'...
>>> cd(sample_buildout, 'parts', 'git-clone')
>>> print system('git branch')
>>> print(system('git branch'))
* master
Revision/branch priority
......@@ -312,7 +312,7 @@ and branch parameter is ignored::
... revision = 2566127
... """)
>>> print system(buildout)
>>> print(system(buildout))
Uninstalling git-clone.
Running uninstall recipe.
Installing git-clone.
......@@ -321,7 +321,7 @@ and branch parameter is ignored::
HEAD is now at 2566127 ...
>>> cd(sample_buildout, 'parts', 'git-clone')
>>> print system('git branch')
>>> print(system('git branch'))
* master
Setup a "develop" repository
......@@ -351,7 +351,7 @@ erase your local modifications by specifying the "develop" flag::
... develop = true
... """)
>>> print system(buildout)
>>> print(system(buildout))
Uninstalling git-clone.
Running uninstall recipe.
Installing git-clone.
......@@ -361,10 +361,10 @@ Buildout will then keep local modifications, instead of resetting the
repository::
>>> cd(sample_buildout, 'parts', 'git-clone')
>>> print system('echo foo > setup.py')
>>> print(system('echo foo > setup.py'))
>>> cd(sample_buildout)
>>> print system(buildout)
>>> print(system(buildout))
Updating git-clone.
Fetching origin
...
......@@ -372,26 +372,26 @@ repository::
>>> cd(sample_buildout, 'parts', 'git-clone')
>>> print system('cat setup.py')
>>> print(system('cat setup.py'))
foo
Then, when update occurs, nothing is done::
>>> cd(sample_buildout, 'parts', 'git-clone')
>>> print system('echo kept > local_change')
>>> print(system('echo kept > local_change'))
>>> print system('git remote add broken http://git.erp5.org/repos/nowhere')
>>> print(system('git remote add broken http://git.erp5.org/repos/nowhere'))
...
>>> cd(sample_buildout)
>>> print system(buildout)
>>> print(system(buildout))
Updating git-clone.
Fetching origin
Fetching broken
Unable to update:
Traceback (most recent call last):
...
CalledProcessError: Command '['git', 'fetch', '--all']' returned non-zero exit status 1
...CalledProcessError: Command '['git', 'fetch', '--all']' returned non-zero exit status 1
<BLANKLINE>
...
fatal: unable to access 'http://git.erp5.org/repos/nowhere/': The requested URL returned error: 500
......@@ -399,7 +399,7 @@ Then, when update occurs, nothing is done::
<BLANKLINE>
>>> cd(sample_buildout, 'parts', 'git-clone')
>>> print system('cat local_change')
>>> print(system('cat local_change'))
kept
In case of uninstall, buildout will keep the repository directory::
......@@ -418,7 +418,7 @@ In case of uninstall, buildout will keep the repository directory::
... foo = bar
... """)
>>> print system(buildout)
>>> print(system(buildout))
Uninstalling git-clone.
Running uninstall recipe.
You have uncommited changes in /sample-buildout/parts/git-clone. This folder will be left as is.
......
......@@ -64,22 +64,16 @@ class GitCloneNonInformativeTests(unittest.TestCase):
recipe = self.makeGitCloneRecipe({"use-cache": "true",
"repository": BAD_GIT_REPOSITORY})
os.chdir(self.dir)
try:
with self.assertRaises(zc.buildout.UserError) as cm:
recipe.install()
# Should have raised before.
self.assertTrue(False)
except zc.buildout.UserError as e:
self.assertEqual(e.message, GIT_CLONE_CACHE_ERROR_MESSAGE)
self.assertEqual(str(cm.exception), GIT_CLONE_CACHE_ERROR_MESSAGE)
def test_not_using_download_cache_if_forbidden(self):
recipe = self.makeGitCloneRecipe({"repository": BAD_GIT_REPOSITORY})
os.chdir(self.dir)
try:
with self.assertRaises(zc.buildout.UserError) as cm:
recipe.install()
# Should have raised before.
self.assertTrue(False)
except zc.buildout.UserError as e:
self.assertEqual(e.message, GIT_CLONE_ERROR_MESSAGE)
self.assertEqual(str(cm.exception), GIT_CLONE_ERROR_MESSAGE)
def test_cleanup_of_pyc_files(self):
recipe = self.makeGitCloneRecipe({})
......@@ -101,9 +95,9 @@ class GitCloneNonInformativeTests(unittest.TestCase):
# Monkey patch check_call
original_check_call = slapos.recipe.gitclone.check_call
check_call_paramater_list = []
check_call_parameter_list = []
def patch_check_call(*args, **kw):
check_call_paramater_list.extend([args, kw])
check_call_parameter_list.extend((args, kw))
original_check_call(args[0])
slapos.recipe.gitclone.check_call = patch_check_call
......@@ -116,19 +110,15 @@ class GitCloneNonInformativeTests(unittest.TestCase):
options = {
'repository': GIT_REPOSITORY,
"ignore-ssl-certificate": str(ignore_ssl_certificate).lower(),
"repository": GIT_REPOSITORY
}
recipe = slapos.recipe.gitclone.Recipe(bo, 'test', options)
recipe.install()
# Check git clone parameters
if ignore_ssl_certificate:
self.assertTrue("--config" in check_call_paramater_list[0][0])
self.assertTrue("http.sslVerify=false" in check_call_paramater_list[0][0])
else:
self.assertTrue(not "--config" in check_call_paramater_list[0][0])
self.assertTrue(not "http.sslVerify=false" in check_call_paramater_list[0][0])
_ = self.assertIn if ignore_ssl_certificate else self.assertNotIn
_("--config", check_call_parameter_list[0][0])
_("http.sslVerify=false", check_call_parameter_list[0][0])
# Restore original check_call method
slapos.recipe.gitclone.check_call = original_check_call
......
......@@ -250,16 +250,16 @@ class Signature:
return m.hexdigest()
def dumps(self):
return '\n'.join(self.item_list)
return b'\n'.join(self.item_list)
def test(self, folder_path):
digest = self.hexdigest()
if os.path.basename(folder_path) == digest:
if os.path.basename(folder_path).encode('utf-8') == digest:
target_path = os.path.join(folder_path, self.filename)
if os.path.exists(target_path) and open(target_path).read() == self.dumps():
if os.path.exists(target_path) and open(target_path, 'rb').read() == self.dumps():
return True
return False
def save(self, folder_path):
with open(os.path.join(folder_path, self.filename), 'w') as f:
with open(os.path.join(folder_path, self.filename), 'wb') as f:
f.write(self.dumps())
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