Debian Codegraph @

python/tests/test_filter_to_disk.py

raw
1 #
2 # subunit: extensions to python unittest to get test results from subprocesses.
3 # Copyright (C) 2013 Subunit Contributors
4 #
5 # Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
6 # license at the users choice. A copy of both licenses are available in the
7 # project source as Apache-2.0 and BSD. You may not use this file except in
8 # compliance with one of these two licences.
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # license you chose for the specific language governing permissions and
14 # limitations under that license.
15
16 import io
17 import os.path
18
19 from fixtures import TempDir
20 from testtools import TestCase
21 from testtools.matchers import FileContains
22
23 from subunit import _to_disk
24 from subunit.v2 import StreamResultToBytes
25
26
27 class SmokeTest(TestCase):
28 def test_smoke(self):
29 output = os.path.join(self.useFixture(TempDir()).path, "output")
30 stdin = io.BytesIO()
31 stdout = io.StringIO()
32 writer = StreamResultToBytes(stdin)
33 writer.startTestRun()
34 writer.status(
35 "foo", "success", {"tag"}, file_name="fred", file_bytes=b"abcdefg", eof=True, mime_type="text/plain"
36 )
37 writer.stopTestRun()
38 stdin.seek(0)
39 _to_disk.to_disk(["-d", output], stdin=stdin, stdout=stdout)
40 self.expectThat(
41 os.path.join(output, "foo/test.json"),
42 FileContains(
43 '{"details": ["fred"], "id": "foo", "start": null, "status": "success", "stop": null, "tags": ["tag"]}'
44 ),
45 )
46 self.expectThat(os.path.join(output, "foo/fred"), FileContains("abcdefg"))