14
14
ids = ("use_env" , "no_env" )
15
15
)
16
16
@pytest .mark .parametrize (
17
- "use_file" , (None , "basic" , "extended" ),
18
- ids = ("no_file" , "basic_file" , "extended_file" )
17
+ "use_file" , (None , "basic" , "extended" , "pyproject.toml" ),
18
+ ids = ("no_file" , "basic_file" , "extended_file" , "pyproject_toml" )
19
19
)
20
20
@pytest .mark .parametrize (
21
21
"use_args" , (True , False ),
@@ -35,8 +35,11 @@ def test_config_setup(
35
35
_other_url : str = "http://simvue.example.com/"
36
36
_arg_url : str = "http://simvue.example.io/"
37
37
_description : str = "test case for runs"
38
+ _description_ppt : str = "test case for runs using pyproject.toml"
38
39
_folder : str = "/test-case"
40
+ _folder_ppt : str = "/test-case-ppt"
39
41
_tags : list [str ] = ["tag-test" , "other-tag" ]
42
+ _tags_ppt : list [str ] = ["tag-test-ppt" , "other-tag-ppt" ]
40
43
41
44
# Deactivate the server checks for this test
42
45
monkeypatch .setenv ("SIMVUE_NO_SERVER_CHECK" , "True" )
@@ -49,10 +52,24 @@ def test_config_setup(
49
52
50
53
with tempfile .TemporaryDirectory () as temp_d :
51
54
_config_file = None
55
+ _ppt_file = None
52
56
if use_file :
57
+ if use_file == "pyproject.toml" :
58
+ _lines_ppt : str = f"""
59
+ [tool.poetry]
60
+ name = "simvue_testing"
61
+ version = "0.1.0"
62
+ description = "A dummy test project"
63
+
64
+ [tool.simvue.run]
65
+ description = "{ _description_ppt } "
66
+ folder = "{ _folder_ppt } "
67
+ tags = { _tags_ppt }
68
+ """
69
+ with open ((_ppt_file := pathlib .Path (temp_d ).joinpath ("pyproject.toml" )), "w" ) as out_f :
70
+ out_f .write (_lines_ppt )
53
71
with open (_config_file := pathlib .Path (temp_d ).joinpath ("simvue.toml" ), "w" ) as out_f :
54
- if use_file :
55
- _lines : str = f"""
72
+ _lines : str = f"""
56
73
[server]
57
74
url = "{ _url } "
58
75
token = "{ _token } "
@@ -72,7 +89,15 @@ def test_config_setup(
72
89
SimvueConfiguration .config_file .cache_clear ()
73
90
74
91
mocker .patch ("simvue.config.parameters.get_expiry" , lambda * _ , ** __ : 1e10 )
75
- mocker .patch ("simvue.config.user.sv_util.find_first_instance_of_file" , lambda * _ , ** __ : _config_file )
92
+
93
+
94
+ def _mocked_find (file_names : list [str ], * _ , ppt_file = _ppt_file , conf_file = _config_file , ** __ ) -> str :
95
+ if "pyproject.toml" in file_names :
96
+ return ppt_file
97
+ else :
98
+ return conf_file
99
+
100
+ mocker .patch ("simvue.config.user.sv_util.find_first_instance_of_file" , _mocked_find )
76
101
77
102
import simvue .config .user
78
103
@@ -88,7 +113,7 @@ def test_config_setup(
88
113
else :
89
114
_config = simvue .config .user .SimvueConfiguration .fetch ()
90
115
91
- if use_file :
116
+ if use_file and use_file != "pyproject.toml" :
92
117
assert _config .config_file () == _config_file
93
118
94
119
if use_env :
@@ -97,7 +122,7 @@ def test_config_setup(
97
122
elif use_args :
98
123
assert _config .server .url == _arg_url
99
124
assert _config .server .token == _arg_token
100
- elif use_file :
125
+ elif use_file and use_file != "pyproject.toml" :
101
126
assert _config .server .url == _url
102
127
assert _config .server .token == _token
103
128
assert _config .offline .cache == temp_d
@@ -106,6 +131,10 @@ def test_config_setup(
106
131
assert _config .run .description == _description
107
132
assert _config .run .folder == _folder
108
133
assert _config .run .tags == _tags
134
+ elif use_file == "pyproject.toml" :
135
+ assert _config .run .description == _description_ppt
136
+ assert _config .run .folder == _folder_ppt
137
+ assert _config .run .tags == _tags_ppt
109
138
elif use_file :
110
139
assert _config .run .folder == "/"
111
140
assert not _config .run .description
0 commit comments