5
5
import os
6
6
import subprocess
7
7
import sys
8
+ import tempfile
8
9
import unittest
9
10
10
11
base_dir = os .path .join (os .path .dirname (__file__ ), ".." , ".." )
@@ -16,34 +17,33 @@ class TestExternal(unittest.TestCase):
16
17
@unittest .skipIf (sys .platform .startswith ("win" ), "rt tests don't work on windows" )
17
18
def test_c_unit_test (self ) -> None :
18
19
"""Run C unit tests in a subprocess."""
19
- # Build Google Test, the C++ framework we use for testing C code.
20
- # The source code for Google Test is copied to this repository.
21
20
cppflags : list [str ] = []
22
21
env = os .environ .copy ()
23
22
if sys .platform == "darwin" :
24
23
cppflags += ["-mmacosx-version-min=10.10" , "-stdlib=libc++" ]
25
24
env ["CPPFLAGS" ] = " " .join (cppflags )
26
- subprocess .check_call (
27
- ["make" , "libgtest.a" ],
28
- env = env ,
29
- cwd = os .path .join (base_dir , "mypyc" , "external" , "googletest" , "make" ),
30
- )
31
25
# Build Python wrapper for C unit tests.
32
- env = os .environ .copy ()
33
- env ["CPPFLAGS" ] = " " .join (cppflags )
34
- status = subprocess .check_call (
35
- [sys .executable , "setup.py" , "build_ext" , "--inplace" ],
36
- env = env ,
37
- cwd = os .path .join (base_dir , "mypyc" , "lib-rt" ),
38
- )
39
- # Run C unit tests.
40
- env = os .environ .copy ()
41
- if "GTEST_COLOR" not in os .environ :
42
- env ["GTEST_COLOR" ] = "yes" # Use fancy colors
43
- status = subprocess .call (
44
- [sys .executable , "-c" , "import sys, test_capi; sys.exit(test_capi.run_tests())" ],
45
- env = env ,
46
- cwd = os .path .join (base_dir , "mypyc" , "lib-rt" ),
47
- )
48
- if status != 0 :
49
- raise AssertionError ("make test: C unit test failure" )
26
+
27
+ with tempfile .TemporaryDirectory () as tmpdir :
28
+ status = subprocess .check_call (
29
+ [
30
+ sys .executable ,
31
+ "setup.py" ,
32
+ "build_ext" ,
33
+ f"--build-lib={ tmpdir } " ,
34
+ f"--build-temp={ tmpdir } " ,
35
+ ],
36
+ env = env ,
37
+ cwd = os .path .join (base_dir , "mypyc" , "lib-rt" ),
38
+ )
39
+ # Run C unit tests.
40
+ env = os .environ .copy ()
41
+ if "GTEST_COLOR" not in os .environ :
42
+ env ["GTEST_COLOR" ] = "yes" # Use fancy colors
43
+ status = subprocess .call (
44
+ [sys .executable , "-c" , "import sys, test_capi; sys.exit(test_capi.run_tests())" ],
45
+ env = env ,
46
+ cwd = tmpdir ,
47
+ )
48
+ if status != 0 :
49
+ raise AssertionError ("make test: C unit test failure" )
0 commit comments