Skip to content

Update syntax of tests. #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ releases are available on [Anaconda.org](https://anaconda.org/conda-forge/pytask

- {pull}`65` simplifies dependency management.
- {pull}`66` removes using `MetaNode`.
- {pull}`72` updates syntax of tests.

## 0.4.1 - 2023-10-12

Expand Down
104 changes: 52 additions & 52 deletions tests/test_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ def test_pytask_execute_task_setup(monkeypatch):
def test_compile_latex_document(runner, tmp_path):
"""Test simple compilation."""
task_source = """
import pytask
from pytask import mark

@pytask.mark.latex(script="document.tex", document="document.pdf")
@mark.latex(script="document.tex", document="document.pdf")
def task_compile_document():
pass
"""
Expand All @@ -63,9 +63,9 @@ def task_compile_document():
def test_compile_latex_document_w_relative(runner, tmp_path):
"""Test simple compilation."""
task_source = f"""
import pytask
from pytask import mark

@pytask.mark.latex(
@mark.latex(
script="document.tex",
document="{tmp_path.joinpath("bld", "document.pdf").as_posix()}"
)
Expand Down Expand Up @@ -95,9 +95,9 @@ def task_compile_document():
def test_compile_latex_document_to_different_name(runner, tmp_path):
"""Compile a LaTeX document where source and output name differ."""
task_source = """
import pytask
from pytask import mark

@pytask.mark.latex(script="in.tex", document="out.pdf")
@mark.latex(script="in.tex", document="out.pdf")
def task_compile_document():
pass

Expand All @@ -122,12 +122,11 @@ def task_compile_document():
def test_compile_w_bibliography(runner, tmp_path):
"""Compile a LaTeX document with bibliography."""
task_source = """
import pytask
from pytask import task
from pytask import task, mark
from pathlib import Path

@task(kwargs={"path": Path("references.bib")})
@pytask.mark.latex(script="in_w_bib.tex", document="out_w_bib.pdf")
@mark.latex(script="in_w_bib.tex", document="out_w_bib.pdf")
def task_compile_document():
pass
"""
Expand Down Expand Up @@ -162,9 +161,9 @@ def task_compile_document():
@pytest.mark.end_to_end()
def test_raise_error_if_latexmk_is_not_found(tmp_path, monkeypatch):
task_source = """
import pytask
from pytask import mark

@pytask.mark.latex(script="document.tex", document="document.pdf")
@mark.latex(script="document.tex", document="document.pdf")
def task_compile_document():
pass
"""
Expand Down Expand Up @@ -196,10 +195,10 @@ def task_compile_document():
@pytest.mark.end_to_end()
def test_compile_latex_document_w_xelatex(runner, tmp_path):
task_source = """
import pytask
from pytask import mark
from pytask_latex import compilation_steps

@pytask.mark.latex(
@mark.latex(
script="document.tex",
document="document.pdf",
compilation_steps=compilation_steps.latexmk(
Expand Down Expand Up @@ -231,11 +230,11 @@ def task_compile_document():
@pytest.mark.end_to_end()
def test_compile_latex_document_w_two_dependencies(runner, tmp_path):
task_source = """
import pytask
from pytask import mark
from pathlib import Path

@pytask.mark.latex(script="document.tex", document="document.pdf")
@pytask.mark.depends_on("in.txt")
def task_compile_document():
@mark.latex(script="document.tex", document="document.pdf")
def task_compile_document(path: Path = Path("in.txt")):
pass
"""
tmp_path.joinpath("task_dummy.py").write_text(textwrap.dedent(task_source))
Expand All @@ -259,11 +258,11 @@ def task_compile_document():
@pytest.mark.end_to_end()
def test_fail_because_script_is_not_latex(tmp_path):
task_source = """
import pytask
from pytask import mark
from pathlib import Path

@pytask.mark.latex(script="document.text", document="document.pdf")
@pytask.mark.depends_on("in.txt")
def task_compile_document():
@mark.latex(script="document.text", document="document.pdf")
def task_compile_document(path: Path = Path("in.txt")):
pass
"""
tmp_path.joinpath("task_dummy.py").write_text(textwrap.dedent(task_source))
Expand Down Expand Up @@ -297,11 +296,11 @@ def test_compile_document_to_out_if_document_has_relative_resources(tmp_path):
tmp_path.joinpath("sub", "resources").mkdir(parents=True)

task_source = """
import pytask
from pytask import mark
from pathlib import Path

@pytask.mark.latex(script="document.tex", document="out/document.pdf")
@pytask.mark.depends_on("resources/content.tex")
def task_compile_document():
@mark.latex(script="document.tex", document="out/document.pdf")
def task_compile_document(path: Path = Path("resources/content.tex")):
pass
"""
tmp_path.joinpath("sub", "task_dummy.py").write_text(textwrap.dedent(task_source))
Expand Down Expand Up @@ -333,10 +332,10 @@ def test_compile_document_w_wrong_flag(tmp_path):
tmp_path.joinpath("sub").mkdir(parents=True)

task_source = """
import pytask
from pytask import mark
from pytask_latex import compilation_steps

@pytask.mark.latex(
@mark.latex(
script="document.tex",
document="out/document.pdf",
compilation_steps=compilation_steps.latexmk("--wrong-flag"),
Expand Down Expand Up @@ -365,17 +364,19 @@ def task_compile_document():
@pytest.mark.end_to_end()
def test_compile_document_w_image(runner, tmp_path):
task_source = f"""
import pytask
from pytask import Product
import shutil
from typing_extensions import Annotated
from pathlib import Path
from pytask import mark

@pytask.mark.produces("image.png")
def task_create_image():
def task_create_image(image: Annotated[Path, Product] = Path("image.png")):
shutil.copy(
"{TEST_RESOURCES.joinpath("image.png").as_posix()}",
"{tmp_path.joinpath("image.png").as_posix()}"
)

@pytask.mark.latex(script="document.tex", document="document.pdf")
@mark.latex(script="document.tex", document="document.pdf")
def task_compile_document():
pass
"""
Expand All @@ -400,10 +401,10 @@ def task_compile_document():
def test_compile_latex_document_w_multiple_marks(runner, tmp_path):
"""Test simple compilation."""
task_source = """
import pytask
from pytask import mark

@pytask.mark.latex(script="document.text")
@pytask.mark.latex(script="document.tex", document="document.pdf")
@mark.latex(script="document.text")
@mark.latex(script="document.tex", document="document.pdf")
def task_compile_document():
pass
"""
Expand All @@ -428,9 +429,9 @@ def task_compile_document():
def test_compile_latex_document_with_wrong_extension(runner, tmp_path):
"""Test simple compilation."""
task_source = """
import pytask
from pytask import mark

@pytask.mark.latex(script="document.tex", document="document.file")
@mark.latex(script="document.tex", document="document.file")
def task_compile_document():
pass
"""
Expand All @@ -455,15 +456,15 @@ def task_compile_document():
def test_compile_w_bibliography_and_keep_bbl(runner, tmp_path):
"""Compile a LaTeX document with bibliography."""
task_source = """
import pytask
from pytask import mark, Product
from pathlib import Path
from typing_extensions import Annotated

@pytask.mark.produces("out_w_bib.bbl")
@pytask.mark.latex(
script="in_w_bib.tex",
document="out_w_bib.pdf",
)
@pytask.mark.depends_on("references.bib")
def task_compile_document():
@mark.latex(script="in_w_bib.tex", document="out_w_bib.pdf")
def task_compile_document(
bibliography: Path = Path("references.bib"),
bbl: Annotated[Path, Product] = Path("out_w_bib.bbl"),
):
pass
"""
tmp_path.joinpath("task_dummy.py").write_text(textwrap.dedent(task_source))
Expand Down Expand Up @@ -508,9 +509,9 @@ def test_compile_latex_document_w_unknown_compilation_step(
):
"""Test simple compilation."""
task_source = f"""
import pytask
from pytask import mark

@pytask.mark.latex(
@mark.latex(
script="document.tex",
document="document.pdf",
compilation_steps={step},
Expand Down Expand Up @@ -539,10 +540,10 @@ def task_compile_document():
def test_compile_latex_document_with_task_decorator(runner, tmp_path):
"""Test simple compilation."""
task_source = """
import pytask
from pytask import mark, task

@pytask.mark.latex(script="document.tex", document="document.pdf")
@pytask.mark.task
@mark.latex(script="document.tex", document="document.pdf")
@task
def compile_document():
pass
"""
Expand Down Expand Up @@ -594,12 +595,11 @@ def test_use_task_without_path(tmp_path):
def test_collect_latex_document_with_product_from_another_task(runner, tmp_path):
"""Test simple compilation."""
task_source = """
import pytask
from pathlib import Path
from pytask import Product
from pytask import Product, mark
from typing_extensions import Annotated

@pytask.mark.latex(script="document.tex", document="document.pdf")
@mark.latex(script="document.tex", document="document.pdf")
def task_compile_document(): pass


Expand Down
4 changes: 2 additions & 2 deletions tests/test_latex_dependency_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
@pytest.mark.parametrize("infer_dependencies", ["true", "false"])
def test_infer_dependencies_from_task(tmp_path, infer_dependencies):
task_source = """
import pytask
from pytask import mark

@pytask.mark.latex(script="document.tex", document="document.pdf")
@mark.latex(script="document.tex", document="document.pdf")
def task_compile_document():
pass
"""
Expand Down
39 changes: 0 additions & 39 deletions tests/test_normal_execution_w_plugin.py

This file was deleted.

12 changes: 6 additions & 6 deletions tests/test_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
@pytest.mark.end_to_end()
def test_parallel_parametrization_over_source_files_w_loop(runner, tmp_path):
source = """
import pytask
from pytask import mark, task

for i in range(1, 3):

@pytask.mark.task
@pytask.mark.latex(script=f"document_{i}.tex", document=f"document_{i}.pdf")
@task
@mark.latex(script=f"document_{i}.tex", document=f"document_{i}.pdf")
def task_compile_latex_document():
pass
"""
Expand Down Expand Up @@ -70,13 +70,13 @@ def task_compile_latex_document():
@pytest.mark.end_to_end()
def test_parallel_parametrization_over_source_file_w_loop(runner, tmp_path):
source = """
import pytask
from pytask import mark, task
from pytask_latex import compilation_steps as cs

for ending in ("pdf", "dvi"):

@pytask.mark.task
@pytask.mark.latex(
@task
@mark.latex(
script="document.tex",
document=f"document.{ending}",
compilation_steps=cs.latexmk(
Expand Down
10 changes: 6 additions & 4 deletions tests/test_parametrize.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
@pytest.mark.end_to_end()
def test_parametrized_compilation_of_latex_documents_w_loop(tmp_path):
source = """
from pytask import mark, task
import pytask

for i in range(1, 3):

@pytask.mark.task
@pytask.mark.latex(script=f"document_{i}.tex", document=f"document_{i}.pdf")
@task
@mark.latex(script=f"document_{i}.tex", document=f"document_{i}.pdf")
def task_compile_latex_document():
pass
"""
Expand Down Expand Up @@ -50,13 +51,14 @@ def task_compile_latex_document():
@pytest.mark.end_to_end()
def test_parametrizing_latex_options_w_loop(tmp_path):
source = """
from pytask import mark, task
import pytask
from pytask_latex import compilation_steps as cs

for ending in ("pdf", "dvi"):

@pytask.mark.task
@pytask.mark.latex(
@task
@mark.latex(
script="document.tex",
document=f"document.{ending}",
compilation_steps=cs.latexmk(
Expand Down