diff --git a/CHANGES.md b/CHANGES.md index 54ec758..336916e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 diff --git a/tests/test_execute.py b/tests/test_execute.py index f30a7bb..8244cef 100644 --- a/tests/test_execute.py +++ b/tests/test_execute.py @@ -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 """ @@ -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()}" ) @@ -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 @@ -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 """ @@ -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 """ @@ -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( @@ -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)) @@ -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)) @@ -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)) @@ -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"), @@ -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 """ @@ -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 """ @@ -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 """ @@ -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)) @@ -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}, @@ -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 """ @@ -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 diff --git a/tests/test_latex_dependency_scanner.py b/tests/test_latex_dependency_scanner.py index a68081e..5553c93 100644 --- a/tests/test_latex_dependency_scanner.py +++ b/tests/test_latex_dependency_scanner.py @@ -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 """ diff --git a/tests/test_normal_execution_w_plugin.py b/tests/test_normal_execution_w_plugin.py deleted file mode 100644 index a5ce537..0000000 --- a/tests/test_normal_execution_w_plugin.py +++ /dev/null @@ -1,39 +0,0 @@ -"""Contains tests which do not require the plugin and ensure normal execution.""" -from __future__ import annotations - -import textwrap - -import pytest -from pytask import ExitCode -from pytask import cli - - -@pytest.mark.end_to_end() -@pytest.mark.parametrize( - "dependencies", - [(), ("in.txt",), ("in_1.txt", "in_2.txt")], -) -@pytest.mark.parametrize("products", [("out.txt",), ("out_1.txt", "out_2.txt")]) -def test_execution_w_varying_dependencies_products( - runner, tmp_path, dependencies, products -): - source = f""" - import pytask - from pathlib import Path - - @pytask.mark.depends_on({dependencies}) - @pytask.mark.produces({products}) - def task_dummy(depends_on, produces): - if isinstance(produces, dict): - produces = produces.values() - elif isinstance(produces, Path): - produces = [produces] - for product in produces: - product.touch() - """ - tmp_path.joinpath("task_dummy.py").write_text(textwrap.dedent(source)) - for dependency in dependencies: - tmp_path.joinpath(dependency).touch() - - result = runner.invoke(cli, [tmp_path.as_posix()]) - assert result.exit_code == ExitCode.OK diff --git a/tests/test_parallel.py b/tests/test_parallel.py index 2106c3e..9b8aa68 100644 --- a/tests/test_parallel.py +++ b/tests/test_parallel.py @@ -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 """ @@ -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( diff --git a/tests/test_parametrize.py b/tests/test_parametrize.py index e65f262..09a611b 100644 --- a/tests/test_parametrize.py +++ b/tests/test_parametrize.py @@ -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 """ @@ -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(