1717to local relative paths
1818"""
1919import os
20+ import re
2021import shutil
2122import unittest
2223from typing import Dict
2324from common .base import TestBase
24- from src .codechecker_script import fix_bazel_paths
25+ from src .codechecker_script import BAZEL_PATHS
2526
2627PATH_RESOLUTION : Dict [str , str ] = {
2728 # {Remote execution absolute path}: {project relative path}
3334}
3435
3536
36- class TestTemplate (TestBase ):
37+ class TestPathResolve (TestBase ):
3738 """Test regex resolution of remote execution paths"""
3839
3940 # Set working directory
@@ -46,38 +47,18 @@ class TestTemplate(TestBase):
4647 )
4748 dir = os .path .dirname (os .path .abspath (__file__ )) + "/tmp"
4849
49- def setUp (self ):
50- """Write absolute paths to action directory"""
51- if os .path .exists ("tmp" ):
52- try :
53- shutil .rmtree ("tmp" )
54- except Exception as e :
55- self .fail (f"Failed to clean up the existing tmp directory { e } " )
56- os .mkdir ("tmp" )
57- with open ("tmp/test.txt" , "w" ) as f :
58- for abs , _ in PATH_RESOLUTION .items ():
59- f .write (abs + "\n " )
60- super ().setUp ()
61-
62- def tearDown (self ):
63- """Remove test files"""
64- if os .path .exists ("tmp" ):
65- try :
66- shutil .rmtree ("tmp" )
67- except :
68- pass
69- return super ().tearDown ()
70-
7150 def test_remote_worker_path_resolution (self ):
7251 """
7352 Test: Resolve absolute path of remote worker
7453 to a relative path of the original project
7554 """
76- fix_bazel_paths (self .__test_path__ + "/tmp" ) # type: ignore
77- with open ("tmp/test.txt" , "r" ) as f :
78- for _ , res in PATH_RESOLUTION .items ():
79- # FIXME: change to assertEqual
80- self .assertNotEqual (f .readline ().strip (), res )
55+ test_on : Dict [str , str ] = PATH_RESOLUTION .copy ()
56+ for before , res in test_on .items ():
57+ after : str = before [:]
58+ for pattern , replace in BAZEL_PATHS .items ():
59+ after = re .sub (pattern , replace , after )
60+ # FIXME: change to assertEqual
61+ self .assertNotEqual (after , res )
8162
8263
8364if __name__ == "__main__" :
0 commit comments