Debian Codegraph @

python/tests/test_filters.py

raw
1 #
2 # subunit: extensions to Python unittest to get test results from subprocesses.
3 # Copyright (C) 2013 Robert Collins <[email protected]>
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
17 from tempfile import NamedTemporaryFile
18
19 from testtools import TestCase
20
21 from subunit import read_test_list
22 from subunit.filters import find_stream
23
24
25 class TestReadTestList(TestCase):
26 def test_read_list(self):
27 with NamedTemporaryFile() as f:
28 f.write(b"foo\nbar\n# comment\nother # comment\n")
29 f.flush()
30 self.assertEqual(read_test_list(f.name), ["foo", "bar", "other"])
31
32
33 class TestFindStream(TestCase):
34 def test_no_argv(self):
35 self.assertEqual("foo", find_stream("foo", []))
36
37 def test_opens_file(self):
38 f = NamedTemporaryFile()
39 f.write(b"foo")
40 f.flush()
41 stream = find_stream("bar", [f.name])
42 self.assertEqual(b"foo", stream.read())