1
1
from __future__ import annotations
2
2
3
+ import os
4
+ import subprocess
5
+ import sys
3
6
import textwrap
4
7
5
8
import pytest
@@ -46,7 +49,7 @@ def test_pass_config_to_cli(tmp_path):
46
49
def test_passing_paths_via_configuration_file (tmp_path , file_or_folder ):
47
50
config = f"""
48
51
[tool.pytask.ini_options]
49
- paths = "{ file_or_folder } "
52
+ paths = [ "{ file_or_folder } "]
50
53
"""
51
54
tmp_path .joinpath ("pyproject.toml" ).write_text (textwrap .dedent (config ))
52
55
@@ -65,10 +68,60 @@ def test_passing_paths_via_configuration_file(tmp_path, file_or_folder):
65
68
def test_not_existing_path_in_config (runner , tmp_path ):
66
69
config = """
67
70
[tool.pytask.ini_options]
68
- paths = "not_existing_path"
71
+ paths = [ "not_existing_path"]
69
72
"""
70
73
tmp_path .joinpath ("pyproject.toml" ).write_text (textwrap .dedent (config ))
71
74
72
- with pytest .warns (FutureWarning , match = "Specifying paths as a string" ):
73
- result = runner .invoke (cli , [tmp_path .as_posix ()])
75
+ result = runner .invoke (cli , [tmp_path .as_posix ()])
74
76
assert result .exit_code == ExitCode .CONFIGURATION_FAILED
77
+
78
+
79
+ def test_paths_are_relative_to_configuration_file_cli (tmp_path ):
80
+ tmp_path .joinpath ("src" ).mkdir ()
81
+ tmp_path .joinpath ("tasks" ).mkdir ()
82
+ config = """
83
+ [tool.pytask.ini_options]
84
+ paths = ["../tasks"]
85
+ """
86
+ tmp_path .joinpath ("src" , "pyproject.toml" ).write_text (textwrap .dedent (config ))
87
+
88
+ source = "def task_example(): ..."
89
+ tmp_path .joinpath ("tasks" , "task_example.py" ).write_text (source )
90
+
91
+ result = subprocess .run (
92
+ ("pytask" , "src" ), cwd = tmp_path , check = False , capture_output = True
93
+ )
94
+
95
+ assert result .returncode == ExitCode .OK
96
+ assert "1 Succeeded" in result .stdout .decode ()
97
+
98
+
99
+ @pytest .mark .skipif (
100
+ sys .platform == "win32" and os .environ .get ("CI" ) == "true" ,
101
+ reason = "Windows does not pick up the right Python interpreter." ,
102
+ )
103
+ def test_paths_are_relative_to_configuration_file (tmp_path ):
104
+ tmp_path .joinpath ("src" ).mkdir ()
105
+ tmp_path .joinpath ("tasks" ).mkdir ()
106
+ config = """
107
+ [tool.pytask.ini_options]
108
+ paths = ["../tasks"]
109
+ """
110
+ tmp_path .joinpath ("src" , "pyproject.toml" ).write_text (textwrap .dedent (config ))
111
+
112
+ source = "def task_example(): ..."
113
+ tmp_path .joinpath ("tasks" , "task_example.py" ).write_text (source )
114
+
115
+ source = """
116
+ from pytask import build
117
+ from pathlib import Path
118
+
119
+ session = build(paths=[Path("src")])
120
+ """
121
+ tmp_path .joinpath ("script.py" ).write_text (textwrap .dedent (source ))
122
+ result = subprocess .run (
123
+ ("python" , "script.py" ), cwd = tmp_path , check = False , capture_output = True
124
+ )
125
+
126
+ assert result .returncode == ExitCode .OK
127
+ assert "1 Succeeded" in result .stdout .decode ()
0 commit comments