41c32129d04f5c02bce69b8d136a84ced6e571a2
[nivanova/samba-autobuild/.git] / lib / subunit / python / subunit / tests / test_details.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 from cStringIO import StringIO
18 import unittest
19
20 import subunit.tests
21 from subunit import content, content_type, details
22
23
24 def test_suite():
25     loader = subunit.tests.TestUtil.TestLoader()
26     result = loader.loadTestsFromName(__name__)
27     return result
28
29
30 class TestSimpleDetails(unittest.TestCase):
31
32     def test_lineReceived(self):
33         parser = details.SimpleDetailsParser(None)
34         parser.lineReceived("foo\n")
35         parser.lineReceived("bar\n")
36         self.assertEqual("foo\nbar\n", parser._message)
37
38     def test_lineReceived_escaped_bracket(self):
39         parser = details.SimpleDetailsParser(None)
40         parser.lineReceived("foo\n")
41         parser.lineReceived(" ]are\n")
42         parser.lineReceived("bar\n")
43         self.assertEqual("foo\n]are\nbar\n", parser._message)
44
45     def test_get_message(self):
46         parser = details.SimpleDetailsParser(None)
47         self.assertEqual("", parser.get_message())
48
49     def test_get_details(self):
50         parser = details.SimpleDetailsParser(None)
51         traceback = ""
52         expected = {}
53         expected['traceback'] = content.Content(
54             content_type.ContentType("text", "x-traceback",
55                 {'charset': 'utf8'}),
56             lambda:[""])
57         found = parser.get_details()
58         self.assertEqual(expected.keys(), found.keys())
59         self.assertEqual(expected['traceback'].content_type,
60             found['traceback'].content_type)
61         self.assertEqual(''.join(expected['traceback'].iter_bytes()),
62             ''.join(found['traceback'].iter_bytes()))
63
64     def test_get_details_skip(self):
65         parser = details.SimpleDetailsParser(None)
66         traceback = ""
67         expected = {}
68         expected['reason'] = content.Content(
69             content_type.ContentType("text", "plain"),
70             lambda:[""])
71         found = parser.get_details("skip")
72         self.assertEqual(expected, found)
73
74     def test_get_details_success(self):
75         parser = details.SimpleDetailsParser(None)
76         traceback = ""
77         expected = {}
78         expected['message'] = content.Content(
79             content_type.ContentType("text", "plain"),
80             lambda:[""])
81         found = parser.get_details("success")
82         self.assertEqual(expected, found)
83
84
85 class TestMultipartDetails(unittest.TestCase):
86
87     def test_get_message_is_None(self):
88         parser = details.MultipartDetailsParser(None)
89         self.assertEqual(None, parser.get_message())
90
91     def test_get_details(self):
92         parser = details.MultipartDetailsParser(None)
93         self.assertEqual({}, parser.get_details())
94
95     def test_parts(self):
96         parser = details.MultipartDetailsParser(None)
97         parser.lineReceived("Content-Type: text/plain\n")
98         parser.lineReceived("something\n")
99         parser.lineReceived("F\r\n")
100         parser.lineReceived("serialised\n")
101         parser.lineReceived("form0\r\n")
102         expected = {}
103         expected['something'] = content.Content(
104             content_type.ContentType("text", "plain"),
105             lambda:["serialised\nform"])
106         found = parser.get_details()
107         self.assertEqual(expected.keys(), found.keys())
108         self.assertEqual(expected['something'].content_type,
109             found['something'].content_type)
110         self.assertEqual(''.join(expected['something'].iter_bytes()),
111             ''.join(found['something'].iter_bytes()))