forked from Ikalus1988/MisakaNet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_search_knowledge_stdout.py
More file actions
37 lines (25 loc) 路 972 Bytes
/
Copy pathtest_search_knowledge_stdout.py
File metadata and controls
37 lines (25 loc) 路 972 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import io
import unittest
from unittest import mock
import search_knowledge
class ReconfigurableStdout(io.StringIO):
def __init__(self):
super().__init__()
self.reconfigure_calls = []
def reconfigure(self, **kwargs):
self.reconfigure_calls.append(kwargs)
class TestSearchKnowledgeStdout(unittest.TestCase):
def test_ensure_utf8_stdout_reconfigures_stream(self):
stdout = ReconfigurableStdout()
with mock.patch.object(search_knowledge.sys, "stdout", stdout):
search_knowledge._ensure_utf8_stdout()
self.assertEqual(
stdout.reconfigure_calls,
[{"encoding": "utf-8", "errors": "replace"}],
)
def test_ensure_utf8_stdout_ignores_unsupported_stream(self):
stdout = io.StringIO()
with mock.patch.object(search_knowledge.sys, "stdout", stdout):
search_knowledge._ensure_utf8_stdout()
if __name__ == "__main__":
unittest.main()