Download testbed/TileDB-Inc__TileDB-Py/tiledb/tests/test_examples.py from hc99/FEA-Bench: direct link, hf CLI and curl.
- Browser
- Download file 2.64 kB
-
https://huggingface.co/datasets/hc99/FEA-Bench/resolve/main/testbed/TileDB-Inc__TileDB-Py/tiledb/tests/test_examples.py
- Command line
-
hf download hf://datasets/hc99/FEA-Bench/testbed/TileDB-Inc__TileDB-Py/tiledb/tests/test_examples.py
-
curl -L -o test_examples.py https://huggingface.co/datasets/hc99/FEA-Bench/resolve/main/testbed/TileDB-Inc__TileDB-Py/tiledb/tests/test_examples.py
2.64 kB
| import doctest | |
| import glob | |
| import os | |
| import subprocess | |
| import sys | |
| import tempfile | |
| import pytest | |
| from .common import has_pandas | |
| # override locally to avoid conflict with capsys used below | |
| def no_output(): | |
| pass | |
| class ExamplesTest: | |
| """Test runnability of scripts in examples/""" | |
| PROJECT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../")) | |
| def test_examples(self, path): | |
| # run example script | |
| # - in a separate process | |
| # - in tmpdir so we don't pollute the source tree | |
| # - with exit status checking (should fail tests if example fails) | |
| requires_pd = [ | |
| os.path.join(self.PROJECT_DIR, "examples", f"{fn}.py") | |
| for fn in [ | |
| "incomplete_iteration", | |
| "parallel_csv_ingestion", | |
| "query_condition_datetime", | |
| ] | |
| ] | |
| if not has_pandas() and path in requires_pd: | |
| pytest.mark.skip("pandas>=1.0,<3.0 not installed") | |
| else: | |
| with tempfile.TemporaryDirectory() as tmpdir: | |
| try: | |
| subprocess.run( | |
| [sys.executable, path], | |
| cwd=tmpdir, | |
| check=True, | |
| stdout=subprocess.PIPE, | |
| stderr=subprocess.PIPE, | |
| encoding="utf8", | |
| ) | |
| except subprocess.CalledProcessError as ex: | |
| pytest.fail(ex.stderr, pytrace=False) | |
| def test_docs(self, path, capsys): | |
| failures, _ = doctest.testfile( | |
| path, | |
| module_relative=False, | |
| verbose=False, | |
| optionflags=doctest.NORMALIZE_WHITESPACE, | |
| ) | |
| if failures: | |
| stderr = capsys.readouterr().out | |
| if "No module named 'pandas'" in stderr or ( | |
| "Pandas version >= 1.0 and < 3.0 required for dataframe functionality" | |
| in stderr | |
| and not has_pandas() | |
| ): | |
| pytest.skip("pandas>=1.0,<3.0 not installed") | |
| else: | |
| pytest.fail(stderr) | |