@@ -13,27 +13,28 @@ def process_decorator_instance():
1313# ---------------------------------------------------------------------------
1414
1515
16- def test_find_python_files (process_decorator_instance : DecoratorProcessor , tmpdir ):
17- tmpdir . join ( "pythonfile.py" ).write ("content" )
18- result = process_decorator_instance .find_python_files (tmpdir )
19- assert result == [str (tmpdir . join ( "pythonfile.py" ) )]
16+ def test_find_python_files (process_decorator_instance : DecoratorProcessor , tmp_path ):
17+ ( tmp_path / "pythonfile.py" ).write_text ("content" )
18+ result = process_decorator_instance .find_python_files (tmp_path )
19+ assert result == [str (tmp_path / "pythonfile.py" )]
2020
2121
22- def test_find_python_files_empty_dir (process_decorator_instance : DecoratorProcessor , tmpdir ):
23- result = process_decorator_instance .find_python_files (tmpdir )
22+ def test_find_python_files_empty_dir (process_decorator_instance : DecoratorProcessor , tmp_path ):
23+ result = process_decorator_instance .find_python_files (tmp_path )
2424 assert result == []
2525
2626
27- def test_find_python_files_nested (process_decorator_instance : DecoratorProcessor , tmpdir ):
28- sub = tmpdir .mkdir ("sub" )
29- sub .join ("nested.py" ).write ("content" )
30- result = process_decorator_instance .find_python_files (tmpdir )
31- assert str (sub .join ("nested.py" )) in result
27+ def test_find_python_files_nested (process_decorator_instance : DecoratorProcessor , tmp_path ):
28+ sub = tmp_path / "sub"
29+ sub .mkdir ()
30+ (sub / "nested.py" ).write_text ("content" )
31+ result = process_decorator_instance .find_python_files (tmp_path )
32+ assert str (sub / "nested.py" ) in result
3233
3334
34- def test_find_python_files_ignores_non_py (process_decorator_instance : DecoratorProcessor , tmpdir ):
35- tmpdir . join ( "readme.txt" ).write ("content" )
36- result = process_decorator_instance .find_python_files (tmpdir )
35+ def test_find_python_files_ignores_non_py (process_decorator_instance : DecoratorProcessor , tmp_path ):
36+ ( tmp_path / "readme.txt" ).write_text ("content" )
37+ result = process_decorator_instance .find_python_files (tmp_path )
3738 assert result == []
3839
3940
@@ -42,39 +43,39 @@ def test_find_python_files_ignores_non_py(process_decorator_instance: DecoratorP
4243# ---------------------------------------------------------------------------
4344
4445
45- def test_get_functions_and_classes (process_decorator_instance : DecoratorProcessor , tmpdir ):
46- file_path = str ( tmpdir . join ( "test_file.py" ))
47- tmpdir . join ( "test_file.py" ). write ('@SVCs("SVC_001")\n class Test:\n pass' )
46+ def test_get_functions_and_classes (process_decorator_instance : DecoratorProcessor , tmp_path ):
47+ file_path = tmp_path / "test_file.py"
48+ file_path . write_text ('@SVCs("SVC_001")\n class Test:\n pass' )
4849 process_decorator_instance .get_functions_and_classes (file_path , ["SVCs" ])
4950 assert process_decorator_instance .req_svc_results [0 ]["name" ] == "Test"
5051 assert process_decorator_instance .req_svc_results [0 ]["decorators" ][0 ]["args" ][0 ] == "SVC_001"
5152 assert process_decorator_instance .req_svc_results [0 ]["decorators" ][0 ]["name" ] == "SVCs"
5253 assert process_decorator_instance .req_svc_results [0 ]["elementKind" ] == "CLASS"
5354
5455
55- def test_get_functions_and_classes_function_def (process_decorator_instance : DecoratorProcessor , tmpdir ):
56- file_path = str ( tmpdir . join ( "f.py" ))
57- tmpdir . join ( "f.py" ). write ('@Requirements("REQ_001")\n def my_func():\n pass' )
56+ def test_get_functions_and_classes_function_def (process_decorator_instance : DecoratorProcessor , tmp_path ):
57+ file_path = tmp_path / "f.py"
58+ file_path . write_text ('@Requirements("REQ_001")\n def my_func():\n pass' )
5859 process_decorator_instance .get_functions_and_classes (file_path , ["Requirements" ])
5960 assert len (process_decorator_instance .req_svc_results ) == 1
6061 result = process_decorator_instance .req_svc_results [0 ]
6162 assert result ["name" ] == "my_func"
6263 assert result ["elementKind" ] == "FUNCTION"
6364
6465
65- def test_get_functions_and_classes_async_function_def (process_decorator_instance : DecoratorProcessor , tmpdir ):
66- file_path = str ( tmpdir . join ( "af.py" ))
67- tmpdir . join ( "af.py" ). write ('@Requirements("REQ_001")\n async def my_async():\n pass' )
66+ def test_get_functions_and_classes_async_function_def (process_decorator_instance : DecoratorProcessor , tmp_path ):
67+ file_path = tmp_path / "af.py"
68+ file_path . write_text ('@Requirements("REQ_001")\n async def my_async():\n pass' )
6869 process_decorator_instance .get_functions_and_classes (file_path , ["Requirements" ])
6970 assert len (process_decorator_instance .req_svc_results ) == 1
7071 result = process_decorator_instance .req_svc_results [0 ]
7172 assert result ["name" ] == "my_async"
7273 assert result ["elementKind" ] == "ASYNCFUNCTION"
7374
7475
75- def test_get_functions_and_classes_multiple_args (process_decorator_instance : DecoratorProcessor , tmpdir ):
76- file_path = str ( tmpdir . join ( "m.py" ))
77- tmpdir . join ( "m.py" ). write ('@Requirements("A", "B")\n def func():\n pass' )
76+ def test_get_functions_and_classes_multiple_args (process_decorator_instance : DecoratorProcessor , tmp_path ):
77+ file_path = tmp_path / "m.py"
78+ file_path . write_text ('@Requirements("A", "B")\n def func():\n pass' )
7879 process_decorator_instance .get_functions_and_classes (file_path , ["Requirements" ])
7980 args = process_decorator_instance .req_svc_results [0 ]["decorators" ][0 ]["args" ]
8081 assert args == ["A" , "B" ]
@@ -89,28 +90,28 @@ def test_get_functions_and_classes_multiple_args(process_decorator_instance: Dec
8990 ],
9091)
9192def test_get_functions_and_classes_element_kind (
92- process_decorator_instance : DecoratorProcessor , tmpdir , code , expected_kind
93+ process_decorator_instance : DecoratorProcessor , tmp_path , code , expected_kind
9394):
9495 """Fix 4: elementKind must be derived from __class__.__name__, not CPython repr."""
95- f = tmpdir . join ( "f.py" )
96- f .write (code )
97- process_decorator_instance .get_functions_and_classes (str ( f ) , ["Requirements" ])
96+ f = tmp_path / "f.py"
97+ f .write_text (code )
98+ process_decorator_instance .get_functions_and_classes (f , ["Requirements" ])
9899 assert process_decorator_instance .req_svc_results [0 ]["elementKind" ] == expected_kind
99100
100101
101- def test_get_functions_and_classes_no_match (process_decorator_instance : DecoratorProcessor , tmpdir ):
102- file_path = str ( tmpdir . join ( "n.py" ))
103- tmpdir . join ( "n.py" ). write ('@OtherDecorator("X")\n def func():\n pass' )
102+ def test_get_functions_and_classes_no_match (process_decorator_instance : DecoratorProcessor , tmp_path ):
103+ file_path = tmp_path / "n.py"
104+ file_path . write_text ('@OtherDecorator("X")\n def func():\n pass' )
104105 process_decorator_instance .get_functions_and_classes (file_path , ["Requirements" ])
105106 assert process_decorator_instance .req_svc_results == []
106107
107108
108109def test_get_functions_and_classes_multiple_decorators_on_func (
109- process_decorator_instance : DecoratorProcessor , tmpdir
110+ process_decorator_instance : DecoratorProcessor , tmp_path
110111):
111- file_path = str ( tmpdir . join ( "md.py" ))
112+ file_path = tmp_path / "md.py"
112113 code = '@Requirements("REQ_001")\n @SVCs("SVC_001")\n def func():\n pass'
113- tmpdir . join ( "md.py" ). write (code )
114+ file_path . write_text (code )
114115 process_decorator_instance .get_functions_and_classes (file_path , ["Requirements" , "SVCs" ])
115116 assert len (process_decorator_instance .req_svc_results ) == 1
116117 names = [d ["name" ] for d in process_decorator_instance .req_svc_results [0 ]["decorators" ]]
@@ -140,7 +141,7 @@ def test_map_type_unknown_type(process_decorator_instance: DecoratorProcessor):
140141# ---------------------------------------------------------------------------
141142
142143
143- def test_format_results_implementations (process_decorator_instance : DecoratorProcessor , tmpdir ):
144+ def test_format_results_implementations (process_decorator_instance : DecoratorProcessor ):
144145 results = [
145146 {
146147 "fullyQualifiedName" : "my.module.py" ,
@@ -252,22 +253,20 @@ def test_process_decorated_data_produces_yaml(process_decorator_instance: Decora
252253 src_file .parent .mkdir ()
253254 src_file .write_text ('@Requirements("REQ_001")\n def my_func():\n pass\n ' )
254255
255- output_file = str ( tmp_path / "out" / "annotations.yml" )
256+ output_file = tmp_path / "out" / "annotations.yml"
256257 process_decorator_instance .process_decorated_data (
257258 path_to_python_files = [str (src_file .parent )], output_file = output_file
258259 )
259260
260- import os
261-
262- assert os .path .exists (output_file )
261+ assert output_file .exists ()
263262
264263
265264def test_process_decorated_data_correct_structure (process_decorator_instance : DecoratorProcessor , tmp_path ):
266265 src_file = tmp_path / "src" / "app.py"
267266 src_file .parent .mkdir ()
268267 src_file .write_text ('@Requirements("REQ_001")\n def my_func():\n pass\n ' )
269268
270- output_file = str ( tmp_path / "out" / "annotations.yml" )
269+ output_file = tmp_path / "out" / "annotations.yml"
271270 process_decorator_instance .process_decorated_data (
272271 path_to_python_files = [str (src_file .parent )], output_file = output_file
273272 )
@@ -285,7 +284,7 @@ def test_process_decorated_data_no_state_accumulation(process_decorator_instance
285284 src_file .parent .mkdir ()
286285 src_file .write_text ('@Requirements("REQ_001")\n def my_func():\n pass\n ' )
287286
288- output_file = str ( tmp_path / "out" / "annotations.yml" )
287+ output_file = tmp_path / "out" / "annotations.yml"
289288
290289 # Call twice
291290 process_decorator_instance .process_decorated_data (
0 commit comments