-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add tests that check extras work as expected
For each extras, it installs the project with that extra, and checks whether the expected extra dependencies have been installed.
- Loading branch information
1 parent
9e0e72b
commit c716659
Showing
2 changed files
with
70 additions
and
0 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
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,57 @@ | ||
# Black-box ABM Calibration Kit (Black-it) | ||
# Copyright (C) 2021-2023 Banca d'Italia | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
"""This module contains tests for the setuptools extras mechanism.""" | ||
import os | ||
import subprocess # nosec | ||
from pathlib import Path | ||
from typing import AbstractSet, Mapping | ||
|
||
import pytest | ||
|
||
from tests.conftest import ROOT_DIR | ||
|
||
# Define your extras and expected dependencies here. | ||
extras_dependencies = { | ||
"gp-sampler": {"GPy"}, | ||
"xgboost-sampler": {"xgboost"}, | ||
} | ||
|
||
|
||
@pytest.mark.not_on_ci | ||
@pytest.mark.parametrize("extra, dependencies", extras_dependencies.items()) | ||
def test_extras_installation( | ||
extra: str, dependencies: Mapping[str, AbstractSet[str]], venv_path: Path | ||
) -> None: | ||
"""Test that the extras dependencies are installed as expected.""" | ||
bin_dirname = "Scripts" if os.name == "nt" else "bin" | ||
bin_dir = venv_path / bin_dirname | ||
pip_bin_path = bin_dir / "pip" | ||
|
||
# Install the project with the extra | ||
subprocess.check_call( # nosec | ||
[pip_bin_path, "install", f".[{extra}]"], cwd=ROOT_DIR | ||
) | ||
|
||
# Get a list of installed packages in the virtual environment | ||
output = ( | ||
subprocess.check_output([pip_bin_path, "freeze"]).decode().splitlines() # nosec | ||
) | ||
installed_packages = [pkg.split("==")[0] for pkg in output] | ||
|
||
# Check that each dependency for the extra is installed | ||
for dependency in dependencies: | ||
assert dependency in installed_packages |