Debian Codegraph @

python/tests/test_details.py

raw
1 #
2 # subunit: extensions to python unittest to get test results from subprocesses.
3 # Copyright (C) 2005 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 import unittest
18
19
20 from subunit import content, content_type, details
21
22
23 class TestSimpleDetails(unittest.TestCase):
24 def test_lineReceived(self):
25 parser = details.SimpleDetailsParser(None)
26 parser.lineReceived(b"foo\n")
27 parser.lineReceived(b"bar\n")
28 self.assertEqual(b"foo\nbar\n", parser._message)
29
30 def test_lineReceived_escaped_bracket(self):
31 parser = details.SimpleDetailsParser(None)
32 parser.lineReceived(b"foo\n")
33 parser.lineReceived(b" ]are\n")
34 parser.lineReceived(b"bar\n")
35 self.assertEqual(b"foo\n]are\nbar\n", parser._message)
36
37 def test_get_message(self):
38 parser = details.SimpleDetailsParser(None)
39 self.assertEqual(b"", parser.get_message())
40
41 def test_get_details(self):
42 parser = details.SimpleDetailsParser(None)
43 expected = {}
44 expected["traceback"] = content.Content(
45 content_type.ContentType("text", "x-traceback", {"charset": "utf8"}), lambda: [b""]
46 )
47 found = parser.get_details()
48 self.assertEqual(expected.keys(), found.keys())
49 self.assertEqual(expected["traceback"].content_type, found["traceback"].content_type)
50 self.assertEqual(b"".join(expected["traceback"].iter_bytes()), b"".join(found["traceback"].iter_bytes()))
51
52 def test_get_details_skip(self):
53 parser = details.SimpleDetailsParser(None)
54 expected = {}
55 expected["reason"] = content.Content(content_type.ContentType("text", "plain"), lambda: [b""])
56 found = parser.get_details("skip")
57 self.assertEqual(expected, found)
58
59 def test_get_details_success(self):
60 parser = details.SimpleDetailsParser(None)
61 expected = {}
62 expected["message"] = content.Content(content_type.ContentType("text", "plain"), lambda: [b""])
63 found = parser.get_details("success")
64 self.assertEqual(expected, found)
65
66
67 class TestMultipartDetails(unittest.TestCase):
68 def test_get_message_is_None(self):
69 parser = details.MultipartDetailsParser(None)
70 self.assertEqual(None, parser.get_message())
71
72 def test_get_details(self):
73 parser = details.MultipartDetailsParser(None)
74 self.assertEqual({}, parser.get_details())
75
76 def test_parts(self):
77 parser = details.MultipartDetailsParser(None)
78 parser.lineReceived(b"Content-Type: text/plain\n")
79 parser.lineReceived(b"something\n")
80 parser.lineReceived(b"F\r\n")
81 parser.lineReceived(b"serialised\n")
82 parser.lineReceived(b"form0\r\n")
83 expected = {}
84 expected["something"] = content.Content(
85 content_type.ContentType("text", "plain"), lambda: [b"serialised\nform"]
86 )
87 found = parser.get_details()
88 self.assertEqual(expected.keys(), found.keys())
89 self.assertEqual(expected["something"].content_type, found["something"].content_type)
90 self.assertEqual(b"".join(expected["something"].iter_bytes()), b"".join(found["something"].iter_bytes()))