-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TST: enable tests for documentation files (#478)
* TST: enable tests for documentation files * Fix sorting of file listing * Use context manager for setting default values * Fix sorting of os.walk * Fix order in conftest.py * Skip test for pandas == 2.1.4 * Fix typo * fix cache test under MacOS, skip under Windows * Fix typo * Fix skipping of tests for caching * Fix path in quickstart under Windows * Remove unneeded import
- Loading branch information
Showing
5 changed files
with
145 additions
and
23 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,108 @@ | ||
from doctest import ELLIPSIS | ||
from doctest import NORMALIZE_WHITESPACE | ||
import os | ||
|
||
import pytest | ||
import sybil | ||
from sybil.parsers.rest import DocTestParser | ||
from sybil.parsers.rest import PythonCodeBlockParser | ||
from sybil.parsers.rest import SkipParser | ||
|
||
import audb | ||
from audb.core.conftest import cache # noqa: F401 | ||
from audb.core.conftest import imports | ||
from audb.core.conftest import public_repository # noqa: F401 | ||
|
||
|
||
class DefaultConfiguration: | ||
"""Context manager to provide default configuration values.""" | ||
|
||
def __init__(self): | ||
self.config = audb.core.config.load_configuration_file( | ||
audb.core.config.global_config_file | ||
) | ||
self._saved_state = {} | ||
|
||
def __enter__(self): | ||
"""Save current state.""" | ||
self._saved_state = { | ||
"cache_root": audb.config.CACHE_ROOT, | ||
"shared_cache_root": audb.config.SHARED_CACHE_ROOT, | ||
"repositories": audb.config.REPOSITORIES, | ||
} | ||
# Set default values | ||
audb.config.CACHE_ROOT = self.config["cache_root"] | ||
audb.config.SHARED_CACHE_ROOT = self.config["shared_cache_root"] | ||
audb.config.REPOSITORIES = [ | ||
audb.Repository(repo["name"], repo["host"], repo["backend"]) | ||
for repo in self.config["repositories"] | ||
] | ||
|
||
def __exit__(self, *args): | ||
"""Restore previous state.""" | ||
for key, value in self._saved_state.items(): | ||
setattr(audb.config, key, value) | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def default_configuration(): | ||
"""Set config values to default values.""" | ||
with DefaultConfiguration(): | ||
yield | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def run_in_tmpdir(tmpdir_factory): | ||
"""Move to a persistent tmpdir for execution of a whole file.""" | ||
tmpdir = tmpdir_factory.mktemp("tmp") | ||
current_dir = os.getcwd() | ||
os.chdir(tmpdir) | ||
|
||
yield | ||
|
||
os.chdir(current_dir) | ||
|
||
|
||
# Collect doctests | ||
# | ||
# We use several `sybil.Sybil` instances | ||
# to pass different fixtures for different files | ||
# | ||
parsers = [ | ||
DocTestParser(optionflags=ELLIPSIS + NORMALIZE_WHITESPACE), | ||
PythonCodeBlockParser(), | ||
SkipParser(), | ||
] | ||
pytest_collect_file = sybil.sybil.SybilCollection( | ||
( | ||
sybil.Sybil( | ||
parsers=parsers, | ||
filenames=[ | ||
"authentication.rst", | ||
"overview.rst", | ||
"quickstart.rst", | ||
"dependencies.rst", | ||
"load.rst", | ||
"audb.info.rst", | ||
], | ||
fixtures=[ | ||
"cache", | ||
"run_in_tmpdir", | ||
"public_repository", | ||
], | ||
setup=imports, | ||
), | ||
sybil.Sybil( | ||
parsers=parsers, | ||
filenames=["publish.rst"], | ||
fixtures=["cache", "run_in_tmpdir"], | ||
setup=imports, | ||
), | ||
sybil.Sybil( | ||
parsers=parsers, | ||
filenames=["configuration.rst", "caching.rst"], | ||
fixtures=["default_configuration"], | ||
setup=imports, | ||
), | ||
) | ||
).pytest() |
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