From cc0d01944651cf66a6732f871aa01f4b6ec8ee17 Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Tue, 16 Mar 2021 13:24:48 +0000 Subject: [PATCH] Add py39 support - update setup.cfg to advertise supported platforms - fix tox.ini file use version agnostic envlist - add openstack-tox-py39 job - minor fix on test file which wrongly assumed that pop returns a new dictionary - added type to release dictionary, which is what would have prevented previous item from being introduced. Change-Id: I60b80ebe41a66d39e6f1a51a3d00c0b9292d42fd --- conftest.py | 1 + pytest.ini | 4 ++++ .../emit_releases_file/emit_releases_file.py | 5 ++++- .../test_write_bash_script.py | 9 +++++++-- scripts/tripleo-jobs-gerrit.py | 2 +- setup.cfg | 13 ++++++++----- tests/test_jobs_gerrit.py | 17 ++++++++++++++--- tox.ini | 2 +- zuul.d/layout.yaml | 7 ++++--- 9 files changed, 44 insertions(+), 16 deletions(-) create mode 100644 conftest.py create mode 100644 pytest.ini diff --git a/conftest.py b/conftest.py new file mode 100644 index 000000000..037585c98 --- /dev/null +++ b/conftest.py @@ -0,0 +1 @@ +pytest_plugins = ['pytest_html'] diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 000000000..5c70c5f25 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,4 @@ +[pytest] +markers: + hookwrapper + optionalhook diff --git a/scripts/emit_releases_file/emit_releases_file.py b/scripts/emit_releases_file/emit_releases_file.py index 0da807a34..1ba0a4a2a 100644 --- a/scripts/emit_releases_file/emit_releases_file.py +++ b/scripts/emit_releases_file/emit_releases_file.py @@ -37,6 +37,7 @@ import os import re import requests import yaml +from typing import Dict # Define releases RELEASES = [ @@ -375,7 +376,9 @@ def shim_convert_old_release_names(releases_names, is_periodic): return modified_releases_name -def write_releases_dictionary_to_bash(releases_dictionary, bash_file_name): +def write_releases_dictionary_to_bash( + releases_dictionary: Dict[str, str], bash_file_name +): logger = logging.getLogger('emit-releases') # Make it deterministic, expected constants in the proper order try: diff --git a/scripts/emit_releases_file/test_write_bash_script.py b/scripts/emit_releases_file/test_write_bash_script.py index 2b6d9e6ed..6cd272df0 100644 --- a/scripts/emit_releases_file/test_write_bash_script.py +++ b/scripts/emit_releases_file/test_write_bash_script.py @@ -1,3 +1,4 @@ +import copy from emit_releases_file import write_releases_dictionary_to_bash from unittest import mock @@ -13,9 +14,12 @@ else: BUILTINS_OPEN = "builtins.open" -def test_empty_releases_dictionary_fails(): +def test_empty_releases_dictionary_fails(caplog): assert not write_releases_dictionary_to_bash({}, "") + expected_info = ('emit-releases', 40, 'Writting releases dictionary') + assert expected_info in caplog.record_tuples + @pytest.fixture def releases_dictionary(): @@ -57,7 +61,8 @@ def releases_dictionary(): ], ) def test_missing_key_fails(releases_dictionary, deleted_key): - wrong_releases_dictionary = releases_dictionary.pop(deleted_key) + wrong_releases_dictionary = copy.copy(releases_dictionary) + wrong_releases_dictionary.pop(deleted_key) assert not write_releases_dictionary_to_bash(wrong_releases_dictionary, "") diff --git a/scripts/tripleo-jobs-gerrit.py b/scripts/tripleo-jobs-gerrit.py index 5a86000c4..e478b3993 100755 --- a/scripts/tripleo-jobs-gerrit.py +++ b/scripts/tripleo-jobs-gerrit.py @@ -249,7 +249,7 @@ def main(args=sys.argv[1:]): ) results = {} for review in proj_reviews: - for ts, message in get_jenkins_comment_message(review).iteritems(): + for ts, message in get_jenkins_comment_message(review).items(): ci_results = process_jenkins_comment_message(message, job_names) patchset = str(re.search('Patch Set (.+?):', message).group(1)) diff --git a/setup.cfg b/setup.cfg index aef48c1aa..b9eb6a841 100644 --- a/setup.cfg +++ b/setup.cfg @@ -13,11 +13,12 @@ classifier = License :: OSI Approved :: Apache Software License Operating System :: POSIX :: Linux Programming Language :: Python - Programming Language :: Python :: 2 - Programming Language :: Python :: 2.7 - Programming Language :: Python :: 2.6 Programming Language :: Python :: 3 - Programming Language :: Python :: 3.3 + Programming Language :: Python :: 3.6 + Programming Language :: Python :: 3.7 + Programming Language :: Python :: 3.8 + Programming Language :: Python :: 3.9 +python_requires = >= 3.6 [files] data_files = @@ -37,7 +38,9 @@ warnerrors = False [tool:pytest] norecursedirs = .git .tox dist .eggs -log_cli = true +# do not set log_cli to true by default as it would display misleading +# exception during normal test execution. +# log_cli = true [flake8] # based on https://github.com/psf/black diff --git a/tests/test_jobs_gerrit.py b/tests/test_jobs_gerrit.py index f4f880e9b..41d4514b9 100644 --- a/tests/test_jobs_gerrit.py +++ b/tests/test_jobs_gerrit.py @@ -1,7 +1,18 @@ import os +from subprocess import run +import subprocess +import sys def test_jobs_gerrit(): - f = os.path.join(os.path.dirname(__file__), "../scripts/tripleo-jobs-gerrit.py") - result = os.system(f) - assert result == 0 + f = os.path.abspath( + os.path.join(os.path.dirname(__file__), "../scripts/tripleo-jobs-gerrit.py") + ) + result = run( + [sys.executable, f], + universal_newlines=True, + check=False, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + ) + assert result.returncode == 0, result diff --git a/tox.ini b/tox.ini index 8a5c3a426..022636ba6 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] # keep py3 before py2 to assure they are preffered for envs like linters: -envlist = linters,py{37,36,35,27},molecule +envlist = linters,py,molecule minversion = 3.4.0 ignore_basepython_conflict = True skip_missing_interpreters = True diff --git a/zuul.d/layout.yaml b/zuul.d/layout.yaml index 668ec95cf..8be91398c 100644 --- a/zuul.d/layout.yaml +++ b/zuul.d/layout.yaml @@ -20,7 +20,7 @@ vars: tox_environment: PYTEST_REQPASS: 1 - - openstack-tox-py36: + - openstack-tox-py36: &tox-py success-url: "tox/reports.html" failure-url: "tox/reports.html" files: &py_files @@ -33,6 +33,7 @@ vars: tox_environment: PYTEST_REQPASS: 84 + - openstack-tox-py39: *tox-py - tripleo-ci-centos-8-content-provider: dependencies: - openstack-tox-linters @@ -43,5 +44,5 @@ # jobs might be defined and nothing can merge in this repo. - openstack-tox-linters - tripleo-tox-molecule - - openstack-tox-py36: - files: *py_files + - openstack-tox-py36: *tox-py + - openstack-tox-py39: *tox-py