66import pytest
77from pony import orm
88from pytask import cli
9- from pytask import db
109from pytask import ExitCode
1110from pytask_environment .database import Environment
1211
12+ # Can be removed with pytask v0.4.
13+ try :
14+ from pytask import db
15+ except ImportError :
16+ from _pytask .database_utils import db
17+
1318
1419@pytest .mark .end_to_end
1520def test_existence_of_python_executable_in_db (tmp_path , runner ):
1621 """Test that the Python executable is stored in the database."""
1722 task_path = tmp_path .joinpath ("task_dummy.py" )
1823 task_path .write_text (textwrap .dedent ("def task_dummy(): pass" ))
19- tmp_path .joinpath ("pytask.ini " ).write_text ("[pytask]" )
24+ tmp_path .joinpath ("pyproject.toml " ).write_text ("[tool. pytask.ini_options ]" )
2025
2126 result = runner .invoke (cli , [tmp_path .as_posix ()])
2227
@@ -34,13 +39,7 @@ def test_existence_of_python_executable_in_db(tmp_path, runner):
3439
3540
3641@pytest .mark .end_to_end
37- @pytest .mark .parametrize (
38- "config_file, content" ,
39- [("pytask.ini" , "[pytask]" ), ("pyproject.toml" , "[tool.pytask.ini_options]" )],
40- )
41- def test_flow_when_python_version_has_changed (
42- monkeypatch , tmp_path , runner , config_file , content
43- ):
42+ def test_flow_when_python_version_has_changed (monkeypatch , tmp_path , runner ):
4443 """Test the whole use-case.
4544
4645 1. Run a simple task to cache the Python version and path.
@@ -57,7 +56,7 @@ def test_flow_when_python_version_has_changed(
5756 "[MSC v.1916 64 bit (AMD64)]"
5857 )
5958
60- tmp_path .joinpath (config_file ).write_text (content )
59+ tmp_path .joinpath ("pyproject.toml" ).write_text ("[tool.pytask.ini_options]" )
6160 source = "def task_dummy(): pass"
6261 task_path = tmp_path .joinpath ("task_dummy.py" )
6362 task_path .write_text (textwrap .dedent (source ))
@@ -98,22 +97,17 @@ def test_flow_when_python_version_has_changed(
9897
9998
10099@pytest .mark .end_to_end
101- @pytest .mark .parametrize (
102- "config_file, content" ,
103- [
104- ("pytask.ini" , "[pytask]\n check_python_version = {}" ),
105- ("pyproject.toml" , "[tool.pytask.ini_options]\n check_python_version = {}" ),
106- ],
107- )
108100@pytest .mark .parametrize ("check_python_version, expected" , [("true" , 1 ), ("false" , 0 )])
109101def test_python_version_changed (
110- monkeypatch , tmp_path , runner , config_file , content , check_python_version , expected
102+ monkeypatch , tmp_path , runner , check_python_version , expected
111103):
112104 fake_version = (
113105 "2.7.8 | packaged by conda-forge | (default, Jul 31 2020, 01:53:57) "
114106 "[MSC v.1916 64 bit (AMD64)]"
115107 )
116- tmp_path .joinpath (config_file ).write_text (content .format (check_python_version ))
108+ tmp_path .joinpath ("pyproject.toml" ).write_text (
109+ f"[tool.pytask.ini_options]\n check_python_version = { check_python_version } "
110+ )
117111 source = "def task_dummy(): pass"
118112 task_path = tmp_path .joinpath ("task_dummy.py" )
119113 task_path .write_text (textwrap .dedent (source ))
@@ -136,18 +130,13 @@ def test_python_version_changed(
136130
137131
138132@pytest .mark .end_to_end
139- @pytest .mark .parametrize (
140- "config_file, content" ,
141- [
142- ("pytask.ini" , "[pytask]\n check_environment = {}" ),
143- ("pyproject.toml" , "[tool.pytask.ini_options]\n check_environment = {}" ),
144- ],
145- )
146133@pytest .mark .parametrize ("check_python_version, expected" , [("true" , 1 ), ("false" , 0 )])
147134def test_environment_changed (
148- monkeypatch , tmp_path , runner , config_file , content , check_python_version , expected
135+ monkeypatch , tmp_path , runner , check_python_version , expected
149136):
150- tmp_path .joinpath (config_file ).write_text (content .format (check_python_version ))
137+ tmp_path .joinpath ("pyproject.toml" ).write_text (
138+ f"[tool.pytask.ini_options]\n check_environment = { check_python_version } "
139+ )
151140 source = "def task_dummy(): pass"
152141 task_path = tmp_path .joinpath ("task_dummy.py" )
153142 task_path .write_text (textwrap .dedent (source ))
0 commit comments