subunit: Import new version.
[nivanova/samba-autobuild/.git] / lib / subunit / python / subunit / tests / test_subunit_tags.py
1 #
2 #  subunit: extensions to python unittest to get test results from subprocesses.
3 #  Copyright (C) 2005  Robert Collins <robertc@robertcollins.net>
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 """Tests for subunit.tag_stream."""
18
19 import unittest
20 from StringIO import StringIO
21
22 import subunit
23 import subunit.test_results
24
25
26 class TestSubUnitTags(unittest.TestCase):
27
28     def setUp(self):
29         self.original = StringIO()
30         self.filtered = StringIO()
31
32     def test_add_tag(self):
33         self.original.write("tags: foo\n")
34         self.original.write("test: test\n")
35         self.original.write("tags: bar -quux\n")
36         self.original.write("success: test\n")
37         self.original.seek(0)
38         result = subunit.tag_stream(self.original, self.filtered, ["quux"])
39         self.assertEqual([
40             "tags: quux",
41             "tags: foo",
42             "test: test",
43             "tags: bar",
44             "success: test",
45             ],
46             self.filtered.getvalue().splitlines())
47
48     def test_remove_tag(self):
49         self.original.write("tags: foo\n")
50         self.original.write("test: test\n")
51         self.original.write("tags: bar -quux\n")
52         self.original.write("success: test\n")
53         self.original.seek(0)
54         result = subunit.tag_stream(self.original, self.filtered, ["-bar"])
55         self.assertEqual([
56             "tags: -bar",
57             "tags: foo",
58             "test: test",
59             "tags: -quux",
60             "success: test",
61             ],
62             self.filtered.getvalue().splitlines())
63
64
65 def test_suite():
66     loader = subunit.tests.TestUtil.TestLoader()
67     result = loader.loadTestsFromName(__name__)
68     return result