Skip to content

Commit

Permalink
test common part of substitutions
Browse files Browse the repository at this point in the history
  • Loading branch information
lennonwoo committed Jul 3, 2019
1 parent d2ef245 commit d1aa11c
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 10 deletions.
7 changes: 4 additions & 3 deletions bloom/generators/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def generate_substitutions_from_package(
warning("No homepage set, defaulting to ''")
data['Homepage'] = homepage
# Increment Number
data['Inc'] = '' if native else '-{0}'.format(inc)
data['Inc'] = '' if native else '{0}'.format(inc)
# Package name
data['Package'] = sanitize_package_name(package.name)
# Installation prefix
Expand Down Expand Up @@ -1025,7 +1025,7 @@ def place_template_files(self, build_type, dir_path=None):
if has_files:
execute_command('git commit -m "Placing {0} template files"'.format(self.package_manager))

def get_subs(self, package, os_version, format_description, format_depends, releaser_history=None):
def get_subs(self, package, os_version, format_description, format_depends):
# This is the common part for generate templacte substitute, then successor of
# the generator will add its specic content via define its get_subs_hook function
subs = generate_substitutions_from_package(
Expand All @@ -1040,7 +1040,8 @@ def get_subs(self, package, os_version, format_description, format_depends, rele
[p.name for p in self.packages.values()],
fallback_resolver=self.missing_dep_resolver
)
subs['release_tag'] = 'release/{0}/{1}-{2}'.format(subs['Name'], subs['Version'], self.inc)
# Try to retrieve the releaser_history
releaser_history = self.get_releaser_history()
subs = self.get_subs_hook(subs, package, self.rosdistro, releaser_history=releaser_history)
for item in subs.items():
subs[item[0]] = convertToUnicode(item[1])
Expand Down
6 changes: 2 additions & 4 deletions bloom/generators/debian/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,8 @@ def pre_modify(self):

def generate_package(self, package, os_version):
info("Generating {0} for {1}...".format(self.package_manager, os_version))
# Try to retrieve the releaser_history
releaser_history = self.get_releaser_history()
# Generate substitution values
subs = self.get_subs(package, os_version, format_description, format_depends, releaser_history)
subs = self.get_subs(package, os_version, format_description, format_depends)
# Use subs to create and store releaser history
releaser_history = [(v, (n, e)) for v, _, _, n, e in subs['changelogs']]
self.set_releaser_history(dict(releaser_history))
Expand Down Expand Up @@ -279,6 +277,6 @@ def get_subs_hook(subs, package, rosdistro, releaser_history=None):
return subs

def generate_tag_name(self, subs):
tag_name = '{Package}_{Version}{Inc}_{Distribution}'
tag_name = '{Package}_{Version}-{Inc}_{Distribution}'
tag_name = self.package_manager + '/' + tag_name.format(**subs)
return tag_name
4 changes: 1 addition & 3 deletions bloom/generators/rpm/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,8 @@ def pre_modify(self):

def generate_package(self, package, os_version):
info("Generating {0} for {1}...".format(self.package_manager, os_version))
# Try to retrieve the releaser_history
releaser_history = self.get_releaser_history()
# Generate substitution values
subs = self.get_subs(package, os_version, format_description, format_depends, releaser_history)
subs = self.get_subs(package, os_version, format_description, format_depends)
# Use subs to create and store releaser history
self.set_releaser_history(dict(subs['changelogs']))
# Template files
Expand Down
48 changes: 48 additions & 0 deletions test/unit_tests/test_generators/test_common/test_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,51 @@ def test_bad_dependency():
with AssertRaisesContext(SystemExit, str(code.GENERATOR_NO_ROSDEP_KEY_FOR_DISTRO)):
with redirected_stdio():
gen.check_all_keys_are_valid("")


def format_depends(depends, resolved_deps):
formatted = []
for d in depends:
formatted.append("{0}".format(d))
return formatted


def format_description(value):
return value


class OneGenerator(PackageManagerGenerator):
package_manager = "test"
@staticmethod
def get_subs_hook(subs, package, rosdistro, releaser_history=None):
subs['Name'] = 'test_pkg improved'
subs['specific_part'] = 'none'
return subs


def test_get_substitute():
pkg_name = 'test_pkg'
pkg = get_package(pkg_name)
pkg_dict = {pkg_name: pkg}

gen = OneGenerator()
gen.packages = pkg_dict
gen.os_name = "ubuntu"
gen.os_version = "xenial"
gen.rosdistro = "kinetic"
gen.install_prefix = gen.default_install_prefix
gen.inc = "1"

with redirected_stdio():
subs = gen.get_subs(pkg, gen.os_version, format_description, format_depends)

assert 'test_pkg improved' == subs['Name']
assert '0.1.0' == subs['Version']
assert 'The test_pkg package' == subs['Description']
assert '1' == subs['Inc']
assert 'test-pkg' == subs['Package']
assert ['roscpp', 'rospy'] == subs['Depends']
assert gen.os_version == subs['Distribution']
assert "nobody1 <[email protected]>" == subs['Maintainer']
assert "nobody1 <[email protected]>, nobody2 <[email protected]>" == subs['Maintainers']
assert 'none' == subs['specific_part']

0 comments on commit d1aa11c

Please sign in to comment.