Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- Convert AttributeError to ImportError.
- Use pytest.importorskip() per the ImportError.
- Create genno.testing.MARK and apply to affected tests.
  • Loading branch information
khaeru committed Jun 19, 2024
1 parent 1a959e2 commit e22eeda
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ repos:
- importlib_resources
- lxml-stubs
- nbclient
- matplotlib
- pint
- pytest
- sdmx1
Expand Down
7 changes: 6 additions & 1 deletion genno/compat/pyam/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
)
from warnings import warn

import pyam
try:
import pyam
except AttributeError as e:
# https://github.com/unionai-oss/pandera/issues/1656 via pyam-iamc and ixmp4.
# Convert AttributeError to ImportError
raise ImportError("pandera") from e

import genno
import genno.operator
Expand Down
11 changes: 11 additions & 0 deletions genno/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys
from contextlib import nullcontext
from functools import partial
from importlib.metadata import version
from itertools import chain, islice
from typing import TYPE_CHECKING, ContextManager, Dict

Expand Down Expand Up @@ -33,6 +34,16 @@

log = logging.getLogger(__name__)

# Common marks

MARK = {
0: pytest.mark.xfail(
condition=version("numpy") > "2",
reason="https://github.com/unionai-oss/pandera/issues/1656 via pyam-iamc/ixmp4",
)
}


# Pytest hooks


Expand Down
6 changes: 6 additions & 0 deletions genno/tests/compat/test_compat.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
from genno.testing import MARK

MARK_0 = MARK[0] # py38 compatibility


@MARK_0
def test_import_pyam():
""".compat.pyam.operator is populated only if pyam itself is installed.
Expand Down
8 changes: 6 additions & 2 deletions genno/tests/compat/test_pyam.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@
from pandas.testing import assert_frame_equal, assert_series_equal

from genno import Computer, Key, Quantity
from genno.compat.pyam import operator, util
from genno.compat.pyam import util
from genno.operator import add, load_file
from genno.testing import assert_logs, assert_units

if TYPE_CHECKING:
import pathlib

# Skip this entire file if pyam is not installed
# Skip this entire file if pyam is not installed or cannot be imported
operator = pytest.importorskip(
"genno.compat.pyam.operator",
reason="https://github.com/unionai-oss/pandera/issues/1656 via pyam-iamc/ixmp4",
)
pyam = pytest.importorskip("pyam", reason="pyam-iamc not installed")

# Warning emitted by pandas ≥ 2.1.0 with pyam 1.9.0
Expand Down

0 comments on commit e22eeda

Please sign in to comment.