Skip to content

Commit 4f40692

Browse files
committed
fix(windows-test): support assign test_exe_testcases platform
* for skip specific testing at windows
1 parent a882fe6 commit 4f40692

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
platform:
2+
- linux
3+
- darwin
14
expected:
25
return_code: 0
36
stdout: "0\n1\n4\n9\n16\n"

tests/test_exe_testcases.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
import os
15+
import platform
1516
import shutil
1617
import subprocess
1718
from dataclasses import dataclass
@@ -36,6 +37,12 @@ class ExpectedConfig:
3637
is_ignore_stdout: bool
3738

3839

40+
@dataclass(frozen=True)
41+
class Config:
42+
platform: [str] # linux, darwin, windows, empty as default all
43+
expected: ExpectedConfig
44+
45+
3946
def _is_valid_testcase_folder(sub_test_case_dir):
4047
module_path = sub_test_case_dir
4148
module_name = basename(module_path)
@@ -61,16 +68,20 @@ def _discover_exe_testcases_folder() -> list:
6168
return sorted(test_cases)
6269

6370

64-
def _read_expected_yaml(expected_yaml: str) -> ExpectedConfig:
71+
def _read_expected_yaml(expected_yaml: str) -> Config:
6572
with open(join(expected_yaml), 'r') as f:
6673
data = yaml.safe_load(f)
6774

6875
expected = data['expected']
69-
config = ExpectedConfig(
76+
expected_config = ExpectedConfig(
7077
return_code=expected.get('return_code', 0),
7178
stdout=expected.get('stdout', '').replace('\n', os.linesep),
7279
is_ignore_stdout=expected.get('is_ignore_stdout', False),
7380
)
81+
config = Config(
82+
platform=data.get('platform', ['all']),
83+
expected=expected_config,
84+
)
7485
return config
7586

7687

@@ -93,6 +104,14 @@ def test_exe__testcases(venv_cli, venv_exe, tmpdir, sub_test_case_folder: str):
93104
shutil.copytree(sub_test_case_folder, dest_dir)
94105
venv_cli.pyconcrete_cli('compile', f'--source={dest_dir}', '--pye', '--remove-py', '--remove-pyc')
95106

107+
config = _read_expected_yaml(join(dest_dir, EXPECTED_YAML))
108+
if 'all' not in config.platform:
109+
_platform = platform.system().lower()
110+
if _platform not in config.platform:
111+
print(f'* platform not match, skip testing. {_platform} not in expected ({config.platform})')
112+
return
113+
expected = config.expected
114+
96115
# execution
97116
main_pye = join(dest_dir, MAIN_PYE)
98117
p = subprocess.Popen(
@@ -106,8 +125,6 @@ def test_exe__testcases(venv_cli, venv_exe, tmpdir, sub_test_case_folder: str):
106125
return_code = p.returncode
107126

108127
# verification
109-
expected = _read_expected_yaml(join(dest_dir, EXPECTED_YAML))
110-
111128
assert type(expected.return_code) is int, f"type of `return_code` ({type(expected.return_code)}) is not int"
112129
assert expected.return_code == return_code
113130

0 commit comments

Comments
 (0)