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

Fix: make gem_search_pattern compatible with rubygems > 3.0

Search pattern for a gem name for rubygems > 3.0 is in format ^gem_name$ instead
of /^gem_name$/ for rubygems < 3.0

/reviewed-by @kirr
/reviewed-on !6
parent 158851a4
......@@ -207,6 +207,7 @@ class Recipe(object):
}
recipe = Download(self.buildout, self.name, options)
recipe.install()
self.version = version
current_dir = os.getcwd()
try:
......@@ -292,13 +293,17 @@ class Recipe(object):
return gem_executable[0]
def get_dependency_list(self, gem_dict, gem_executable):
gem_search_pattern = '^' + gem_dict['gemname'].replace('.',r'\.') + '$'
if self.version[0] < '3':
gem_search_pattern = '/' + gem_search_pattern + '/'
cmd = [
self.ruby_executable,
gem_executable,
'dependency',
'-rv',
gem_dict['version'],
'/^' + gem_dict['gemname'].replace('.',r'\.') + '$/',
gem_search_pattern,
]
cmd_result = self.run(cmd, self._get_env())
......
......@@ -31,10 +31,10 @@ class fixture(object):
def __call__(self, func):
@functools.wraps(func)
def wrapper(test):
buildout, name, options = self.set_up()
buildout, name, options, version = self.set_up()
cwd = os.getcwd()
os.chdir(str(self.tempdir))
func(test, self.tempdir, self.patches, buildout, name, options)
func(test, self.tempdir, self.patches, buildout, name, options, version)
os.chdir(cwd)
self.tear_down()
return wrapper
......@@ -78,7 +78,7 @@ class fixture(object):
options = self.options.get('recipe', {})
return buildout, name, options
return buildout, name, options, version
def tear_down(self):
for patcher in self.patchers.values():
......@@ -122,7 +122,7 @@ class RubyGemsTestCase(unittest.TestCase):
class RubyGemsDefaultTestCase(RubyGemsTestCase):
@fixture({'recipe': {'gems': 'sass'}})
def test_success(self, path, patches, buildout, name, options):
def test_success(self, path, patches, buildout, name, options, version):
recipe = rubygems.Recipe(buildout, name, options)
recipe.install()
......@@ -137,7 +137,7 @@ class RubyGemsDefaultTestCase(RubyGemsTestCase):
path, patches, expected_install_arg_list_list)
@fixture({'recipe': {}})
def test_missing_gems(self, path, patches, buildout, name, options):
def test_missing_gems(self, path, patches, buildout, name, options, version):
self.assertRaisesRegexp(
zc.buildout.UserError,
"Configuration error, 'gems' option is missing",
......@@ -145,7 +145,7 @@ class RubyGemsDefaultTestCase(RubyGemsTestCase):
)
@fixture({'recipe': {'gems': 'sass'}})
def test_oserror(self, path, patches, buildout, name, options):
def test_oserror(self, path, patches, buildout, name, options, version):
patches['check_output'].side_effect = OSError
recipe = rubygems.Recipe(buildout, name, options)
self.assertRaisesRegexp(
......@@ -155,7 +155,7 @@ class RubyGemsDefaultTestCase(RubyGemsTestCase):
)
@fixture({'recipe': {'gems': 'sass'}})
def test_signal_received(self, path, patches, buildout, name, options):
def test_signal_received(self, path, patches, buildout, name, options, version):
exception = subprocess.CalledProcessError(-1, '')
patches['check_output'].side_effect = exception
recipe = rubygems.Recipe(buildout, name, options)
......@@ -166,7 +166,7 @@ class RubyGemsDefaultTestCase(RubyGemsTestCase):
)
@fixture({'recipe': {'gems': 'sass'}})
def test_non_zero_exitcode(self, path, patches, buildout, name, options):
def test_non_zero_exitcode(self, path, patches, buildout, name, options, version):
exception = subprocess.CalledProcessError(1, '')
patches['check_output'].side_effect = exception
recipe = rubygems.Recipe(buildout, name, options)
......@@ -177,12 +177,12 @@ class RubyGemsDefaultTestCase(RubyGemsTestCase):
)
@fixture({'recipe': {'gems': 'sass'}})
def test_update(self, path, patches, buildout, name, options):
def test_update(self, path, patches, buildout, name, options, version):
recipe = rubygems.Recipe(buildout, name, options)
recipe.update()
@fixture({'recipe': {'gems': 'sass', 'environment': 'invalid'}})
def test_invalid_environment(self, path, patches, buildout, name, options):
def test_invalid_environment(self, path, patches, buildout, name, options, version):
recipe = rubygems.Recipe(buildout, name, options)
self.assertRaisesRegexp(
zc.buildout.UserError,
......@@ -195,17 +195,17 @@ class RubyGemsDefaultTestCase(RubyGemsTestCase):
'gems': 'sass',
'url': 'https://rubygems.org/rubygems/rubygems-2.0.0.zip',
}})
def test_version_from_url(self, path, patches, buildout, name, options):
def test_version_from_url(self, path, patches, buildout, name, options, version):
recipe = rubygems.Recipe(buildout, name, options)
recipe.install()
@fixture({'recipe': {'gems': 'sass'}, 'version': '2.0.0'})
def test_version(self, path, patches, buildout, name, options):
def test_version(self, path, patches, buildout, name, options, version):
recipe = rubygems.Recipe(buildout, name, options)
recipe.install()
@fixture({'recipe': {'gems': 'sass'}})
def test_no_version(self, path, patches, buildout, name, options):
def test_no_version(self, path, patches, buildout, name, options, version):
patches['urlopen'].return_value = BytesIO(b'')
recipe = rubygems.Recipe(buildout, name, options)
self.assertRaisesRegexp(zc.buildout.UserError,
......@@ -215,7 +215,7 @@ class RubyGemsDefaultTestCase(RubyGemsTestCase):
@fixture({'recipe': {'gems': 'sass'}})
@mock.patch('rubygems.os.mkdir')
def test_mkdir_error(self, path, patches, buildout, name, options, mkdir):
def test_mkdir_error(self, path, patches, buildout, name, options, version, mkdir):
mkdir.side_effect = OSError(errno.EIO)
recipe = rubygems.Recipe(buildout, name, options)
self.assertRaisesRegexp(
......@@ -225,13 +225,13 @@ class RubyGemsDefaultTestCase(RubyGemsTestCase):
)
@fixture({'recipe': {'gems': 'sass'}})
def test_executables(self, path, patches, buildout, name, options):
def test_executables(self, path, patches, buildout, name, options, version):
recipe = rubygems.Recipe(buildout, name, options)
touch(pathlib.Path(recipe.options['location']) / 'bin/sass')
recipe.install()
@fixture({'recipe': {'gems': 'sass==1.0'}})
def test_pinned_versions(self, path, patches, buildout, name, options):
def test_pinned_versions(self, path, patches, buildout, name, options, version):
recipe = rubygems.Recipe(buildout, name, options)
touch(path / 'rubygems/bin/gem')
recipe.install()
......@@ -244,7 +244,7 @@ class RubyGemsDefaultTestCase(RubyGemsTestCase):
break
@fixture({'recipe': {'gems': 'sass'}, 'version': '3.1.2'})
def test_non_ascii_encoding(self, path, patches, buildout, name, options):
def test_non_ascii_encoding(self, path, patches, buildout, name, options, version):
rubygems_setup_output_path = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
'test_data',
......@@ -269,24 +269,28 @@ class deployment_fixture(fixture):
return dependency_output
def set_up(self):
buildout, name, options = super(deployment_fixture, self).set_up()
buildout, name, options, version = super(deployment_fixture, self).set_up()
options['deployment'] = 'true'
self.patches['check_output'].side_effect = self.mocked_check_output_for_dependencies
return buildout, name, options
return buildout, name, options, version
class RubyGemsDeploymentTestCase(RubyGemsTestCase):
def deployment_install_test(self, buildout, name, path, patches, options):
def deployment_install_test(self, buildout, name, path, patches, options, version):
recipe = rubygems.Recipe(buildout, name, options)
recipe.install()
expected_install_arg_list_list = []
gem_dict_list = list(map(recipe.get_gem_dict, recipe.gems))
for gem_dict in gem_dict_list:
gem_search_pattern = '^' + gem_dict['gemname'].replace('.',r'\.') + '$'
if version[0] < '3':
gem_search_pattern = '/' + gem_search_pattern + '/'
expected_install_arg_list_list.extend([
[
'ruby', None, 'dependency', '-rv', gem_dict['version'],
'/^%s$/' % gem_dict['gemname'].replace('.',r'\.'),
gem_search_pattern,
], [
'ruby', None, 'install', '--no-document',
'--bindir=%s/rubygems/bin' % path,
......@@ -300,7 +304,7 @@ class RubyGemsDeploymentTestCase(RubyGemsTestCase):
@deployment_fixture({'recipe': {'gems': 'sass'}})
def test_deployment_not_pinned_version_error(
self, path, patches, buildout, name, options):
self, path, patches, buildout, name, options, version):
recipe = rubygems.Recipe(buildout, name, options)
self.assertRaisesRegexp(
zc.buildout.UserError,
......@@ -310,7 +314,7 @@ class RubyGemsDeploymentTestCase(RubyGemsTestCase):
@deployment_fixture({'recipe': {'gems': 'rash==0.1.0'}})
def test_deployment_not_pinned_dependency_error(
self, path, patches, buildout, name, options):
self, path, patches, buildout, name, options, version):
recipe = rubygems.Recipe(buildout, name, options)
self.assertRaisesRegexp(
zc.buildout.UserError,
......@@ -320,7 +324,7 @@ class RubyGemsDeploymentTestCase(RubyGemsTestCase):
@deployment_fixture({'recipe': {'gems': 'rash==0.1.0 hashie==0.3.0'}})
def test_deployment_more_or_equal_constraint_error(
self, path, patches, buildout, name, options):
self, path, patches, buildout, name, options, version):
recipe = rubygems.Recipe(buildout, name, options)
self.assertRaisesRegexp(
zc.buildout.UserError,
......@@ -331,12 +335,13 @@ class RubyGemsDeploymentTestCase(RubyGemsTestCase):
@deployment_fixture({'recipe': {'gems': 'rash==0.1.0 hashie==0.3.1'}})
def test_deployment_more_or_equal_constraint_success(
self, path, patches, buildout, name, options):
self.deployment_install_test(buildout, name, path, patches, options)
self, path, patches, buildout, name, options, version):
self.deployment_install_test(
buildout, name, path, patches, options, version)
@deployment_fixture({'recipe': {'gems': 'rash==0.3.0 hashie==1.1.0'}})
def test_deployment_similar_constraint_error(
self, path, patches, buildout, name, options):
self, path, patches, buildout, name, options, version):
recipe = rubygems.Recipe(buildout, name, options)
self.assertRaisesRegexp(
zc.buildout.UserError,
......@@ -347,8 +352,9 @@ class RubyGemsDeploymentTestCase(RubyGemsTestCase):
@deployment_fixture({'recipe': {'gems': 'rash==0.3.0 hashie==1.0.0'}})
def test_deployment_similar_constraint_success(
self, path, patches, buildout, name, options):
self.deployment_install_test(buildout, name, path, patches, options)
self, path, patches, buildout, name, options, version):
self.deployment_install_test(
buildout, name, path, patches, options, version)
@deployment_fixture({'recipe': {
'gems': 'activesupport==3.2.0 atomic==0.0.1 cucumber-gherkin==9.1.0 '
......@@ -357,7 +363,7 @@ class RubyGemsDeploymentTestCase(RubyGemsTestCase):
'thor==0.9.2 thread_safe==0.1.0'
}})
def test_deployment_more_or_equal_constraint_error(
self, path, patches, buildout, name, options):
self, path, patches, buildout, name, options, version):
recipe = rubygems.Recipe(buildout, name, options)
self.assertRaisesRegexp(
zc.buildout.UserError,
......@@ -374,12 +380,13 @@ class RubyGemsDeploymentTestCase(RubyGemsTestCase):
'thor==0.9.2 thread_safe==0.1.0'
}})
def test_deployment_more_or_equal_constraint_success(
self, path, patches, buildout, name, options):
self.deployment_install_test(buildout, name, path, patches, options)
self, path, patches, buildout, name, options, version):
self.deployment_install_test(
buildout, name, path, patches, options, version)
@deployment_fixture({'recipe': {'gems': 'hoe==3.4.0 rake==11.0.0'}})
def test_deployment_less_constraint_error(
self, path, patches, buildout, name, options):
self, path, patches, buildout, name, options, version):
recipe = rubygems.Recipe(buildout, name, options)
self.assertRaisesRegexp(
zc.buildout.UserError,
......@@ -390,15 +397,16 @@ class RubyGemsDeploymentTestCase(RubyGemsTestCase):
@deployment_fixture({'recipe': {'gems': 'hoe==3.4.0 rake==10.0.1'}})
def test_deployment_less_constraint_success(
self, path, patches, buildout, name, options):
self.deployment_install_test(buildout, name, path, patches, options)
self, path, patches, buildout, name, options, version):
self.deployment_install_test(
buildout, name, path, patches, options, version)
@deployment_fixture({'recipe': {
'gems': 'cucumber-core==3.0.0 backports==3.8.0 '
'cucumber-tag_expressions==1.0.1 gherkin==8.0.0'
}})
def test_deployment_not_pinned_subdependency_error(
self, path, patches, buildout, name, options):
self, path, patches, buildout, name, options, version):
recipe = rubygems.Recipe(buildout, name, options)
self.assertRaisesRegexp(
zc.buildout.UserError,
......@@ -413,8 +421,9 @@ class RubyGemsDeploymentTestCase(RubyGemsTestCase):
'cucumber-messages==6.0.1'
}})
def test_deployment_pinned_subdependency_success(
self, path, patches, buildout, name, options):
self.deployment_install_test(buildout, name, path, patches, options)
self, path, patches, buildout, name, options, version):
self.deployment_install_test(
buildout, name, path, patches, options, version)
@deployment_fixture({'recipe': {
'gems': 'activesupport==3.2.0 atomic==0.0.1 cucumber-core==7.1.0 '
......@@ -424,7 +433,7 @@ class RubyGemsDeploymentTestCase(RubyGemsTestCase):
'thread_safe==0.1.0'
}})
def test_deployment_subdependency_constraint_error(
self, path, patches, buildout, name, options):
self, path, patches, buildout, name, options, version):
recipe = rubygems.Recipe(buildout, name, options)
self.assertRaisesRegexp(
zc.buildout.UserError,
......@@ -442,8 +451,9 @@ class RubyGemsDeploymentTestCase(RubyGemsTestCase):
'thread_safe==0.1.0'
}})
def test_deployment_subdependency_constraint_success(
self, path, patches, buildout, name, options):
self.deployment_install_test(buildout, name, path, patches, options)
self, path, patches, buildout, name, options, version):
self.deployment_install_test(
buildout, name, path, patches, options, version)
@deployment_fixture({'recipe': {
'gems': 'activesupport==3.2.0 atomic==0.0.1 cucumber-core==7.1.0 '
......@@ -453,7 +463,7 @@ class RubyGemsDeploymentTestCase(RubyGemsTestCase):
'thread_safe==0.1.0'
}})
def test_deployment_similar_second_constraint_error(
self, path, patches, buildout, name, options):
self, path, patches, buildout, name, options, version):
recipe = rubygems.Recipe(buildout, name, options)
self.assertRaisesRegexp(
zc.buildout.UserError,
......@@ -470,5 +480,5 @@ class RubyGemsDeploymentTestCase(RubyGemsTestCase):
'thread_safe==0.1.0'
}})
def test_deployment_similar_second_constraint_success(
self, path, patches, buildout, name, options):
self.deployment_install_test(buildout, name, path, patches, options)
self, path, patches, buildout, name, options, version):
self.deployment_install_test(buildout, name, path, patches, options, version)
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