MCPcopy Index your code
hub / github.com/python/cpython / stream_context

Method stream_context

Lib/test/test_android.py:99–123  ·  view source on GitHub ↗
(self, stream_name, level)

Source from the content-addressed store, hash-verified

97 stream.reconfigure(**original_settings)
98
99 def stream_context(self, stream_name, level):
100 stack = ExitStack()
101 stack.enter_context(self.subTest(stream_name))
102
103 # In --verbose3 mode, sys.stdout and sys.stderr are captured, so we can't
104 # test them directly. Detect this mode and use some temporary streams with
105 # the same properties.
106 stream = getattr(sys, stream_name)
107 native_stream = getattr(sys, f"__{stream_name}__")
108 if isinstance(stream, io.StringIO):
109 # https://developer.android.com/ndk/reference/group/logging
110 prio = {"I": 4, "W": 5}[level]
111 stack.enter_context(
112 patch(
113 f"sys.{stream_name}",
114 stream := TextLogStream(
115 prio, f"python.{stream_name}", native_stream,
116 ),
117 )
118 )
119
120 # The tests assume the stream is initially buffered.
121 stack.enter_context(self.reconfigure(stream, write_through=False))
122
123 return stack
124
125 def test_str(self):
126 for stream_name, level, fileno in STREAM_INFO:

Callers 2

test_strMethod · 0.95
test_bytesMethod · 0.95

Calls 6

reconfigureMethod · 0.95
ExitStackClass · 0.90
patchFunction · 0.90
TextLogStreamClass · 0.90
enter_contextMethod · 0.80
subTestMethod · 0.45

Tested by

no test coverage detected