Skip to content

Commit 137a148

Browse files
committed
添加 argparse 测试用例
1 parent c165620 commit 137a148

File tree

1 file changed

+52
-14
lines changed

1 file changed

+52
-14
lines changed

case/argparse/test_script.py

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,47 @@ def test_cmd_1(execute):
1313
logging.info('the test_cmd_1 ended.')
1414

1515

16+
IS_DEBUG_ONLY = False
17+
# IS_SKIP = True
18+
19+
20+
@pytest.fixture(scope='session', autouse=True)
21+
def generic_cmd_env(_temp_dir, _temp_file):
22+
''' generic cmd env '''
23+
pass
24+
25+
1626
# @pytest.fixture(scope='session', params=['test_argparse_0.py'])
17-
@pytest.fixture(scope='session', params=['test_argparse_1.py'])
18-
# @pytest.fixture(scope='session', params=['test_argparse_0.py', 'test_argparse_1.py'])
19-
def generic_cmd_prefix(_temp_dir, _temp_file, request):
27+
# @pytest.fixture(scope='session', params=['test_argparse_1.py'])
28+
# @pytest.fixture(scope='session', params=['test_argparse_2.py'])
29+
@pytest.fixture(scope='session',
30+
params=[
31+
pytest.param('test_argparse_0.py', marks=pytest.mark.skip),
32+
pytest.param('test_argparse_1.py', marks=pytest.mark.skip), 'test_argparse_2.py'
33+
])
34+
# @pytest.mark.parametrize('script_name', ['test_argparse_0.py', 'test_argparse_1.py', 'test_argparse_2.py'])
35+
def generic_cmd_prefix(request):
2036
''' the generic command prefix '''
2137
dest_script_name = os.path.join(os.path.dirname(__file__), request.param)
2238
logging.debug('the generic_cmd_prefix dest_script_name is {}'.format(dest_script_name))
2339
return [sys.executable, dest_script_name]
2440

2541

26-
@pytest.fixture(params=[['1'], ['-h']])
42+
# the test_argparse_2.py script only
43+
PARAMS_ARGPARSE_2 = [['-h'], ['./a', './b'], ['./a', './b', '-vs'], ['./a', './b', '-v1', '0'],
44+
['./a', './b', '-v1', '1'], ['./a', './b', '-v1', '2'], ['./a', './b', '-v2'],
45+
['./a', './b', '-v2', '-v2'], ['./a', './b', '-v'], ['./a', './b', '-q'],
46+
['./a', './b', '-vs', '-v1', '0'], ['./a', './b', '-vs', '-v1', '1'],
47+
['./a', './b', '-vs', '-v1', '2'], ['./a', './b', '-vs', '-v1', '0', '-v2'],
48+
['./a', './b', '-vs', '-v1', '1', '-v2'], ['./a', './b', '-vs', '-v1', '2', '-v2'],
49+
['./a', './b', '-vs', '-v1', '0', '-v2', '-v2'], ['./a', './b', '-vs', '-v1', '1', '-v2', '-v2'],
50+
['./a', './b', '-vs', '-v1', '2', '-v2', '-v2'], ['./a', './b', '-vs', '-v1', '0', '-v2', '-v'],
51+
['./a', './b', '-vs', '-v1', '1', '-v2', '-v'], ['./a', './b', '-vs', '-v1', '2', '-v2', '-v'],
52+
['./a', './b', '-vs', '-v1', '0', '-v2', '-q'], ['./a', './b', '-vs', '-v1', '1', '-v2', '-q'],
53+
['./a', './b', '-vs', '-v1', '2', '-v2', '-q']]
54+
55+
56+
@pytest.fixture(params=PARAMS_ARGPARSE_2)
2757
def generic_cmd_args(generic_cmd_prefix, request):
2858
''' the generic command args '''
2959
dest_script_args = generic_cmd_prefix + request.param
@@ -33,19 +63,27 @@ def generic_cmd_args(generic_cmd_prefix, request):
3363

3464
@pytest.fixture()
3565
def execute(generic_cmd_args):
66+
''' the execute '''
3667
try:
3768
args = generic_cmd_args
38-
logging.warning('the parameters required for current execution, the command script: [\"{}\"]'.format(
39-
' '.join(args)))
40-
std_output = subprocess.check_output(args)
41-
if type(std_output) == bytes:
42-
# logging.warning(str(std_output, encoding='utf-8'))
43-
logging.info('the capture std output from subprocess:\n {}'.format(str(std_output, encoding='utf-8')))
69+
if args:
70+
logging.warning('the parameters required for current execution, the command script: [\"{}\"]'.format(
71+
' '.join(args)))
72+
if IS_DEBUG_ONLY:
73+
pass
74+
else:
75+
std_output = subprocess.check_output(args)
76+
if type(std_output) == bytes:
77+
# logging.warning(str(std_output, encoding='utf-8'))
78+
logging.info('the capture std output from subprocess:\n {}'.format(str(std_output,
79+
encoding='utf-8')))
80+
else:
81+
logging.warning(std_output)
82+
retcode = subprocess.check_call(args)
83+
if retcode == 0:
84+
logging.info('the script verify passed.')
4485
else:
45-
logging.warning(std_output)
46-
retcode = subprocess.check_call(args)
47-
if retcode == 0:
48-
logging.info('the script verify passed.')
86+
logging.warning('the error script command line that is skipped.')
4987
finally:
5088
logging.debug('the execute ended')
5189

0 commit comments

Comments
 (0)