Skip to main content
Version: 0.1.1

sdvplot.testing

Shared behaviour every adapter must have. Adapter test suites call check_adapter_contract().

NameWhat it is
check_adapter_contractRaise an AssertionError naming the broken rule if the adapter breaks the sdvplot adapter contract.
check_table_adapter_contractRaise an AssertionError naming the broken rule (T0-T6) if a table adapter breaks the table contract.

check_adapter_contract​

check_adapter_contract(
adapter: module,
make_target: collections.abc.Callable[[], Any],
*,
league: str = 'nfl',
known: tuple[str, str] = ('LV', 'LAR'),
known_wordmarks: tuple[str, str] = ('LV', 'LAC'),
players: tuple[str, str] = ('3139477', '4241479'),
make_axis_target: collections.abc.Callable[[list[str]], Any] | None = None,
) -> None

Raise an AssertionError naming the broken rule if the adapter breaks the sdvplot adapter contract.

The rules, and the test hooks the adapter must expose, are in this module's docstring.

Arguments​

NameTypeDescription
adaptermoduleThe adapter module under test (it exposes add_logos, add_wordmarks, add_headshots, axis_logos and the _drawn_marks hook).
make_targetcollections.abc.Callable[[], Any]Builds a fresh target (a plot) to draw on each time it is called.
leaguestrThe SDV league key the checks run in.
knowntuple[str, str]Two team ids of league that have logos.
known_wordmarkstuple[str, str]Two team ids of league that have wordmarks.
playerstuple[str, str]Two player ids of league that have headshots.
make_axis_targetcollections.abc.Callable[[list[str]], Any] | Nonemake_axis_target(categories) builds a target whose x axis shows those categories, in order. Required when the adapter supports axis logos (rule 7).

Returns​

None — Returns normally when every rule holds.

Raises​

  • AssertionError: Naming the broken rule ("rule N: ..."), when the adapter breaks it.
  • UnsupportedTargetError: (a TypeError) If no adapter is registered for the library of make_target()'s object (register the adapter before checking it).
  • InputError: (a ValueError) If league is unknown.
  • OfflineError: If the logo manifest, which the checks read for the expected marks, is neither cached nor downloadable (a DownloadError, also an OSError, when the CDN answers with an error status). A download error inside an adapter call is reported as the AssertionError of the rule that made the call.
  • UnsafeDownloadError: (an OSError) If the manifest download is refused: larger than the byte cap, past the deadline, or redirected away from https.

Example​

import matplotlib.pyplot as plt
from sdvplot import matplotlib as adapter
from sdvplot.testing import check_adapter_contract

def make_target():
_, ax = plt.subplots()
ax.set_xlim(0, 30)
ax.set_ylim(-10, 0)
return ax

def make_axis_target(categories):
_, ax = plt.subplots()
ax.bar(categories, range(1, len(categories) + 1))
return ax

check_adapter_contract(adapter, make_target=make_target, make_axis_target=make_axis_target)

See also​

  • Add an adapter
  • sdvplot.testing.check_table_adapter_contract: the harness for table adapters

check_table_adapter_contract​

check_table_adapter_contract(
adapter: module,
make_table: collections.abc.Callable[[Any], Any],
*,
league: str = 'nfl',
known: tuple[str, str] = ('LV', 'LAR'),
known_wordmarks: tuple[str, str] = ('LV', 'LAC'),
players: tuple[str, str] = ('3139477', '4241479'),
) -> None

Raise an AssertionError naming the broken rule (T0-T6) if a table adapter breaks the table contract.

The rules and the _drawn_cells and _rendered_html hooks are in this module's docstring.

Arguments​

NameTypeDescription
adaptermoduleThe table adapter module under test (it exposes add_logos, add_wordmarks, add_headshots and the two hooks).
make_tablecollections.abc.Callable[[Any], Any]make_table(frame) builds the adapter's table from a pandas or polars DataFrame (for great_tables: GT).
leaguestrThe SDV league key the checks run in.
knowntuple[str, str]Two team ids of league that have logos.
known_wordmarkstuple[str, str]Two team ids of league that have wordmarks.
playerstuple[str, str]Two player ids of league that have headshots.

Returns​

None — Returns normally when every rule holds.

Raises​

  • AssertionError: Naming the broken rule ("rule T: ..."), when the adapter breaks it.
  • InputError: (a ValueError) If league is unknown.
  • OfflineError: If the logo manifest, which the checks read for the expected marks, is neither cached nor downloadable (a DownloadError, also an OSError, when the CDN answers with an error status). A download error inside an adapter call is reported as the AssertionError of the rule that made the call.
  • UnsafeDownloadError: (an OSError) If the manifest download is refused: larger than the byte cap, past the deadline, or redirected away from https.

Example​

from great_tables import GT
from sdvplot import great_tables as adapter
from sdvplot.testing import check_table_adapter_contract

check_table_adapter_contract(adapter, make_table=GT)

See also​

  • Add an adapter
  • sdvplot.testing.check_adapter_contract: the harness for plot adapters