1
1
import os
2
2
import pytest
3
+ import shutil
4
+ from tempfile import mkdtemp
5
+
3
6
from ci_tools .snippet_update .python_snippet_updater import (
4
7
get_snippet ,
5
8
update_snippet ,
6
9
check_snippets ,
7
10
check_not_up_to_date ,
8
11
)
9
12
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
+
10
27
11
28
def test_get_snippet ():
12
- folder = os . path . dirname ( os . path . abspath ( __file__ ))
29
+ folder = scenario
13
30
file = os .path .join (folder , "example_async.py" )
14
31
get_snippet (file )
15
32
snippets = check_snippets ().keys ()
@@ -19,15 +36,15 @@ def test_get_snippet():
19
36
20
37
21
38
def test_update_snippet ():
22
- folder = os . path . dirname ( os . path . abspath ( __file__ ) )
39
+ folder = create_temp_directory_from_template ( scenario )
23
40
file = os .path .join (folder , "example_async.py" )
24
41
get_snippet (file )
25
42
file_1 = os .path .join (folder , "README.md" )
26
43
update_snippet (file_1 )
27
44
28
45
29
46
def test_missing_snippet ():
30
- folder = os . path . dirname ( os . path . abspath ( __file__ ) )
47
+ folder = create_temp_directory_from_template ( scenario )
31
48
file = os .path .join (folder , "example_async.py" )
32
49
get_snippet (file )
33
50
file_1 = os .path .join (folder , "README_missing_snippet.md" )
@@ -36,7 +53,7 @@ def test_missing_snippet():
36
53
37
54
38
55
def test_out_of_sync ():
39
- folder = os . path . dirname ( os . path . abspath ( __file__ ) )
56
+ folder = create_temp_directory_from_template ( scenario )
40
57
file = os .path .join (folder , "example_async.py" )
41
58
get_snippet (file )
42
59
file_1 = os .path .join (folder , "README_out_of_sync.md" )
0 commit comments