Skip to content

Commit 955054f

Browse files
committed
fix: improve testing setup
- Use a new environment variable called `TESTDIR` in `skll.utils.testing` as an alternative to hard-coding the path to the `tests` directory. This is needed when running tests as part of testing the conda and PyPI packages. - Tweak some path based tests to use absoluate paths when comparing.
1 parent 2019e61 commit 955054f

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

skll/utils/testing.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Utility functions to make SKLL testing simpler."""
22

33

4+
import os
45
import re
56
from collections import OrderedDict
67
from math import floor, log10
@@ -23,7 +24,10 @@
2324
from skll.data import FeatureSet, NDJWriter
2425
from skll.types import PathOrStr
2526

26-
tests_dir = Path(__file__).resolve().parent.parent.parent / "tests"
27+
if env_test_dir := os.getenv("TESTDIR"):
28+
tests_dir = Path(env_test_dir) / "tests"
29+
else:
30+
tests_dir = Path(__file__).resolve().parent.parent.parent / "tests"
2731
config_dir = tests_dir / "configs"
2832
backward_compatibility_dir = tests_dir / "backward_compatibility"
2933
examples_dir = tests_dir.parent / "examples"

tests/test_input.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -85,26 +85,27 @@ def test_locate_file_valid_paths1(self):
8585
"""Test that `config.locate_file` works with absolute paths."""
8686
config_abs_path = config_dir / "test_config_parsing_relative_path1.cfg"
8787
open(config_abs_path, "w").close()
88-
self.assertEqual(
89-
locate_file(config_abs_path, tests_dir),
90-
str(config_dir / "test_config_parsing_relative_path1.cfg"),
91-
)
88+
computed_path = locate_file(config_abs_path, tests_dir)
89+
expected_path = str(config_dir / "test_config_parsing_relative_path1.cfg")
90+
self.assertEqual(Path(computed_path).resolve(), Path(expected_path).resolve())
9291

9392
def test_locate_file_valid_paths2(self):
9493
"""Test that `config.locate_file` works with relative paths."""
9594
config_abs_path = config_dir / "test_config_parsing_relative_path2.cfg"
9695
config_rel_path = "configs/test_config_parsing_relative_path2.cfg"
9796
open(config_abs_path, "w").close()
98-
self.assertEqual(locate_file(config_rel_path, tests_dir), str(config_abs_path))
97+
computed_path = locate_file(config_rel_path, tests_dir)
98+
expected_path = str(config_abs_path)
99+
self.assertEqual(Path(computed_path).resolve(), Path(expected_path).resolve())
99100

100101
def test_locate_file_valid_paths3(self):
101102
"""Test that `config.locate_file` works with relative/absolute paths."""
102103
config_abs_path = config_dir / "test_config_parsing_relative_path3.cfg"
103104
config_rel_path = "configs/test_config_parsing_relative_path3.cfg"
104105
open(config_abs_path, "w").close()
105-
self.assertEqual(
106-
locate_file(config_abs_path, tests_dir), locate_file(config_rel_path, tests_dir)
107-
)
106+
computed_path = locate_file(config_abs_path, tests_dir)
107+
expected_path = locate_file(config_rel_path, tests_dir)
108+
self.assertEqual(Path(computed_path).resolve(), Path(expected_path).resolve())
108109

109110
def test_locate_file_invalid_path(self):
110111
"""Test that `config.locate_file` raises error for paths that do not exist."""

0 commit comments

Comments
 (0)