Commit 96ddcde9 authored by Léo-Paul Géneau's avatar Léo-Paul Géneau 👾 Committed by Kirill Smelkov

Fix encoding error in Python2

Using decode method on subprocess.checkoutput() throws an encoding error
in Python2 when returned value contains non ascii caracters

/reviewed-by @kirr
/reviewed-on nexedi/rubygemsrecipe!6
parent cdfcc3c3
......@@ -59,7 +59,7 @@ class Recipe(object):
env.update(environ)
try:
cmd_result = subprocess.check_output(cmd, env=env).decode()
return subprocess.check_output(cmd, env=env, universal_newlines=True)
except OSError as e:
raise zc.buildout.UserError(
'System error, command failed: %s: %s' % (e, cmd))
......@@ -75,7 +75,6 @@ class Recipe(object):
'System error, command failed with exit code %s: %s'
% (e.returncode, e.cmd)
)
return cmd_result
def update(self):
pass
......
Successfully built RubyGem
Name: bundler
Version: 2.1.2
File: bundler-2.1.2.gem
Bundler 2.1.2 installed
RubyGems 3.1.2 installed
Regenerating binstubs
=== 3.1.2 / 2019-12-20
Minor enhancements:
* Restore non prompting `gem update --system` behavior. Pull request #3040
by David Rodríguez.
* Show only release notes for new code installed. Pull request #3041 by
David Rodríguez.
* Inform about installed `bundle` executable after `gem update --system`.
Pull request #3042 by David Rodríguez.
* Use Bundler 2.1.2. Pull request #3043 by SHIBATA Hiroshi.
Bug fixes:
* Require `uri` in source.rb. Pull request #3034 by mihaibuzgau.
* Fix `gem update --system --force`. Pull request #3035 by David
Rodríguez.
* Move `require uri` to source_list. Pull request #3038 by mihaibuzgau.
=== 3.1.1 / 2019-12-16
Bug fixes:
* Vendor Bundler 2.1.0 again. The version of Bundler with
RubyGems 3.1.0 was Bundler 2.1.0.pre.3. Pull request #3029 by
SHIBATA Hiroshi.
------------------------------------------------------------------------------
\ No newline at end of file
......@@ -271,22 +271,14 @@ class fixture(object):
shutil.rmtree(str(self.tempdir))
class RubyGemsTests(unittest.TestCase):
class RubyGemsTestCase(unittest.TestCase):
def check_output_test(self, check_output_mock, expected_arg_list_list):
self.assertEqual(check_output_mock.call_count,
len(expected_arg_list_list))
for command_nb, expected_arg_list in enumerate(
for mock_call, expected_arg_list in zip(check_output_mock.mock_calls,
expected_arg_list_list):
# half of the mock calls come from the use of 'decode' method
self.assertEqual(
check_output_mock.mock_calls[2*command_nb][1][0],
expected_arg_list
)
self.assertEqual(
str(check_output_mock.mock_calls[2*command_nb+1]),
'call().decode()'
)
self.assertEqual(mock_call[1][0], expected_arg_list)
def install_with_default_rubygems_test(self, path, patches,
expected_install_arg_list_list):
......@@ -390,7 +382,7 @@ class RubyGemsTests(unittest.TestCase):
recipe = rubygems.Recipe(buildout, name, options)
recipe.install()
@fixture({'recipe': {'gems': 'sass', 'version': '2.0.0'}})
@fixture({'recipe': {'gems': 'sass'}, 'version': '2.0.0'})
def test_version(self, path, patches, buildout, name, options):
recipe = rubygems.Recipe(buildout, name, options)
recipe.install()
......@@ -434,6 +426,20 @@ class RubyGemsTests(unittest.TestCase):
self.assertEqual(matched.group(), '--version=1.0')
break
@fixture({'recipe': {'gems': 'sass'}, 'version': '3.1.2'})
def test_non_ascii_encoding(self, path, patches, buildout, name, options):
rubygems_setup_output_path = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
'test_data',
'rubygems_3.1.2_setup_output.txt'
)
with open(rubygems_setup_output_path) as fd:
rubygems_setup_output = fd.read()
patches['check_output'].return_value = rubygems_setup_output
recipe = rubygems.Recipe(buildout, name, options)
recipe.install()
@fixture({'recipe': {'gems': 'sass', 'deployment': 'true'}})
def test_deployment_not_pinned_version_error(
self, path, patches, buildout, name, options):
......
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