@@ -58,26 +58,26 @@ def fake_func():
58
58
)
59
59
def test_apcustom_choices_callable_count (kwargs , is_valid ):
60
60
parser = Cmd2ArgumentParser ()
61
- try :
61
+ if is_valid :
62
62
parser .add_argument ('name' , ** kwargs )
63
- assert is_valid
64
- except ValueError as ex :
65
- assert not is_valid
66
- assert 'Only one of the following parameters' in str ( ex )
63
+ else :
64
+ expected_err = 'Only one of the following parameters'
65
+ with pytest . raises ( ValueError , match = expected_err ):
66
+ parser . add_argument ( 'name' , ** kwargs )
67
67
68
68
69
69
@pytest .mark .parametrize ('kwargs' , [({'choices_provider' : fake_func }), ({'completer' : fake_func })])
70
70
def test_apcustom_no_choices_callables_alongside_choices (kwargs ):
71
+ parser = Cmd2ArgumentParser ()
71
72
with pytest .raises (TypeError ) as excinfo :
72
- parser = Cmd2ArgumentParser ()
73
73
parser .add_argument ('name' , choices = ['my' , 'choices' , 'list' ], ** kwargs )
74
74
assert 'None of the following parameters can be used alongside a choices parameter' in str (excinfo .value )
75
75
76
76
77
77
@pytest .mark .parametrize ('kwargs' , [({'choices_provider' : fake_func }), ({'completer' : fake_func })])
78
78
def test_apcustom_no_choices_callables_when_nargs_is_0 (kwargs ):
79
+ parser = Cmd2ArgumentParser ()
79
80
with pytest .raises (TypeError ) as excinfo :
80
- parser = Cmd2ArgumentParser ()
81
81
parser .add_argument ('--name' , action = 'store_true' , ** kwargs )
82
82
assert 'None of the following parameters can be used on an action that takes no arguments' in str (excinfo .value )
83
83
@@ -126,24 +126,24 @@ def test_apcustom_nargs_range_validation(cust_app):
126
126
],
127
127
)
128
128
def test_apcustom_narg_invalid_tuples (nargs_tuple ):
129
- with pytest .raises (ValueError ) as excinfo :
130
- parser = Cmd2ArgumentParser ()
129
+ parser = Cmd2ArgumentParser ()
130
+ expected_err = 'Ranged values for nargs must be a tuple of 1 or 2 integers'
131
+ with pytest .raises (ValueError , match = expected_err ):
131
132
parser .add_argument ('invalid_tuple' , nargs = nargs_tuple )
132
- assert 'Ranged values for nargs must be a tuple of 1 or 2 integers' in str (excinfo .value )
133
133
134
134
135
135
def test_apcustom_narg_tuple_order ():
136
- with pytest .raises (ValueError ) as excinfo :
137
- parser = Cmd2ArgumentParser ()
136
+ parser = Cmd2ArgumentParser ()
137
+ expected_err = 'Invalid nargs range. The first value must be less than the second'
138
+ with pytest .raises (ValueError , match = expected_err ):
138
139
parser .add_argument ('invalid_tuple' , nargs = (2 , 1 ))
139
- assert 'Invalid nargs range. The first value must be less than the second' in str (excinfo .value )
140
140
141
141
142
142
def test_apcustom_narg_tuple_negative ():
143
- with pytest .raises (ValueError ) as excinfo :
144
- parser = Cmd2ArgumentParser ()
143
+ parser = Cmd2ArgumentParser ()
144
+ expected_err = 'Negative numbers are invalid for nargs range'
145
+ with pytest .raises (ValueError , match = expected_err ):
145
146
parser .add_argument ('invalid_tuple' , nargs = (- 1 , 1 ))
146
- assert 'Negative numbers are invalid for nargs range' in str (excinfo .value )
147
147
148
148
149
149
def test_apcustom_narg_tuple_zero_base ():
0 commit comments