From 132fc093c0bcc124a05a18bb3157c82b6c149f31 Mon Sep 17 00:00:00 2001 From: Kamil Páral Date: May 21 2019 15:30:08 +0000 Subject: tests: convert to python3 --- diff --git a/README.rst b/README.rst index 729aa8e..e9162ab 100644 --- a/README.rst +++ b/README.rst @@ -10,8 +10,12 @@ using an rpmdeplint_ tool. See `recent results`_ and `task documentation`_. Running locally =============== -You can run the same task locally by running the ansible playbook. Execute the -following command as root (don't do this on a production machine!):: +You can run the same task locally by running the ansible playbook. Install +rpmdeplint first:: + + $ sudo dnf install rpmdeplint + +Then execute the following command as root (don't do this on a production machine!):: $ ansible-playbook tests.yml -e taskotron_item= -e taskotron_arch= @@ -38,7 +42,7 @@ Running the test suite Install dependepcies:: - sudo dnf install python-virtualenv python2-rpmfluff createrepo_c + sudo dnf install rpmdeplint python3-virtualenv python3-rpm createrepo_c Create virtualenv:: diff --git a/requirements.txt b/requirements.txt index 3e42931..440b1f5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,10 +1,8 @@ # This is a list of pypi packages to be installed into virtualenv. Alternatively, # you can install these as RPMs instead of pypi packages. -rpmdeplint - # Test suite requirements -dingus pytest pytest-cov PyYAML +rpmfluff diff --git a/testing/functest_scenarios.py b/testing/functest_scenarios.py index 8cca549..b3baaae 100644 --- a/testing/functest_scenarios.py +++ b/testing/functest_scenarios.py @@ -55,8 +55,8 @@ def test_scenarios(scenario, tmpdir, monkeypatch): # decode the input tuple for readability scenario_pass = scenario[0] scenario_path = scenario[1] - print scenario_pass - print "\n### Running scenario %s" % scenario_path + print(scenario_pass) + print("\n### Running scenario %s" % scenario_path) # convert the yaml scenario to fake rpms and repos scenario_data = read_yamldata(scenario_path) diff --git a/testing/scenarios/README.md b/testing/scenarios/README.md index 87ef0f7..a94c0ff 100644 --- a/testing/scenarios/README.md +++ b/testing/scenarios/README.md @@ -37,13 +37,13 @@ expected_outcome: pass current_repo: - - envra: foo-0.1-1.fc19.noarch + nevra: foo-0.1-1.fc19.noarch - - envra: moo-0.2-3.fc19.noarch + nevra: moo-0.2-3.fc19.noarch update_repo: - - envra: bar-0.1-1.fc19.noarch + nevra: bar-0.1-1.fc19.noarch requires: foo ``` @@ -52,16 +52,16 @@ update_repo: `current_repo`, and `update_repo` are YAML lists of package descriptions. The `current_repo` describes the state of the 'stable' repository, and the `update_repo` the available update. -Each package is represented by `envra`. To describe dependencies, you can add `requires`, `provides`, `conflicts`, and `obsoletes`. +Each package is represented by `nevra`. To describe dependencies, you can add `requires`, `provides`, `conflicts`, and `obsoletes`. Thus creating descriptions like these: ``` ... - - envra: foo-0.1-1.fc19.noarch + nevra: foo-0.1-1.fc19.noarch requires: libbar.so - - envra: bar-0.1-1.fc19.noarch + nevra: bar-0.1-1.fc19.noarch provides: libbar.so conflicts: moo diff --git a/testing/scenarios/scenarios/fail/01_version.yaml b/testing/scenarios/scenarios/fail/01_version.yaml index a50f593..8c7323d 100644 --- a/testing/scenarios/scenarios/fail/01_version.yaml +++ b/testing/scenarios/scenarios/fail/01_version.yaml @@ -5,12 +5,12 @@ expected_outcome: fail current_repo: - - envra: foo-0.1-1.fc19.noarch + nevra: foo-0.1-1.fc19.noarch - - envra: bar-0.1-1.fc19.noarch + nevra: bar-0.1-1.fc19.noarch requires: foo == 0.1-1.fc19 update_repo: - - envra: bar-0.2-1.fc19.noarch + nevra: bar-0.2-1.fc19.noarch requires: foo == 0.2-1.fc19 diff --git a/testing/scenarios/scenarios/fail/02_multilib.yaml b/testing/scenarios/scenarios/fail/02_multilib.yaml index 8a56438..c6a2e68 100644 --- a/testing/scenarios/scenarios/fail/02_multilib.yaml +++ b/testing/scenarios/scenarios/fail/02_multilib.yaml @@ -5,11 +5,11 @@ expected_outcome: fail current_repo: - - envra: foo-0.1-1.fc19.i386 + nevra: foo-0.1-1.fc19.i386 - - envra: foo-0.1-1.fc19.x86_64 + nevra: foo-0.1-1.fc19.x86_64 update_repo: - - envra: bar-0.2-1.fc19.x86_64 + nevra: bar-0.2-1.fc19.x86_64 requires: foo == 0.2-1.x86_64 diff --git a/testing/scenarios/scenarios/fail/03_package_requires.yaml b/testing/scenarios/scenarios/fail/03_package_requires.yaml index 711dfa4..a676d06 100644 --- a/testing/scenarios/scenarios/fail/03_package_requires.yaml +++ b/testing/scenarios/scenarios/fail/03_package_requires.yaml @@ -5,9 +5,9 @@ expected_outcome: fail current_repo: - - envra: foo-0.1-1.fc19.i386 + nevra: foo-0.1-1.fc19.i386 update_repo: - - envra: foo-0.2-1.fc19.x86_64 + nevra: foo-0.2-1.fc19.x86_64 requires: bar diff --git a/testing/scenarios/scenarios/fail/04_file_requires.yaml b/testing/scenarios/scenarios/fail/04_file_requires.yaml index 2422b49..d59dbc9 100644 --- a/testing/scenarios/scenarios/fail/04_file_requires.yaml +++ b/testing/scenarios/scenarios/fail/04_file_requires.yaml @@ -5,9 +5,9 @@ expected_outcome: fail current_repo: - - envra: foo-0.1-1.fc19.i386 + nevra: foo-0.1-1.fc19.i386 update_repo: - - envra: foo-0.2-1.fc19.x86_64 + nevra: foo-0.2-1.fc19.x86_64 requires: libbar.so diff --git a/testing/scenarios/scenarios/known_broken/05_removing_provides.yaml b/testing/scenarios/scenarios/known_broken/05_removing_provides.yaml index 5db6c76..84b83ee 100644 --- a/testing/scenarios/scenarios/known_broken/05_removing_provides.yaml +++ b/testing/scenarios/scenarios/known_broken/05_removing_provides.yaml @@ -5,14 +5,14 @@ expected_outcome: fail current_repo: - - envra: foo-0.1-1.fc19.x86_64 + nevra: foo-0.1-1.fc19.x86_64 provides: cannedunicorn - - envra: bar-0.1-1.fc19.x86_64 + nevra: bar-0.1-1.fc19.x86_64 requires: cannedunicorn update_repo: - - envra: foo-0.2-1.fc19.x86_64 + nevra: foo-0.2-1.fc19.x86_64 obsoletes: foo-0.1-1.fc19.x86_64 diff --git a/testing/scenarios/scenarios/known_broken/06_removing_subpackage.yaml b/testing/scenarios/scenarios/known_broken/06_removing_subpackage.yaml index cde3328..a976a7e 100644 --- a/testing/scenarios/scenarios/known_broken/06_removing_subpackage.yaml +++ b/testing/scenarios/scenarios/known_broken/06_removing_subpackage.yaml @@ -4,12 +4,12 @@ description: expected_outcome: fail current_repo: - - envra: mojito-1.0-1.fc19.noarch + - nevra: mojito-1.0-1.fc19.noarch requires: libmint = 1.0 - - envra: libmint-1.0-1.fc19.noarch + - nevra: libmint-1.0-1.fc19.noarch provides: libmint = 1.0 update_repo: - - envra: libmint-2.0-1.fc19.noarch + - nevra: libmint-2.0-1.fc19.noarch provides: libmint = 2.0 diff --git a/testing/scenarios/scenarios/pass/01_simple.yaml b/testing/scenarios/scenarios/pass/01_simple.yaml index 7f9da8a..b965598 100644 --- a/testing/scenarios/scenarios/pass/01_simple.yaml +++ b/testing/scenarios/scenarios/pass/01_simple.yaml @@ -5,9 +5,9 @@ expected_outcome: pass current_repo: - - envra: foo-0.1-1.fc19.noarch + nevra: foo-0.1-1.fc19.noarch update_repo: - - envra: bar-0.1-1.fc19.noarch + nevra: bar-0.1-1.fc19.noarch requires: foo diff --git a/testing/scenarios/scenarios/pass/02_conflicts_1.yaml b/testing/scenarios/scenarios/pass/02_conflicts_1.yaml index 12d7e18..b56ee52 100644 --- a/testing/scenarios/scenarios/pass/02_conflicts_1.yaml +++ b/testing/scenarios/scenarios/pass/02_conflicts_1.yaml @@ -6,10 +6,10 @@ expected_outcome: pass current_repo: - - envra: foo-0.1-1.fc19.noarch + nevra: foo-0.1-1.fc19.noarch conflicts: bar update_repo: - - envra: bar-0.1-1.fc19.noarch + nevra: bar-0.1-1.fc19.noarch conflicts: foo diff --git a/testing/scenarios/scenarios/pass/03_conflicts_2.yaml b/testing/scenarios/scenarios/pass/03_conflicts_2.yaml index 22f6c7e..134f2d4 100644 --- a/testing/scenarios/scenarios/pass/03_conflicts_2.yaml +++ b/testing/scenarios/scenarios/pass/03_conflicts_2.yaml @@ -6,9 +6,9 @@ expected_outcome: pass current_repo: - - envra: foo-0.1-1.fc19.noarch + nevra: foo-0.1-1.fc19.noarch conflicts: bar update_repo: - - envra: bar-0.1-1.fc19.noarch + nevra: bar-0.1-1.fc19.noarch diff --git a/testing/scenarios/scenarios/pass/04_conflicts_3.yaml b/testing/scenarios/scenarios/pass/04_conflicts_3.yaml index ff1a926..e9d2d93 100644 --- a/testing/scenarios/scenarios/pass/04_conflicts_3.yaml +++ b/testing/scenarios/scenarios/pass/04_conflicts_3.yaml @@ -6,9 +6,9 @@ expected_outcome: pass current_repo: - - envra: foo-0.1-1.fc19.noarch + nevra: foo-0.1-1.fc19.noarch update_repo: - - envra: bar-0.1-1.fc19.noarch + nevra: bar-0.1-1.fc19.noarch conflicts: foo diff --git a/testing/scenarios/scenarios/pass/05_strange_conflict.yaml b/testing/scenarios/scenarios/pass/05_strange_conflict.yaml index 995f799..b41e067 100644 --- a/testing/scenarios/scenarios/pass/05_strange_conflict.yaml +++ b/testing/scenarios/scenarios/pass/05_strange_conflict.yaml @@ -10,13 +10,13 @@ expected_outcome: pass current_repo: - - envra: foo-0.1-1.fc19.x86_64 + nevra: foo-0.1-1.fc19.x86_64 conflicts: foo-extras(x86-32) update_repo: - - envra: foo-0.1-1.fc19.i386 + nevra: foo-0.1-1.fc19.i386 - - envra: foo-extras-0.1-1.fc19.x86_64 + nevra: foo-extras-0.1-1.fc19.x86_64 - - envra: foo-extras-0.1-1.fc19.i386 + nevra: foo-extras-0.1-1.fc19.i386 diff --git a/testing/scenarios/scenarios/pass/06_multilib.yaml b/testing/scenarios/scenarios/pass/06_multilib.yaml index 1c993ff..e18702f 100644 --- a/testing/scenarios/scenarios/pass/06_multilib.yaml +++ b/testing/scenarios/scenarios/pass/06_multilib.yaml @@ -5,12 +5,12 @@ expected_outcome: pass current_repo: - - envra: foo-0.1-1.fc19.x86_64 + nevra: foo-0.1-1.fc19.x86_64 - - envra: foo-0.1-1.fc19.i386 + nevra: foo-0.1-1.fc19.i386 update_repo: - - envra: foo-0.2-1.fc19.x86_64 + nevra: foo-0.2-1.fc19.x86_64 - - envra: foo-0.2-1.fc19.i386 + nevra: foo-0.2-1.fc19.i386 diff --git a/testing/scenarios/scenarios/pass/07_codependencies.yaml b/testing/scenarios/scenarios/pass/07_codependencies.yaml index 2e0b0e6..624b502 100644 --- a/testing/scenarios/scenarios/pass/07_codependencies.yaml +++ b/testing/scenarios/scenarios/pass/07_codependencies.yaml @@ -6,27 +6,27 @@ expected_outcome: pass current_repo: - - envra: kernel-tools-3.17.1-302.fc21.x86_64 + nevra: kernel-tools-3.17.1-302.fc21.x86_64 - - envra: kernel-tools-libs-3.17.1-302.fc21.x86_64 + nevra: kernel-tools-libs-3.17.1-302.fc21.x86_64 - - envra: kernel-tools-libs-devel-3.17.1-302.fc21.x86_64 - requires: + nevra: kernel-tools-libs-devel-3.17.1-302.fc21.x86_64 + requires: - kernel-tools = 3.17.1-302.fc21 - kernel-tools-libs = 3.17.1-302.fc21 update_repo: - - envra: kernel-tools-libs-devel-3.17.1-303.fc21.x86_64 + nevra: kernel-tools-libs-devel-3.17.1-303.fc21.x86_64 requires: - kernel-tools = 3.17.1-303.fc21 - kernel-tools-libs = 3.17.1-303.fc21 - - envra: kernel-tools-3.17.1-303.fc21.x86_64 + nevra: kernel-tools-3.17.1-303.fc21.x86_64 - - envra: kernel-tools-libs-3.17.1-303.fc21.x86_64 + nevra: kernel-tools-libs-3.17.1-303.fc21.x86_64 diff --git a/testing/scenarios/scenarios/pass/08_recommends_present.yaml b/testing/scenarios/scenarios/pass/08_recommends_present.yaml index d798215..5be4dd1 100644 --- a/testing/scenarios/scenarios/pass/08_recommends_present.yaml +++ b/testing/scenarios/scenarios/pass/08_recommends_present.yaml @@ -5,9 +5,9 @@ expected_outcome: pass current_repo: - - envra: foo-0.1-1.fc19.noarch + nevra: foo-0.1-1.fc19.noarch update_repo: - - envra: bar-0.1-1.fc19.noarch + nevra: bar-0.1-1.fc19.noarch recommends: foo diff --git a/testing/scenarios/scenarios/pass/09_recommends_not_present.yaml b/testing/scenarios/scenarios/pass/09_recommends_not_present.yaml index 39706c6..e941d8a 100644 --- a/testing/scenarios/scenarios/pass/09_recommends_not_present.yaml +++ b/testing/scenarios/scenarios/pass/09_recommends_not_present.yaml @@ -5,9 +5,9 @@ expected_outcome: pass current_repo: - - envra: bar-0.1-0.fc19.noarch + nevra: bar-0.1-0.fc19.noarch update_repo: - - envra: bar-0.1-1.fc19.noarch + nevra: bar-0.1-1.fc19.noarch recommends: foo diff --git a/testing/scenarios/scenarios/pass/10_suggests_present.yaml b/testing/scenarios/scenarios/pass/10_suggests_present.yaml index 8340362..3f83a9e 100644 --- a/testing/scenarios/scenarios/pass/10_suggests_present.yaml +++ b/testing/scenarios/scenarios/pass/10_suggests_present.yaml @@ -5,9 +5,9 @@ expected_outcome: pass current_repo: - - envra: foo-0.1-1.fc19.noarch + nevra: foo-0.1-1.fc19.noarch update_repo: - - envra: bar-0.1-1.fc19.noarch + nevra: bar-0.1-1.fc19.noarch suggests: foo diff --git a/testing/scenarios/scenarios/pass/11_suggests_not_present.yaml b/testing/scenarios/scenarios/pass/11_suggests_not_present.yaml index a148aae..1433cfb 100644 --- a/testing/scenarios/scenarios/pass/11_suggests_not_present.yaml +++ b/testing/scenarios/scenarios/pass/11_suggests_not_present.yaml @@ -5,9 +5,9 @@ expected_outcome: pass current_repo: - - envra: bar-0.1-0.fc19.noarch + nevra: bar-0.1-0.fc19.noarch update_repo: - - envra: bar-0.1-1.fc19.noarch + nevra: bar-0.1-1.fc19.noarch suggests: foo diff --git a/testing/scenarios/scenarios/pass/12_supplements_present.yaml b/testing/scenarios/scenarios/pass/12_supplements_present.yaml index 3a8fa7f..6817bf3 100644 --- a/testing/scenarios/scenarios/pass/12_supplements_present.yaml +++ b/testing/scenarios/scenarios/pass/12_supplements_present.yaml @@ -5,9 +5,9 @@ expected_outcome: pass current_repo: - - envra: baz-0.1-1.fc19.noarch + nevra: baz-0.1-1.fc19.noarch update_repo: - - envra: bar-0.1-1.fc19.noarch + nevra: bar-0.1-1.fc19.noarch supplements: foo diff --git a/testing/scenarios/scenarios/pass/13_supplements_not_present.yaml b/testing/scenarios/scenarios/pass/13_supplements_not_present.yaml index 6d1d280..8915783 100644 --- a/testing/scenarios/scenarios/pass/13_supplements_not_present.yaml +++ b/testing/scenarios/scenarios/pass/13_supplements_not_present.yaml @@ -5,9 +5,9 @@ expected_outcome: pass current_repo: - - envra: bar-0.1-1.fc19.noarch + nevra: bar-0.1-1.fc19.noarch update_repo: - - envra: baz-0.1-1.fc19.noarch + nevra: baz-0.1-1.fc19.noarch supplements: foo diff --git a/testing/scenarios/yaml_to_repos.py b/testing/scenarios/yaml_to_repos.py index 50ec968..1313a17 100644 --- a/testing/scenarios/yaml_to_repos.py +++ b/testing/scenarios/yaml_to_repos.py @@ -20,46 +20,12 @@ import os import yaml import tempfile import rpmfluff -import rpmUtils.arch -import rpmUtils.miscutils import subprocess +from libtaskotron.ext.fedora import rpm_utils -__all__ = ['create_repos'] -def parseENVRA(envra, fmt = "envra"): - """ - @param envra string to be 'manipulated' - can be standard style rpm filename, - envra, envr, nvr - @param fmt desired format of the string to be returned. Allowed options are: - envra, envr, nvra, nvr, e, n, v, r, a. If arch is not present in envra, - 'noarch' is returned wherever needed. - @returns list of strings based on the specified format; if epoch is requested but not - present, it is se to empty string - """ - fmt = fmt.lower() - supported_formats = ['envra', 'envr', 'nvra', 'nvr', 'e', 'n', 'v', 'r', 'a'] - if fmt not in supported_formats: - raise ValueError("Format '%s' not in supported formats (%s)" % (fmt, ', '.join(supported_formats))) - - # prepare envra so it can be used with rpmUtils.miscutils.splitFilename() - parts = envra.split('.') - if parts[-1].lower() != 'rpm': - parts.append('rpm') - if parts[-2].lower() not in rpmUtils.arch.arches.keys() + ['noarch', 'src']: - parts.insert(-1, 'noarch') - - # split the filename - (n, v, r, e, a) = rpmUtils.miscutils.splitFilename('.'.join(parts)) - - if len(fmt) == 1: - return {'e':e, 'n':n, 'v':v, 'r':r, 'a':a}[fmt] - - return {'envra': (e, n, v, r, a), - 'envr' : (e, n, v ,r), - 'nvra' : (n, v, r ,a), - 'nvr' : (n, v, r), - }[fmt] +__all__ = ['create_repos'] class MySimpleRpmBuild(rpmfluff.SimpleRpmBuild): """Derivative of SimpleRpmBuild which allows setting output directory""" @@ -84,7 +50,12 @@ def package_to_SimpleRpmBuild(package, rpmdir = None): @returns instance of MySimpleRpmBuild """ - e,n,v,r,a = parseENVRA(package['envra']) + n = rpm_utils.rpmformat(package['nevra'], fmt='n', end_arch=True) + e = rpm_utils.rpmformat(package['nevra'], fmt='e', end_arch=True) + v = rpm_utils.rpmformat(package['nevra'], fmt='v', end_arch=True) + r = rpm_utils.rpmformat(package['nevra'], fmt='r', end_arch=True) + a = rpm_utils.rpmformat(package['nevra'], fmt='a', end_arch=True) + p = MySimpleRpmBuild(n, v, r, [a], rpmdir) p.epoch = e @@ -182,7 +153,7 @@ def create_repos(data, outdir = None): for root, dirs, files in os.walk(os.path.join(rpmdir, directory, 'RPMS')): for file in [f for f in files if f.endswith('.rpm')]: subprocess.check_call(['cp', os.path.join(root, file), repodir]) - print "copied %s to %s" % (file, repodir) + print("copied %s to %s" % (file, repodir)) # create repo subprocess.check_call(['createrepo_c', repodir]) @@ -194,7 +165,7 @@ if __name__ == "__main__": try: data = yaml.load(open(sys.argv[1]).read()) except: - print >> sys.stderr, ("\n\nMust supply valid yaml.") + print("\n\nMust supply valid yaml.", file=sys.stderr) sys.exit(1) create_repos(data) diff --git a/testing/test_squash_results.py b/testing/test_squash_results.py index 9ef7344..d35594e 100644 --- a/testing/test_squash_results.py +++ b/testing/test_squash_results.py @@ -1,4 +1,4 @@ -from dingus import Dingus +import mock from utils.squash_results import _squash_rpms_to_builds from utils import PASS, FAIL @@ -14,8 +14,9 @@ class TestSquashResults(object): 'rpm1': {'result': PASS, 'details': []}, 'rpm2': {'result': PASS, 'details': ["moo"]}, } - fake_koji = Dingus(rpms_to_build__returns = [{'nvr': 'nvr1'}, - {'nvr': 'nvr1'}]) + fake_koji = mock.Mock() + fake_koji.rpms_to_build = mock.Mock(return_value=[{'nvr': 'nvr1'}, + {'nvr': 'nvr1'}]) outcome = _squash_rpms_to_builds(run_results, fake_koji) assert len(outcome.keys()) == 1 @@ -31,9 +32,10 @@ class TestSquashResults(object): 'rpm2': {'result': FAIL, 'details': ["foo bar"]}, 'rpm3': {'result': PASS, 'details': ["moo"]}, } - fake_koji = Dingus(rpms_to_build__returns = [{'nvr': 'nvr1'}, - {'nvr': 'nvr1'}, - {'nvr': 'nvr1'}]) + fake_koji = mock.Mock() + fake_koji.rpms_to_build = mock.Mock(return_value=[{'nvr': 'nvr1'}, + {'nvr': 'nvr1'}, + {'nvr': 'nvr1'}]) outcome = _squash_rpms_to_builds(run_results, fake_koji) assert len(outcome.keys()) == 1