Debian Codegraph @

autopage/tests/sinks.py

raw symbols SCIP
1 # Licensed under the Apache License, Version 2.0 (the "License"); you may
2 # not use this file except in compliance with the License. You may obtain
3 # a copy of the License at
4 #
5 # http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 # License for the specific language governing permissions and limitations
11 # under the License.
12
13 import io
14 import os
15 import pty
16 import tempfile
17
18 import fixtures # type: ignore
19
20 import typing
21
22
23 class TTYFixture(fixtures.Fixture):
24 def _setUp(self) -> None:
25 self._k, term = pty.openpty()
26 self.stream = os.fdopen(term, 'w')
27 self.addCleanup(self.stream.close)
28 self.addCleanup(os.close, self._k)
29
30
31 class TempFixture(fixtures.Fixture):
32 def _setUp(self) -> None:
33 self.stream = typing.cast(typing.TextIO, tempfile.TemporaryFile('w'))
34
35 def close() -> None:
36 try:
37 self.stream.close()
38 except ValueError:
39 pass
40
41 self.addCleanup(close)
42
43
44 class BufferFixture(fixtures.Fixture):
45 def _setUp(self) -> None:
46 self.stream: typing.TextIO = io.StringIO()
47 self.addCleanup(self.stream.close)