Skip to content

Commit

Permalink
Apply the usetex-test to all other tex-or-not bundles
Browse files Browse the repository at this point in the history
  • Loading branch information
pnkraemer committed Sep 24, 2024
1 parent cd7dc6f commit 6808e91
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 17 deletions.
46 changes: 43 additions & 3 deletions tests/test_bundles_error_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
from tueplots import bundles


@pytest_cases.case(tags=["multicol"])
@pytest_cases.case(tags=["multicol", "tex_or_not"])
def case_bundle_cvpr2024():
return bundles.cvpr2024


@pytest_cases.case(tags=["multicol"])
@pytest_cases.case(tags=["multicol", "tex_or_not"])
def case_bundle_icml2022():
return bundles.icml2022


@pytest_cases.case(tags=["multicol"])
@pytest_cases.case(tags=["multicol", "tex_or_not"])
def case_bundle_icml2024():
return bundles.icml2024

Expand Down Expand Up @@ -46,6 +46,36 @@ def case_bundle_uai2024():
return bundles.uai2023


@pytest_cases.case(tags=["tex_or_not"])
def case_bundle_neurips2021():
return bundles.neurips2021


@pytest_cases.case(tags=["tex_or_not"])
def case_bundle_neurips2022():
return bundles.neurips2022


@pytest_cases.case(tags=["tex_or_not"])
def case_bundle_neurips2023():
return bundles.neurips2023


@pytest_cases.case(tags=["tex_or_not"])
def case_bundle_neurips2024():
return bundles.neurips2024


@pytest_cases.case(tags=["tex_or_not"])
def case_bundle_iclr2023():
return bundles.iclr2023


@pytest_cases.case(tags=["tex_or_not"])
def case_bundle_iclr2024():
return bundles.iclr2024


@pytest_cases.parametrize_with_cases("bundle_fun", cases=".", has_tag=["multicol"])
def test_column_neither_half_nor_full_raises_value_error(bundle_fun):
# Sanity checks
Expand All @@ -54,3 +84,13 @@ def test_column_neither_half_nor_full_raises_value_error(bundle_fun):

with pytest.raises(ValueError, match="expected"):
_ = bundle_fun(column="anything-but-half")


@pytest_cases.parametrize_with_cases("bundle_fun", cases=".", has_tag=["tex_or_not"])
def test_usetex_must_be_bool_otherwise_type_error(bundle_fun):
# Sanity checks
_ = bundle_fun(usetex=True)
_ = bundle_fun(usetex=False)

with pytest.raises(ValueError, match="expected"):
_ = bundle_fun(usetex=2)
52 changes: 38 additions & 14 deletions tueplots/bundles.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ def cvpr2024(*, column="half", nrows=1, ncols=1, usetex=True, family="serif"):
elif column == "full":
size = figsizes.cvpr2024_full(nrows=nrows, ncols=ncols)
else:
msg = _msg_error_wrong_column_arg(column)
msg = _msg_error_wrong_arg_column(column)
raise ValueError(msg)
if usetex is True:
font_config = fonts.cvpr2024_tex(family=family)
elif usetex is False:
font_config = fonts.cvpr2024(family=family)
else:
raise ValueError(_msg_error_wrong_arg_usetex(usetex))
fontsize_config = fontsizes.cvpr2024()
return {**font_config, **size, **fontsize_config}

Expand All @@ -28,12 +30,14 @@ def icml2022(*, column="half", nrows=1, ncols=1, usetex=True, family="serif"):
elif column == "full":
size = figsizes.icml2022_full(nrows=nrows, ncols=ncols)
else:
msg = _msg_error_wrong_column_arg(column)
msg = _msg_error_wrong_arg_column(column)
raise ValueError(msg)
if usetex is True:
font_config = fonts.icml2022_tex(family=family)
elif usetex is False:
font_config = fonts.icml2022(family=family)
else:
raise ValueError(_msg_error_wrong_arg_usetex(usetex))
fontsize_config = fontsizes.icml2022()
return {**font_config, **size, **fontsize_config}

Expand All @@ -45,12 +49,14 @@ def icml2024(*, column="half", nrows=1, ncols=1, usetex=True, family="serif"):
elif column == "full":
size = figsizes.icml2024_full(nrows=nrows, ncols=ncols)
else:
msg = _msg_error_wrong_column_arg(column)
msg = _msg_error_wrong_arg_column(column)
raise ValueError(msg)
if usetex is True:
font_config = fonts.icml2024_tex(family=family)
elif usetex is False:
font_config = fonts.icml2024(family=family)
else:
raise ValueError(_msg_error_wrong_arg_usetex(usetex))
fontsize_config = fontsizes.icml2024()
return {**font_config, **size, **fontsize_config}

Expand All @@ -62,7 +68,7 @@ def aistats2022(*, column="half", nrows=1, ncols=1, family="serif"):
elif column == "full":
size = figsizes.aistats2022_full(nrows=nrows, ncols=ncols)
else:
msg = _msg_error_wrong_column_arg(column)
msg = _msg_error_wrong_arg_column(column)
raise ValueError(msg)
font_config = fonts.aistats2022_tex(family=family)
fontsize_config = fontsizes.aistats2022()
Expand All @@ -76,7 +82,7 @@ def aistats2023(*, column="half", nrows=1, ncols=1, family="serif"):
elif column == "full":
size = figsizes.aistats2023_full(nrows=nrows, ncols=ncols)
else:
msg = _msg_error_wrong_column_arg(column)
msg = _msg_error_wrong_arg_column(column)
raise ValueError(msg)
font_config = fonts.aistats2023_tex(family=family)
fontsize_config = fontsizes.aistats2023()
Expand All @@ -90,7 +96,7 @@ def aistats2025(*, column="half", nrows=1, ncols=1, family="serif"):
elif column == "full":
size = figsizes.aistats2025_full(nrows=nrows, ncols=ncols)
else:
msg = _msg_error_wrong_column_arg(column)
msg = _msg_error_wrong_arg_column(column)
raise ValueError(msg)
font_config = fonts.aistats2025_tex(family=family)
fontsize_config = fontsizes.aistats2025()
Expand All @@ -107,7 +113,7 @@ def aaai2024(*, column="half", nrows=1, ncols=1, family="serif", rel_width=1.0):
elif column == "full":
size = figsizes.aaai2024_full(nrows=nrows, ncols=ncols, rel_width=rel_width)
else:
msg = _msg_error_wrong_column_arg(column)
msg = _msg_error_wrong_arg_column(column)
raise ValueError(msg)
font_config = fonts.aaai2024_tex(family=family)
fontsize_config = fontsizes.aaai2024()
Expand All @@ -121,19 +127,13 @@ def uai2023(*, column="half", nrows=1, ncols=1, family="serif"):
elif column == "full":
size = figsizes.uai2023_full(nrows=nrows, ncols=ncols)
else:
msg = _msg_error_wrong_column_arg(column)
msg = _msg_error_wrong_arg_column(column)
raise ValueError(msg)
font_config = fonts.uai2023_tex(family=family)
fontsize_config = fontsizes.uai2023()
return {**font_config, **size, **fontsize_config}


def _msg_error_wrong_column_arg(column):
msg = f"Argument column={column} unknown."
msg += "Either column='half' or column='full' expected."
return msg


def eccv2024(*, rel_width=1.0, nrows=1, ncols=1, family="serif"):
"""ECCV 2024 bundle."""
size = figsizes.eccv2024(rel_width=rel_width, nrows=nrows, ncols=ncols)
Expand Down Expand Up @@ -164,6 +164,8 @@ def neurips2021(*, usetex=True, rel_width=1.0, nrows=1, ncols=1, family="serif")
font_config = fonts.neurips2021_tex(family=family)
elif usetex is False:
font_config = fonts.neurips2021(family=family)
else:
raise ValueError(_msg_error_wrong_arg_usetex(usetex))
size = figsizes.neurips2021(rel_width=rel_width, nrows=nrows, ncols=ncols)
fontsize_config = fontsizes.neurips2021()
return {**font_config, **size, **fontsize_config}
Expand All @@ -175,6 +177,8 @@ def neurips2022(*, usetex=True, rel_width=1.0, nrows=1, ncols=1, family="serif")
font_config = fonts.neurips2022_tex(family=family)
elif usetex is False:
font_config = fonts.neurips2022(family=family)
else:
raise ValueError(_msg_error_wrong_arg_usetex(usetex))
size = figsizes.neurips2022(rel_width=rel_width, nrows=nrows, ncols=ncols)
fontsize_config = fontsizes.neurips2022()
return {**font_config, **size, **fontsize_config}
Expand All @@ -186,6 +190,8 @@ def neurips2023(*, usetex=True, rel_width=1.0, nrows=1, ncols=1, family="serif")
font_config = fonts.neurips2023_tex(family=family)
elif usetex is False:
font_config = fonts.neurips2023(family=family)
else:
raise ValueError(_msg_error_wrong_arg_usetex(usetex))
size = figsizes.neurips2023(rel_width=rel_width, nrows=nrows, ncols=ncols)
fontsize_config = fontsizes.neurips2023()
return {**font_config, **size, **fontsize_config}
Expand All @@ -197,6 +203,8 @@ def neurips2024(*, usetex=True, rel_width=1.0, nrows=1, ncols=1, family="serif")
font_config = fonts.neurips2024_tex(family=family)
elif usetex is False:
font_config = fonts.neurips2024(family=family)
else:
raise ValueError(_msg_error_wrong_arg_usetex(usetex))
size = figsizes.neurips2024(rel_width=rel_width, nrows=nrows, ncols=ncols)
fontsize_config = fontsizes.neurips2024()
return {**font_config, **size, **fontsize_config}
Expand All @@ -208,6 +216,8 @@ def iclr2023(*, usetex=True, rel_width=1.0, nrows=1, ncols=1, family="serif"):
font_config = fonts.iclr2023_tex(family=family)
elif usetex is False:
font_config = fonts.iclr2023(family=family)
else:
raise ValueError(_msg_error_wrong_arg_usetex(usetex))
size = figsizes.iclr2023(rel_width=rel_width, nrows=nrows, ncols=ncols)
fontsize_config = fontsizes.iclr2023()
return {**font_config, **size, **fontsize_config}
Expand All @@ -219,11 +229,25 @@ def iclr2024(*, usetex=True, rel_width=1.0, nrows=1, ncols=1, family="serif"):
font_config = fonts.iclr2024_tex(family=family)
elif usetex is False:
font_config = fonts.iclr2024(family=family)
else:
raise ValueError(_msg_error_wrong_arg_usetex(usetex))
size = figsizes.iclr2024(rel_width=rel_width, nrows=nrows, ncols=ncols)
fontsize_config = fontsizes.iclr2024()
return {**font_config, **size, **fontsize_config}


def _msg_error_wrong_arg_usetex(usetex):
msg = f"Argument usetex={usetex} unknown."
msg += "Either usetex=True or usetex=False expected."
return msg


def _msg_error_wrong_arg_column(column):
msg = f"Argument column={column} unknown."
msg += "Either column='half' or column='full' expected."
return msg


def beamer_moml(
*,
rel_width=1.0,
Expand Down

0 comments on commit 6808e91

Please sign in to comment.