Skip to content

Commit

Permalink
Py38 (#432)
Browse files Browse the repository at this point in the history
* enable py38

* AT_LEAST_PY38; deprecate `create_*_future` for tests

* fix test_upload_artifacts_throws

* fix test_run_tasks_cancel_claim_work

* fix test_run_tasks_no_cancel

* fix test_run_tasks_cancel_sleep

* fix test_run_tasks_cancel_cot

* fix test_run_tasks_cancel_run_tasks

* fix test_run_tasks_cancel_right_before_proc_created

* fix test_run_tasks_cancel_right_before_cot

* fix test_run_tasks_cancel_right_before_claim_work

* fix test_trace_back_to_tree_mobile_staging_repos_dont_access_restricted_scopes

* add py38-cot; add py38 support in package desc

* add stub 31.0.0 history. need to add release date

* 31.0.0
  • Loading branch information
escapewindow authored Feb 18, 2020
1 parent 4d723e4 commit 0d9160d
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 97 deletions.
3 changes: 2 additions & 1 deletion .taskcluster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ tasks:
}, ['secrets:get:repo:github.com/mozilla-releng/scriptworker:coveralls']],
# Disabled due to legitimate failures.
# See https://github.com/mozilla-releng/scriptworker/issues/415
#['py38', 'python:3.8', {NO_TESTS_OVER_WIRE: '1'}, []],
['py38', 'python:3.8', {NO_TESTS_OVER_WIRE: '1'}, []],
['py37-cot', 'python:3.7', {NO_CREDENTIALS_TESTS: '1'}, []],
['py38-cot', 'python:3.8', {NO_CREDENTIALS_TESTS: '1'}, []],
['lint', 'python:3.7', {}, []],
['mypy', 'python:3.7', {}, []]]
each(py):
Expand Down
11 changes: 11 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ Change Log
All notable changes to this project will be documented in this file.
This project adheres to `Semantic Versioning <http://semver.org/>`__.

[31.0.0] - 2020-02-18
---------------------

Added
~~~~~
- Python 3.8 support.

Changed
~~~~~~~
- Swapped out ``frozendict`` for ``immutabledict``.

[30.0.1] - 2020-02-06
---------------------

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,6 @@ def run_tests(self):
"Natural Language :: English",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
),
)
4 changes: 2 additions & 2 deletions src/scriptworker/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def get_version_string(version: Union[ShortVerType, LongVerType]) -> str:

# 1}}}
# Semantic versioning 2.0.0 http://semver.org/
__version__ = (30, 0, 1)
__version__ = (31, 0, 0)
__version_string__ = get_version_string(__version__)


Expand All @@ -74,7 +74,7 @@ def write_version(name: Optional[str] = None, path: Optional[str] = None) -> Non
# Written like this for coverage purposes.
# http://stackoverflow.com/questions/5850268/how-to-test-or-mock-if-name-main-contents/27084447#27084447
if name in (None, "__main__"):
path = path or os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "version.json")
path = path or os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))), "version.json")
contents = {"version": __version__, "version_string": __version_string__}
with open(path, "w") as filehandle:
print(json.dumps(contents, sort_keys=True, indent=4, separators=(",", ":")), file=filehandle)
Expand Down
6 changes: 6 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import asyncio
import json
import os
import sys

import aiohttp
import arrow
Expand All @@ -27,6 +28,7 @@
}

TIMEOUT_SCRIPT = os.path.join(os.path.dirname(__file__), "data", "long_running.py")
AT_LEAST_PY38 = sys.version_info >= (3, 8)


def read(path):
Expand Down Expand Up @@ -128,12 +130,16 @@ def noop_sync(*args, **kwargs):


def create_finished_future(result=None):
# XXX deprecated; remove after we drop py37 support
assert not AT_LEAST_PY38, "Use AsyncMock!"
future = asyncio.Future()
future.set_result(result)
return future


def create_rejected_future(exception=BaseException):
# XXX deprecated; remove after we drop py37 support
assert not AT_LEAST_PY38, "Use AsyncMock!"
future = asyncio.Future()
future.set_exception(exception)
return future
Expand Down
23 changes: 13 additions & 10 deletions tests/test_artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
)
from scriptworker.exceptions import ScriptWorkerRetryException, ScriptWorkerTaskException

from . import create_finished_future, create_rejected_future, touch
from . import touch


@pytest.yield_fixture(scope="function")
Expand Down Expand Up @@ -84,15 +84,18 @@ async def foo(_, path, **kwargs):


@pytest.mark.asyncio
async def test_upload_artifacts_throws(context):
def mock_create_artifact():
yield create_finished_future()
yield create_rejected_future(ArithmeticError)

generator = mock_create_artifact()
with mock.patch("scriptworker.artifacts.create_artifact", new=lambda *args, **kwargs: next(generator)):
with pytest.raises(ArithmeticError):
await upload_artifacts(context, ["one", "public/two"])
async def test_upload_artifacts_throws(context, mocker):
exceptions = [None, ArithmeticError]

async def mock_create_artifact(*args, **kwargs):
exc = exceptions.pop()
if exc:
raise exc("foo")
return 0

mocker.patch("scriptworker.artifacts.create_artifact", new=mock_create_artifact)
with pytest.raises(ArithmeticError):
await upload_artifacts(context, ["one", "public/two"])


@pytest.mark.parametrize(
Expand Down
16 changes: 8 additions & 8 deletions tests/test_cot_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import os
import tempfile
from copy import deepcopy
from unittest.mock import MagicMock, patch
from unittest.mock import MagicMock

import aiohttp
import jsone
Expand All @@ -20,7 +20,7 @@
from scriptworker.utils import load_json_or_yaml, makedirs, read_from_file
from taskcluster.exceptions import TaskclusterFailure

from . import create_async, create_finished_future, noop_async, noop_sync, touch
from . import create_async, noop_async, noop_sync, touch

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -2013,17 +2013,17 @@ async def test_trace_back_to_tree_diff_repo(chain, decision_link, build_link, do
)
@pytest.mark.asyncio
async def test_trace_back_to_tree_mobile_staging_repos_dont_access_restricted_scopes(
mobile_chain, mobile_github_release_link, mobile_build_link, source_url, raises
mobile_chain, mobile_github_release_link, mobile_build_link, source_url, raises, mocker
):
(source_url, raises) = ("https://github.com/mozilla-mobile/focus-android", False)
mobile_github_release_link.task["metadata"]["source"] = source_url
mobile_chain.links = [mobile_github_release_link, mobile_build_link]
with patch.object(mobile_chain, "is_try_or_pull_request", return_value=create_finished_future(False)):
if raises:
with pytest.raises(CoTError):
await cotverify.trace_back_to_tree(mobile_chain)
else:
mocker.patch.object(mobile_chain, "is_try_or_pull_request", new=create_async(result=False))
if raises:
with pytest.raises(CoTError):
await cotverify.trace_back_to_tree(mobile_chain)
else:
await cotverify.trace_back_to_tree(mobile_chain)


# AuditLogFormatter {{{1
Expand Down
Loading

0 comments on commit 0d9160d

Please sign in to comment.