~ihanick/percona-server/5.1.59-innodb_log_archiving

« back to all changes in this revision

Viewing changes to python-for-subunit2junitxml/subunit/tests/test_details.py

  • Committer: Stewart Smith
  • Date: 2011-10-06 06:45:16 UTC
  • Revision ID: stewart@flamingspork.com-20111006064516-rrjg17x7wwn9vr6w
add subunit support to mtr

Show diffs side-by-side

added added

removed removed

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