This repository has been archived by the owner on May 3, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR improves the handling of module reloading to prevent changed dependencies between modified modules from preventing the reload process from completing successfully. The failure mode comes about when changes in one module are imported into another module and by the previous sorting method, the importing module is reloaded first.
- Loading branch information
Showing
7 changed files
with
171 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,81 @@ | ||
stages: | ||
- check | ||
- broadcast | ||
- check | ||
- broadcast | ||
|
||
pytest-py36: | ||
image: python:3.6 | ||
stage: check | ||
script: | ||
- export PYTHONPATH="${PYTHONPATH}:$(pwd)" | ||
- pip install -r requirements.txt | ||
- > | ||
py.test | ||
--verbose | ||
--cov-report term | ||
--cov=cauldron | ||
. | ||
- export PYTHONPATH="${PYTHONPATH}:$(pwd)" | ||
- pip install -r requirements.txt | ||
- > | ||
py.test | ||
--verbose | ||
--cov-report term | ||
--cov=cauldron | ||
. | ||
pytest-py37: | ||
image: python:3.7 | ||
stage: check | ||
script: | ||
- export PYTHONPATH="${PYTHONPATH}:$(pwd)" | ||
- pip install -r requirements.txt | ||
- pip install codecov coveralls codacy-coverage | ||
- > | ||
py.test | ||
--verbose | ||
--cov-report xml:"$(pwd)/coverage.xml" | ||
--cov-report term | ||
--cov=cauldron | ||
. | ||
- export PYTHONPATH="${PYTHONPATH}:$(pwd)" | ||
- pip install -r requirements.txt | ||
- pip install codecov coveralls codacy-coverage | ||
- > | ||
py.test | ||
--verbose | ||
--cov-report xml:"$(pwd)/coverage.xml" | ||
--cov-report term | ||
--cov=cauldron | ||
. | ||
pytest-py38: | ||
image: python:3.8 | ||
stage: check | ||
coverage: '/^TOTAL.*\s+\d+\s+\d+\s+(\d+)%/' | ||
script: | ||
- export PYTHONPATH="${PYTHONPATH}:$(pwd)" | ||
- pip install -r requirements.txt | ||
- > | ||
py.test | ||
--verbose | ||
--cov-report term | ||
--cov=cauldron | ||
. | ||
- export PYTHONPATH="${PYTHONPATH}:$(pwd)" | ||
- pip install -r requirements.txt | ||
- > | ||
py.test | ||
--verbose | ||
--cov-report term | ||
--cov=cauldron | ||
. | ||
artifacts: | ||
paths: | ||
- .coverage | ||
- coverage.xml | ||
- .coverage | ||
- coverage.xml | ||
expire_in: 1 day | ||
|
||
pytest-py39: | ||
image: python:3.9 | ||
stage: check | ||
coverage: '/^TOTAL.*\s+\d+\s+\d+\s+(\d+)%/' | ||
script: | ||
- export PYTHONPATH="${PYTHONPATH}:$(pwd)" | ||
- pip install -r requirements.txt | ||
- > | ||
py.test | ||
--verbose | ||
--cov-report term | ||
--cov=cauldron | ||
. | ||
- export PYTHONPATH="${PYTHONPATH}:$(pwd)" | ||
- pip install -r requirements.txt | ||
- > | ||
py.test | ||
--verbose | ||
--cov-report term | ||
--cov=cauldron | ||
. | ||
codecov: | ||
image: python:3.9 | ||
stage: broadcast | ||
allow_failure: true | ||
script: | ||
- pip install codecov | ||
- ls -la | ||
- codecov | ||
- pip install codecov | ||
- ls -la | ||
- codecov | ||
|
||
coveralls: | ||
image: python:3.9 | ||
stage: broadcast | ||
allow_failure: true | ||
script: | ||
- pip install coveralls | ||
- ls -la | ||
- coveralls --verbose | ||
- pip install coveralls | ||
- ls -la | ||
- coveralls --verbose |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"notebookVersion": "v1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import functools | ||
import pathlib | ||
import random | ||
from unittest.mock import MagicMock | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
|
||
import cauldron | ||
from cauldron import runner | ||
|
||
|
||
def _mock_reload_module(history: dict, path: str, library_directory: str): | ||
"""Mocked version of the runner.__init__._reload_module function.""" | ||
output = {"path": path, "library_directory": library_directory} | ||
if path not in history and random.random() > 0.5: | ||
history[path] = output | ||
raise ValueError("Faking that this did not go well for the first time.") | ||
|
||
history[path] = output | ||
return output | ||
|
||
|
||
@patch("cauldron.runner._reload_module") | ||
def test_reload(reload_module: MagicMock): | ||
"""Should reload as expected.""" | ||
history = {} | ||
reload_module.side_effect = functools.partial(_mock_reload_module, history) | ||
library_directory = pathlib.Path(cauldron.__file__).resolve().parent | ||
output = runner.reload_libraries([None, str(library_directory)]) | ||
|
||
me = pathlib.Path(__file__).resolve() | ||
root = pathlib.Path(cauldron.__file__).resolve() | ||
keys = list(history.keys()) | ||
assert keys.index(str(me)) < keys.index(str(root)), """ | ||
Expecting deeper hierarchy to be reloaded first. | ||
""" | ||
|
||
assert output, "Expect a non-empty list returned." | ||
|
||
|
||
@patch("cauldron.runner._reload_module") | ||
def test_reload_failure(reload_module: MagicMock): | ||
"""Should raise RuntimeError if imports fail after many retries.""" | ||
reload_module.side_effect = ValueError("Nope") | ||
library_directory = pathlib.Path(cauldron.__file__).resolve().parent | ||
|
||
with pytest.raises(RuntimeError): | ||
runner.reload_libraries([None, str(library_directory)]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.