@@ -109,6 +109,14 @@ def test_extend_match(self):
109
109
pattern = r"option_(\d+)" ,
110
110
dest = "passes" ,
111
111
)
112
+ parser .add_argument (
113
+ "--default-override" ,
114
+ action = _ExtendMatchAction ,
115
+ pattern = r"option_(\d+)" ,
116
+ default = ["0" ],
117
+ dest = "override" ,
118
+ override = True ,
119
+ )
112
120
113
121
args , _ = parser .parse_known_args (
114
122
["--foo=option_1,option_2" ],
@@ -125,22 +133,26 @@ def test_extend_match(self):
125
133
with self .assertRaises (TypeError ):
126
134
args , _ = parser .parse_known_args (["--baz=1" ], namespace )
127
135
128
- # Check that the default pass defined by --qux always exists.
136
+ # Check that the default values defined by flags always exists.
129
137
# Note that the caller must initialize the default.
138
+ namespace .override = ["0" ]
130
139
namespace ._passes = {"--qux" : ["0" ]}
131
140
args , _ = parser .parse_known_args (
132
141
[],
133
142
namespace ,
134
143
)
144
+ self .assertEqual (args .override , ["0" ])
135
145
self .assertEqual (args ._passes , {"--qux" : ["0" ]})
136
146
137
147
# Check that the default pass is overridden by use of --qux.
138
148
# Note that the caller must initialize the default.
149
+ namespace .override = ["0" ]
139
150
namespace ._passes = {"--qux" : ["0" ]}
140
151
args , _ = parser .parse_known_args (
141
- ["--qux=option_1,option_2" ],
152
+ ["--qux=option_1,option_2" , "--default-override=option_1" ],
142
153
namespace ,
143
154
)
155
+ self .assertEqual (args .override , ["1" ])
144
156
self .assertEqual (args ._passes , {"--qux" : ["1" , "2" ]})
145
157
146
158
namespace ._passes = {}
@@ -150,8 +162,6 @@ def test_extend_match(self):
150
162
)
151
163
self .assertEqual (args ._passes , {"--one" : ["1" , "2" ]})
152
164
153
- namespace ._passes = {}
154
-
155
165
156
166
if __name__ == "__main__" :
157
167
unittest .main ()
0 commit comments