Skip to content

Commit

Permalink
Merge pull request #43 from capitalone/dev
Browse files Browse the repository at this point in the history
Release 2022.7.0
  • Loading branch information
Faisal authored Jul 15, 2022
2 parents 9932944 + 456aa34 commit 028a94a
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 36 deletions.
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
author = "Akshay Gupta"

# The short X.Y version
version = "2022.6.0"
version = "2022.7.0"
# The full version, including alpha/beta/rc tags
release = ""

Expand Down
5 changes: 5 additions & 0 deletions docs/source/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ framework that allows for additional functionality. We expose the following hook
+---------------------------------------------------------+----------------------------------------------+
| :py:meth:`edgetest.hookspecs.create_environment` [#f1]_ | This hook creates the virtual environment. |
+---------------------------------------------------------+----------------------------------------------+
| :py:meth:`edgetest.hookspecs.run_update` [#f1]_ | | This hook runs the environment update. |
| | | As an example, you could implement updates |
| | | via `pip`, `conda`, or some other package |
| | | manager. |
+---------------------------------------------------------+----------------------------------------------+
| :py:meth:`edgetest.hookspecs.post_run_hook` | | This hook executes code after the testing |
| | | has completed. Commonly used for creating |
| | | notifications. |
Expand Down
2 changes: 1 addition & 1 deletion edgetest/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Package initialization."""


__version__ = "2022.6.0"
__version__ = "2022.7.0"

__title__ = "edgetest"
__description__ = "Bleeding edge dependency testing"
Expand Down
12 changes: 5 additions & 7 deletions edgetest/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,11 @@ def setup(
LOG.info(
f"Upgrading the following packages in {self.envname}: {', '.join(self.upgrade)}"
)
_run_command(
self.python_path,
"-m",
"pip",
"install",
*self.upgrade,
"--upgrade",
self.hook.run_update(
basedir=self._basedir,
envname=self.envname,
upgrade=self.upgrade,
conf=options,
)
LOG.info(f"Successfully upgraded packages in {self.envname}")

Expand Down
24 changes: 24 additions & 0 deletions edgetest/hookspecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,30 @@ def create_environment(basedir: str, envname: str, conf: Dict):
"""


@hookspec(firstresult=True)
def run_update(basedir: str, envname: str, upgrade: List, conf: Dict):
"""Update packages from upgrade list.
Parameters
----------
basedir : str
The base directory location for the environment.
envname : str
The name of the virtual environment.
upgrade : list
The list of packages to upgrade
conf : dict
The configuration dictionary for the environment. This is useful if you
want to add configuration arguments for additional dependencies that can
only be installed through the environment manager (e.g. Conda).
Raises
------
RuntimeError
Error raised if the packages cannot be updated.
"""


@hookspec
def post_run_hook(testers: List, conf: Dict):
"""Post testing hook.
Expand Down
38 changes: 37 additions & 1 deletion edgetest/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import platform
from pathlib import Path
from typing import Dict
from typing import Dict, List
from venv import EnvBuilder

import pluggy

from .utils import _run_command

hookimpl = pluggy.HookimplMarker("edgetest")


Expand Down Expand Up @@ -44,3 +46,37 @@ def create_environment(basedir: str, envname: str, conf: Dict):
builder.create(env_dir=Path(basedir, envname))
except Exception:
raise RuntimeError(f"Unable to create {envname} in {basedir}")


@hookimpl(trylast=True)
def run_update(basedir: str, envname: str, upgrade: List, conf: Dict):
"""Update packages from upgrade list.
Parameters
----------
basedir : str
The base directory location for the environment.
envname : str
The name of the virtual environment.
upgrade : list
The list of packages to upgrade
conf : dict
Ignored.
Raises
------
RuntimeError
Error raised if the packages cannot be updated.
"""
python_path = path_to_python(basedir, envname)
try:
_run_command(
python_path,
"-m",
"pip",
"install",
*upgrade,
"--upgrade",
)
except Exception:
raise RuntimeError(f"Unable to pip upgrade: {upgrade}")
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pluggy==1.0.0
# via edgetest (setup.cfg)
pyparsing==3.0.9
# via packaging
tabulate==0.8.9
tabulate==0.8.10
# via edgetest (setup.cfg)

# The following packages are considered to be unsafe in a requirements file:
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ install_requires =
Cerberus<=1.3.4,>=1.3.0
click<=8.1.3,>=7.0
pluggy<=1.0.0,>=1.0.0
tabulate<=0.8.9,>=0.8.9
tabulate<=0.8.10,>=0.8.9
packaging<=21.3,>20.6

[options.extras_require]
Expand Down Expand Up @@ -98,7 +98,7 @@ console_scripts =
edgetest = edgetest.interface:cli

[bumpver]
current_version = "2022.6.0"
current_version = "2022.7.0"
version_pattern = "YYYY.MM.INC0"
commit_message = "Bump {old_version} to {new_version}"
commit = True
Expand Down
7 changes: 6 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import platform
from pathlib import Path
from typing import Dict
from typing import Dict, List

import pluggy
import pytest
Expand All @@ -29,6 +29,11 @@ def create_environment(self, basedir: str, envname: str, conf: Dict):
"""Create the virtual environment for testing."""
pass

@hookimpl
def run_update(self, basedir: str, envname: str, upgrade: List):
"""Update packages from upgrade list."""
pass


@pytest.fixture
def plugin_manager():
Expand Down
22 changes: 0 additions & 22 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,6 @@ def test_basic_setup(mock_popen, mock_path, tmpdir, plugin_manager):
stdout=-1,
universal_newlines=True,
),
call(
(
f"{str(py_loc)}",
"-m",
"pip",
"install",
"myupgrade",
"--upgrade",
),
stdout=-1,
universal_newlines=True,
),
]


Expand Down Expand Up @@ -101,11 +89,6 @@ def test_setup_extras(mock_popen, mock_path, tmpdir, plugin_manager):
stdout=-1,
universal_newlines=True,
),
call(
(f"{py_loc}", "-m", "pip", "install", "myupgrade", "--upgrade"),
stdout=-1,
universal_newlines=True,
),
]


Expand Down Expand Up @@ -152,11 +135,6 @@ def test_setup_pip_deps(mock_popen, mock_path, tmpdir, plugin_manager):
stdout=-1,
universal_newlines=True,
),
call(
(f"{py_loc}", "-m", "pip", "install", "myupgrade", "--upgrade"),
stdout=-1,
universal_newlines=True,
),
]


Expand Down
47 changes: 47 additions & 0 deletions tests/test_lib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from pathlib import Path
from unittest.mock import patch

import pytest

from edgetest.lib import create_environment, path_to_python, run_update


@patch("edgetest.lib.platform", autospec=True)
def test_path_to_python(mock_platform):
mock_platform.system.return_value = "Windows"
assert path_to_python("test", "test") == str(
Path("test") / "test" / "Scripts" / "python"
)

mock_platform.system.return_value = "Unix"
assert path_to_python("test", "test") == str(
Path("test") / "test" / "bin" / "python"
)

mock_platform.system.side_effect = RuntimeError()
with pytest.raises(RuntimeError):
path_to_python("test", "test")


@patch("edgetest.lib.EnvBuilder", autospec=True)
def test_create_environment(mock_env_builder):
create_environment("test", "test", {})
mock_env_builder.assert_called_with(with_pip=True)
mock_env_builder().create.assert_called_with(env_dir=Path("test", "test"))

mock_env_builder().create.side_effect = RuntimeError()
with pytest.raises(RuntimeError):
create_environment("test", "test", {})


@patch("edgetest.lib._run_command", autospec=True)
def test_run_update(mock_run):
python_path = path_to_python("test", "test")
run_update("test", "test", ["1", "2"], {"test": "test"})
mock_run.assert_called_with(
python_path, "-m", "pip", "install", "1", "2", "--upgrade"
)

mock_run.side_effect = RuntimeError()
with pytest.raises(RuntimeError):
run_update("test", "test", ["1", "2"], {"test": "test"})

0 comments on commit 028a94a

Please sign in to comment.