11import os
22import pytest
3+ import shutil
4+ from tempfile import mkdtemp
5+
36from ci_tools .snippet_update .python_snippet_updater import (
47 get_snippet ,
58 update_snippet ,
69 check_snippets ,
710 check_not_up_to_date ,
811)
912
13+ scenario = os .path .join (os .path .dirname (__file__ ), "integration" , "scenarios" , "snippet-updater" )
14+
15+ def create_temp_directory_from_template (input_directory : str ) -> str :
16+ """
17+ Create a temporary directory from a template directory.
18+ Args:
19+ input_directory (str): The path to the input directory to copy.
20+ Returns:
21+ str: The path to the newly created temporary directory.
22+ """
23+ temp_dir = mkdtemp ()
24+ shutil .copytree (input_directory , temp_dir , dirs_exist_ok = True )
25+ return temp_dir
26+
1027
1128def test_get_snippet ():
12- folder = os . path . dirname ( os . path . abspath ( __file__ ))
29+ folder = scenario
1330 file = os .path .join (folder , "example_async.py" )
1431 get_snippet (file )
1532 snippets = check_snippets ().keys ()
@@ -19,15 +36,15 @@ def test_get_snippet():
1936
2037
2138def test_update_snippet ():
22- folder = os . path . dirname ( os . path . abspath ( __file__ ) )
39+ folder = create_temp_directory_from_template ( scenario )
2340 file = os .path .join (folder , "example_async.py" )
2441 get_snippet (file )
2542 file_1 = os .path .join (folder , "README.md" )
2643 update_snippet (file_1 )
2744
2845
2946def test_missing_snippet ():
30- folder = os . path . dirname ( os . path . abspath ( __file__ ) )
47+ folder = create_temp_directory_from_template ( scenario )
3148 file = os .path .join (folder , "example_async.py" )
3249 get_snippet (file )
3350 file_1 = os .path .join (folder , "README_missing_snippet.md" )
@@ -36,7 +53,7 @@ def test_missing_snippet():
3653
3754
3855def test_out_of_sync ():
39- folder = os . path . dirname ( os . path . abspath ( __file__ ) )
56+ folder = create_temp_directory_from_template ( scenario )
4057 file = os .path .join (folder , "example_async.py" )
4158 get_snippet (file )
4259 file_1 = os .path .join (folder , "README_out_of_sync.md" )
0 commit comments