| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
import pytest |
| 4 |
|
| 5 |
pytest.register_assert_rewrite( |
| 6 |
"dask.array.utils", "dask.dataframe.utils", "dask.bag.utils" |
| 7 |
) |
| 8 |
|
| 9 |
# The doctests in these files fail due to either: |
| 10 |
# - Non-required dependencies not being installed |
| 11 |
# - Imported doctests due to pulling the docstrings from other packages |
| 12 |
# (e.g. `numpy`). No need to run these doctests. |
| 13 |
collect_ignore = [ |
| 14 |
"dask/bytes/hdfs3.py", |
| 15 |
"dask/bytes/pyarrow.py", |
| 16 |
"dask/bytes/s3.py", |
| 17 |
"dask/array/ghost.py", |
| 18 |
"dask/array/fft.py", |
| 19 |
"dask/dataframe/io/io.py", |
| 20 |
"dask/dataframe/io/parquet/arrow.py", |
| 21 |
"dask/dot.py", |
| 22 |
"dask/ml.py", |
| 23 |
] |
| 24 |
|
| 25 |
collect_ignore_glob = [] |
| 26 |
try: |
| 27 |
import numpy # noqa: F401 |
| 28 |
except ImportError: |
| 29 |
collect_ignore_glob.append("dask/array/*") |
| 30 |
|
| 31 |
try: |
| 32 |
import pandas # noqa: F401 |
| 33 |
except ImportError: |
| 34 |
collect_ignore_glob.append("dask/dataframe/*") |
| 35 |
|
| 36 |
try: |
| 37 |
import scipy # noqa: F401 |
| 38 |
except ImportError: |
| 39 |
collect_ignore.append("dask/array/stats.py") |
| 40 |
|
| 41 |
try: |
| 42 |
import pyarrow # noqa: F401 |
| 43 |
except ImportError: |
| 44 |
collect_ignore.append("dask/dataframe/io/orc/arrow.py") |
| 45 |
|
| 46 |
try: |
| 47 |
import tiledb # noqa: F401 |
| 48 |
except ImportError: |
| 49 |
collect_ignore.append("dask/array/tiledb_io.py") |
| 50 |
|
| 51 |
try: |
| 52 |
import sqlalchemy # noqa: F401 |
| 53 |
except ImportError: |
| 54 |
collect_ignore.append("dask/dataframe/io/sql.py") |
| 55 |
|
| 56 |
|
| 57 |
def pytest_addoption(parser): |
| 58 |
parser.addoption("--runslow", action="store_true", help="run slow tests") |
| 59 |
|
| 60 |
|
| 61 |
def pytest_runtest_setup(item): |
| 62 |
if "slow" in item.keywords and not item.config.getoption("--runslow"): |
| 63 |
pytest.skip("need --runslow option to run") |
| 64 |
|
| 65 |
|
| 66 |
def pytest_assertrepr_compare(op, left, right): |
| 67 |
import difflib |
| 68 |
|
| 69 |
from dask._task_spec import Task |
| 70 |
|
| 71 |
if isinstance(left, Task) and isinstance(right, Task): |
| 72 |
|
| 73 |
def _get_attrs(node): |
| 74 |
return ( |
| 75 |
[ |
| 76 |
str(node.func), |
| 77 |
] |
| 78 |
+ sorted([str(a) for a in node.args]) |
| 79 |
+ sorted([f"{k}: {v}" for k, v in node.kwargs.items()]) |
| 80 |
) |
| 81 |
|
| 82 |
diff = list( |
| 83 |
difflib.ndiff( |
| 84 |
_get_attrs(left), |
| 85 |
_get_attrs(right), |
| 86 |
) |
| 87 |
) |
| 88 |
return [ |
| 89 |
"Comparing two dask graph nodes:", |
| 90 |
f" left: {left.key} right: {right.key}", |
| 91 |
" Diff:", |
| 92 |
] + diff |