@@ -152,7 +152,9 @@ def run_espsecure(self, args):
152
152
print (e .output )
153
153
raise e
154
154
155
- def run_esptool (self , args , baud = None , chip = None , port = None , preload = True ):
155
+ def run_esptool (
156
+ self , args , baud = arg_baud , chip = arg_chip , port = arg_port , preload = True
157
+ ):
156
158
"""
157
159
Run esptool with the specified arguments. --chip, --port and --baud
158
160
are filled in automatically from the command line.
@@ -189,12 +191,12 @@ def run_esptool_process(cmd):
189
191
esptool = ["-m" , "esptool" ]
190
192
trace_arg = ["--trace" ] if arg_trace else []
191
193
base_cmd = [sys .executable ] + esptool + trace_arg
192
- if chip or arg_chip is not None and chip != "auto" :
193
- base_cmd += ["--chip" , chip or arg_chip ]
194
- if port or arg_port is not None :
195
- base_cmd += ["--port" , port or arg_port ]
196
- if baud or arg_baud is not None :
197
- base_cmd += ["--baud" , str (baud or arg_baud )]
194
+ if chip and chip != "auto" :
195
+ base_cmd += ["--chip" , chip ]
196
+ if port :
197
+ base_cmd += ["--port" , port ]
198
+ if baud :
199
+ base_cmd += ["--baud" , str (baud )]
198
200
usb_jtag_serial_reset = ["--before" , "usb-reset" ] if arg_preload_port else []
199
201
usb_otg_dont_reset = (
200
202
["--after" , "no-reset-stub" ] if "ESPTOOL_TEST_USB_OTG" in os .environ else []
@@ -206,6 +208,7 @@ def run_esptool_process(cmd):
206
208
# Preload a dummy binary to disable the RTC watchdog, needed in USB-JTAG/Serial
207
209
if (
208
210
preload
211
+ and port
209
212
and arg_preload_port
210
213
and arg_chip
211
214
in [
@@ -240,15 +243,15 @@ def run_esptool_process(cmd):
240
243
241
244
return output
242
245
243
- def run_esptool_error (self , args , baud = None , chip = None ):
246
+ def run_esptool_error (self , args , baud = arg_baud , chip = arg_chip , port = arg_port ):
244
247
"""
245
248
Run esptool similar to run_esptool, but expect an error.
246
249
247
250
Verifies the error is an expected error not an unhandled exception,
248
251
and returns the output from esptool as a string.
249
252
"""
250
253
with pytest .raises (subprocess .CalledProcessError ) as fail :
251
- self .run_esptool (args , baud , chip )
254
+ self .run_esptool (args , baud , chip , port )
252
255
failure = fail .value
253
256
assert failure .returncode in [1 , 2 ] # UnsupportedCmdError and FatalError codes
254
257
return failure .output .decode ("utf-8" )
@@ -1913,3 +1916,28 @@ def test_esp_rfc2217_server_py(self):
1913
1916
decoded = output .decode ("utf-8" )
1914
1917
assert "esp_rfc2217_server.py" in decoded
1915
1918
assert "DEPRECATED" in decoded
1919
+
1920
+
1921
+ @pytest .mark .host_test
1922
+ class TestPortFilter (EsptoolTestCase ):
1923
+ def test_port_filter_name (self ):
1924
+ """Test CLI with --port-filter non-existent name option"""
1925
+ output = self .run_esptool_error (
1926
+ "--port-filter name=NonExistentChip flash-id" , port = None
1927
+ )
1928
+ # The command should fail due to no device found, not due to parsing error
1929
+ assert "Option --port-filter argument key not recognized" not in output
1930
+ # Should fail with device connection error instead
1931
+ assert "Found 0 serial ports..." in output
1932
+
1933
+ def test_port_filter_invalid_key_error (self ):
1934
+ """Test CLI with invalid --port-filter key still shows correct error"""
1935
+ output = self .run_esptool_error (
1936
+ "--port-filter invalidkey=123 flash-id" , port = None
1937
+ )
1938
+ assert "Option --port-filter argument key not recognized" in output
1939
+
1940
+ def test_port_filter_missing_equal_sign (self ):
1941
+ """Test CLI with missing equal sign in --port-filter option"""
1942
+ output = self .run_esptool_error ("--port-filter name123 flash-id" , port = None )
1943
+ assert "Option --port-filter argument must consist of key=value." in output
0 commit comments