Skip to content

Commit 4008d28

Browse files
committed
tests: move util functions into separate file
1 parent 878753a commit 4008d28

File tree

5 files changed

+75
-65
lines changed

5 files changed

+75
-65
lines changed

tests/conftest.py

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -68,68 +68,6 @@ def isolated_python_env(tmp_path):
6868
}
6969

7070

71-
def run_in_venv(
72-
venv_info: Dict, cmd: str, check: bool = True, **kwargs
73-
) -> subprocess.CompletedProcess:
74-
"""
75-
Run a command in an isolated virtual environment.
76-
77-
Args:
78-
venv_info: Dictionary from isolated_python_env fixture
79-
cmd: Command to run
80-
check: Whether to raise on non-zero exit code
81-
**kwargs: Additional arguments to subprocess.run
82-
83-
Returns:
84-
CompletedProcess instance with stdout, stderr, and returncode
85-
"""
86-
env = os.environ.copy()
87-
env.update(venv_info["env"])
88-
89-
try:
90-
return subprocess.run(
91-
cmd, shell=True, env=env, capture_output=True, text=True, check=check, **kwargs
92-
)
93-
except subprocess.CalledProcessError as e:
94-
print("Command failed with CalledProcessError.")
95-
print("Exit code:", e.returncode)
96-
print("Command:", e.cmd)
97-
print("Stdout:", e.stdout)
98-
print("Stderr:", e.stderr)
99-
raise
100-
101-
102-
def run_command(
103-
cmd: str, check: bool = True, capture_stderr: bool = True
104-
) -> subprocess.CompletedProcess:
105-
"""
106-
Execute shell commands and return output.
107-
108-
This function is kept for backward compatibility with tests using isolated_solc_data.
109-
For tests using isolated_python_env, use run_in_venv instead.
110-
111-
Args:
112-
cmd: Command to run
113-
check: Whether to raise on non-zero exit code
114-
capture_stderr: Whether to capture stderr
115-
116-
Returns:
117-
CompletedProcess instance with stdout, stderr, and returncode
118-
"""
119-
stderr_setting = subprocess.STDOUT if capture_stderr else subprocess.PIPE
120-
121-
result = subprocess.run(
122-
cmd,
123-
shell=True,
124-
capture_output=False,
125-
stdout=subprocess.PIPE,
126-
stderr=stderr_setting,
127-
text=True,
128-
check=check,
129-
)
130-
return result
131-
132-
13371
@pytest.fixture(scope="session")
13472
def test_contracts_dir() -> Path:
13573
"""Path to test Solidity contracts."""

tests/test_compiler_versions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
This module tests compilation with different Solidity versions.
55
"""
66

7-
from .conftest import run_command
7+
from .utils import run_command
88

99

1010
class TestCompilerVersions:

tests/test_platform_specific.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import pytest
1111

12-
from .conftest import run_command
12+
from .utils import run_command
1313

1414
# Platform configuration matrix
1515
PLATFORM_CONFIGS = {

tests/test_upgrade.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from pathlib import Path
99

10-
from .conftest import run_in_venv
10+
from .utils import run_in_venv
1111

1212

1313
class TestUpgrade: # pylint: disable=too-few-public-methods

tests/utils.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
"""
2+
Utility functions for solc-select tests.
3+
4+
This module contains helper functions that are not pytest fixtures
5+
but are used across multiple test files.
6+
"""
7+
8+
import os
9+
import subprocess
10+
from typing import Dict
11+
12+
13+
def run_in_venv(
14+
venv_info: Dict, cmd: str, check: bool = True, **kwargs
15+
) -> subprocess.CompletedProcess:
16+
"""
17+
Run a command in an isolated virtual environment.
18+
19+
Args:
20+
venv_info: Dictionary from isolated_python_env fixture
21+
cmd: Command to run
22+
check: Whether to raise on non-zero exit code
23+
**kwargs: Additional arguments to subprocess.run
24+
25+
Returns:
26+
CompletedProcess instance with stdout, stderr, and returncode
27+
"""
28+
env = os.environ.copy()
29+
env.update(venv_info["env"])
30+
31+
try:
32+
return subprocess.run(
33+
cmd, shell=True, env=env, capture_output=True, text=True, check=check, **kwargs
34+
)
35+
except subprocess.CalledProcessError as e:
36+
print("Command failed with CalledProcessError.")
37+
print("Exit code:", e.returncode)
38+
print("Command:", e.cmd)
39+
print("Stdout:", e.stdout)
40+
print("Stderr:", e.stderr)
41+
raise
42+
43+
44+
def run_command(
45+
cmd: str, check: bool = True, capture_stderr: bool = True
46+
) -> subprocess.CompletedProcess:
47+
"""
48+
Execute shell commands and return output.
49+
50+
This function is kept for backward compatibility with tests using isolated_solc_data.
51+
For tests using isolated_python_env, use run_in_venv instead.
52+
53+
Args:
54+
cmd: Command to run
55+
check: Whether to raise on non-zero exit code
56+
capture_stderr: Whether to capture stderr
57+
58+
Returns:
59+
CompletedProcess instance with stdout, stderr, and returncode
60+
"""
61+
stderr_setting = subprocess.STDOUT if capture_stderr else subprocess.PIPE
62+
63+
result = subprocess.run(
64+
cmd,
65+
shell=True,
66+
capture_output=False,
67+
stdout=subprocess.PIPE,
68+
stderr=stderr_setting,
69+
text=True,
70+
check=check,
71+
)
72+
return result

0 commit comments

Comments
 (0)