Skip to content

Commit

Permalink
Test data paths were added multiple times to cdl.utils.tests.TST_PATH
Browse files Browse the repository at this point in the history
Fix #84
  • Loading branch information
PierreRaybaut committed Jul 2, 2024
1 parent 9e6c4b5 commit d11b923
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@
],
"env": {
// "DEBUG": "1",
// The `CDL_DATA` environment variable is set here just for checking
// that the data path is not added twice to the test data path list:
"CDL_DATA": "${workspaceFolder}/cdl/data/tests",
"LANG": "en",
"QT_COLOR_MODE": "light",
}
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

See DataLab [roadmap page](https://datalab-platform.com/en/contributing/roadmap.html) for future and past milestones.

## DataLab Version 0.16.3 ##

🛠️ Bug fixes:

* Fixed [Issue #84](https://github.com/DataLab-Platform/DataLab/issues/84) - Build issues with V0.16.1: `signal` name conflict, ...
* This issue was intended to be fixed in version 0.16.2, but the fix was not complete
* Thanks to [@rolandmas](https://github.com/rolandmas) for reporting the issue and for the help in investigating the problem and testing the fix
* Fixed [Issue #85](https://github.com/DataLab-Platform/DataLab/issues/85) - Test data paths may be added multiple times to `cdl.utils.tests.TST_PATH`
* This issue is related to [Issue #84](https://github.com/DataLab-Platform/DataLab/issues/84)
* Adding the test data paths multiple times to `cdl.utils.tests.TST_PATH` was causing the test data to be loaded multiple times, which lead to some tests failing (a simple workaround was added to V0.16.2: this issue is now fixed)
* Thanks again to [@rolandmas](https://github.com/rolandmas) for reporting the issue in the context of the Debian packaging

## DataLab Version 0.16.2 ##

This release requires PlotPy v2.4.0 or later, which brings the following bug fixes and new features:
Expand Down
2 changes: 1 addition & 1 deletion cdl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import os

__version__ = "0.16.2"
__version__ = "0.16.3"
__docurl__ = __homeurl__ = "https://datalab-platform.com/"
__supporturl__ = "https://github.com/DataLab-Platform/DataLab/issues/new/choose"

Expand Down
6 changes: 0 additions & 6 deletions cdl/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@
from cdl.utils import qthelpers as qth
from cdl.utils import tests

# Add test data files and folders pointed by `CDL_DATA` environment variable:
tests.add_test_path_from_env("CDL_DATA")


# TODO: [P2] Documentation: add more screenshots from tests


@contextmanager
def cdltest_app_context(
Expand Down
26 changes: 24 additions & 2 deletions cdl/utils/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,33 @@
TST_PATH = []


def add_test_path(path: str) -> None:
"""Appends test data path, after normalizing it and making it absolute.
Do nothing if the path is already in the list.
Args:
Path to add to the list of test data paths
Raises:
FileNotFoundError: if the path does not exist
"""
path = osp.abspath(osp.normpath(path))
if path not in TST_PATH:
if not osp.exists(path):
raise FileNotFoundError(f"Test data path does not exist: {path}")
TST_PATH.append(path)


def add_test_path_from_env(envvar: str) -> None:
"""Appends test data path from environment variable (fails silently)"""
# Note: this function is used in third-party plugins
path = os.environ.get(envvar)
if path:
TST_PATH.append(path)
add_test_path(path)


# Add test data files and folders pointed by `CDL_DATA` environment variable:
add_test_path_from_env("CDL_DATA")


def add_test_module_path(modname: str, relpath: str) -> None:
Expand All @@ -43,9 +64,10 @@ def add_test_module_path(modname: str, relpath: str) -> None:
modname must be the name of an already imported module as found in
sys.modules
"""
TST_PATH.append(get_module_data_path(modname, relpath=relpath))
add_test_path(get_module_data_path(modname, relpath=relpath))


# Add test data files and folders for the DataLab module:
add_test_module_path(MOD_NAME, osp.join("data", "tests"))


Expand Down

0 comments on commit d11b923

Please sign in to comment.