gromero commented on code in PR #11043:
URL: https://github.com/apache/tvm/pull/11043#discussion_r853507006


##########
apps/microtvm/arduino/template_project/tests/test_arduino_microtvm_api_server.py:
##########
@@ -98,36 +101,52 @@ def test_parse_connected_boards(self):
         ]
 
     @mock.patch("subprocess.run")
-    def test_auto_detect_port(self, sub_mock):
+    def test_auto_detect_port(self, mock_run):
         process_mock = mock.Mock()
         handler = microtvm_api_server.Handler()
 
         # Test it returns the correct port when a board is connected
-        sub_mock.return_value.stdout = bytes(self.BOARD_CONNECTED_V18, "utf-8")
+        mock_run.return_value.stdout = bytes(self.BOARD_CONNECTED_V18, "utf-8")
         assert handler._auto_detect_port(self.DEFAULT_OPTIONS) == 
"/dev/ttyACM0"
 
-        # Test it raises an exception when no board is connected
-        sub_mock.return_value.stdout = bytes(self.BOARD_CONNECTED_V21, "utf-8")
+        # Should work with old or new arduino-cli version
+        mock_run.return_value.stdout = bytes(self.BOARD_CONNECTED_V21, "utf-8")
         assert handler._auto_detect_port(self.DEFAULT_OPTIONS) == 
"/dev/ttyACM0"
 
-        # Should work with old or new arduino-cli version
-        sub_mock.return_value.stdout = bytes(self.BOARD_DISCONNECTED_V21, 
"utf-8")
+        # Test it raises an exception when no board is connected
+        mock_run.return_value.stdout = bytes(self.BOARD_DISCONNECTED_V21, 
"utf-8")
         with pytest.raises(microtvm_api_server.BoardAutodetectFailed):
             handler._auto_detect_port(self.DEFAULT_OPTIONS)
 
         # Test that the FQBN needs to match EXACTLY
         handler._get_fqbn = 
mock.MagicMock(return_value="arduino:mbed_nano:nano33")
-        sub_mock.return_value.stdout = bytes(self.BOARD_CONNECTED_V18, "utf-8")
+        mock_run.return_value.stdout = bytes(self.BOARD_CONNECTED_V18, "utf-8")
         assert (
             handler._auto_detect_port({**self.DEFAULT_OPTIONS, 
"arduino_board": "nano33"})
             == "/dev/ttyACM1"
         )
 
-    CLI_VERSION = "arduino-cli  Version: 0.21.1 Commit: 9fcbb392 Date: 
2022-02-24T15:41:45Z\n"
+    BAD_CLI_VERSION = "arduino-cli  Version: 0.7.1 Commit: 7668c465 Date: 
2019-12-31T18:24:32Z\n"
+    GOOD_CLI_VERSION = "arduino-cli  Version: 0.21.1 Commit: 9fcbb392 Date: 
2022-02-24T15:41:45Z\n"
+
+    @mock.patch("subprocess.run")
+    def test_auto_detect_port(self, mock_run):
+        handler = microtvm_api_server.Handler()
+        mock_run.return_value.stdout = bytes(self.GOOD_CLI_VERSION, "utf-8")
+        handler._check_platform_version(self.DEFAULT_OPTIONS)
+        assert handler._version == version.parse("0.21.1")
+
+        # Using too low a version should raise an error. Note that naively

Review Comment:
   nit: the second part of this comment, about the naive comparison, seems to 
be a bit misplaced here, would it fit better in the test above for 
`GOOD_CLI_VERSION` instead (or even in `_get_platform_version` when 
`version.parse()` is used)?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to