55
55
56
56
57
57
def decode (var , encoding ):
58
- '''
58
+ """
59
59
If not already unicode, decode it.
60
- '''
60
+ """
61
61
if PY2 :
62
62
if isinstance (var , unicode ):
63
63
ret = var
@@ -74,9 +74,10 @@ def decode(var, encoding):
74
74
75
75
76
76
class TestSuite (object ):
77
- '''Suite of test cases.
77
+ """
78
+ Suite of test cases.
78
79
Can handle unicode strings or binary strings if their encoding is provided.
79
- '''
80
+ """
80
81
81
82
def __init__ (self , name , test_cases = None , hostname = None , id = None ,
82
83
package = None , timestamp = None , properties = None ):
@@ -94,14 +95,13 @@ def __init__(self, name, test_cases=None, hostname=None, id=None,
94
95
self .timestamp = timestamp
95
96
self .properties = properties
96
97
97
-
98
98
def build_xml_doc (self , encoding = None ):
99
- '''
99
+ """
100
100
Builds the XML document for the JUnit test suite.
101
101
Produces clean unicode strings and decodes non-unicode with the help of encoding.
102
102
@param encoding: Used to decode encoded strings.
103
103
@return: XML document with unicode string elements
104
- '''
104
+ """
105
105
106
106
# build the test suite element
107
107
test_suite_attributes = dict ()
@@ -192,10 +192,11 @@ def build_xml_doc(self, encoding=None):
192
192
193
193
@staticmethod
194
194
def to_xml_string (test_suites , prettyprint = True , encoding = None ):
195
- '''Returns the string representation of the JUnit XML document.
195
+ """
196
+ Returns the string representation of the JUnit XML document.
196
197
@param encoding: The encoding of the input.
197
198
@return: unicode string
198
- '''
199
+ """
199
200
200
201
try :
201
202
iter (test_suites )
@@ -233,22 +234,21 @@ def to_xml_string(test_suites, prettyprint=True, encoding=None):
233
234
234
235
@staticmethod
235
236
def to_file (file_descriptor , test_suites , prettyprint = True , encoding = None ):
236
- '''
237
+ """
237
238
Writes the JUnit XML document to a file.
238
- '''
239
+ """
239
240
xml_string = TestSuite .to_xml_string (
240
241
test_suites , prettyprint = prettyprint , encoding = encoding )
241
242
# has problems with encoded str with non-ASCII (non-default-encoding) characters!
242
243
file_descriptor .write (xml_string )
243
244
244
-
245
245
@staticmethod
246
246
def _clean_illegal_xml_chars (string_to_clean ):
247
- '''
247
+ """
248
248
Removes any illegal unicode characters from the given XML string.
249
249
250
250
@see: http://stackoverflow.com/questions/1707890/fast-way-to-filter-illegal-xml-unicode-chars-in-python
251
- '''
251
+ """
252
252
253
253
illegal_unichrs = [
254
254
(0x00 , 0x08 ), (0x0B , 0x1F ), (0x7F , 0x84 ), (0x86 , 0x9F ),
0 commit comments