Skip to content

Commit d748ec0

Browse files
committed
Fix CLI tests
1 parent 4c4ff99 commit d748ec0

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

chipflow_lib/platforms/_software.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import warnings
55

66
from collections import defaultdict
7-
from typing import TYPE_CHECKING
87

98
from amaranth import Fragment
109
from amaranth.hdl import UnusedElaboratable

chipflow_lib/steps/silicon.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
# SPDX-License-Identifier: BSD-2-Clause
44

5-
import argparse
65
import inspect
76
import json
87
import logging
@@ -178,7 +177,7 @@ def submit(self, rtlil_path, args):
178177
json.dump(data, f)
179178
with open("config", 'w') as f:
180179
f.write(config)
181-
sp.info(f"Compiled design and configuration can be found in in `rtlil` and `config`")
180+
sp.info("Compiled design and configuration can be found in in `rtlil` and `config`")
182181
return
183182

184183
def network_err(e):

tests/test_cli.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import pytest
44
import unittest
5+
6+
from contextlib import redirect_stdout
7+
from io import StringIO
58
from unittest import mock
69

710
from chipflow_lib import ChipFlowError
@@ -64,17 +67,15 @@ def test_run_command_error(self, mock_get_cls, mock_pin_command, mock_parse_conf
6467
mock_get_cls.return_value = lambda config: mock_test_cmd
6568

6669
# Capture stdout for assertion
67-
with mock.patch("builtins.print") as mock_print:
70+
with redirect_stdout(StringIO()) as buffer:
6871
with pytest.raises(SystemExit) as systemexit:
6972
# Run with error action
7073
run(["test", "error"])
7174

7275
assert systemexit.type is SystemExit
7376
assert systemexit.value.code == 1
7477

75-
# Error message should be printed
76-
mock_print.assert_called_once()
77-
self.assertIn("Error while executing `test error`", mock_print.call_args[0][0])
78+
self.assertIn("Error while executing `test error`", buffer.getvalue())
7879

7980
@mock.patch("chipflow_lib.cli._parse_config")
8081
@mock.patch("chipflow_lib.cli.PinCommand")
@@ -91,7 +92,7 @@ def test_run_unexpected_error(self, mock_get_cls, mock_pin_command, mock_parse_c
9192
mock_get_cls.return_value = lambda config: mock_test_cmd
9293

9394
# Capture stdout for assertion
94-
with mock.patch("builtins.print") as mock_print:
95+
with redirect_stdout(StringIO()) as buffer:
9596
with pytest.raises(SystemExit) as systemexit:
9697
# Run with unexpected error action
9798
run(["test", "unexpected"])
@@ -100,9 +101,8 @@ def test_run_unexpected_error(self, mock_get_cls, mock_pin_command, mock_parse_c
100101
assert systemexit.value.code == 1
101102

102103
# Error message should be printed
103-
mock_print.assert_called_once()
104-
self.assertIn("Error while executing `test unexpected`", mock_print.call_args[0][0])
105-
self.assertIn("Unexpected error", mock_print.call_args[0][0])
104+
self.assertIn("Error while executing `test unexpected`", buffer.getvalue())
105+
self.assertIn("Unexpected error", buffer.getvalue())
106106

107107
@mock.patch("chipflow_lib.cli._parse_config")
108108
@mock.patch("chipflow_lib.cli.PinCommand")

0 commit comments

Comments
 (0)