
expect.match_max는 일치하는 문자열의 최대 길이를 지정할 수 있는 옵션이며, 사용법은 다음과 같습니다.
expect.match_max(max_length, string, substring)
- max_length: 일치하는 문자열의 최대 길이
- string: 전체 문자열
- substring: 부분 문자열
예를 들어, "hello world"와 "hello"가 일치하는지 테스트하려면 다음과 같이 사용할 수 있습니다.
expect.match_max(5, "hello world", "hello")
이 코드는 "hello world"의 최대 5자리 문자열이 "hello"와 일치하는지 테스트합니다.
위의 예시 코드에서 expect.match_max를 사용하여 테스트를 작성한 코드는 다음과 같이 수정할 수 있습니다.
python
import unittest
from unittest.mock import patch
class TestHelloWorld(unittest.TestCase):
@patch('sys.stdout')
def test_hello_world(self, mock_stdout):
with patch('builtins.input', return_value='hello'):
self.assertTrue(expect.match_max(5, 'hello world', 'hello'))
이 코드는 "hello world"의 최대 5자리 문자열이 "hello"와 일치하는지 테스트합니다.
2025-06-11 09:38