1
1
2
2
import os
3
3
import sys
4
+ import datetime
4
5
import time
5
6
import traceback
6
7
import six
16
17
# http://stackoverflow.com/questions/1707890/fast-way-to-filter-illegal-xml-unicode-chars-in-python
17
18
18
19
_illegal_unichrs = [
19
- (0x00 , 0x08 ), (0x0B , 0x0C ), (0x0E , 0x1F ),
20
- (0x7F , 0x84 ), (0x86 , 0x9F ),
20
+ (0x00 , 0x08 ), (0x0B , 0x0C ), (0x0E , 0x1F ),
21
+ (0x7F , 0x84 ), (0x86 , 0x9F ),
21
22
(0xFDD0 , 0xFDDF ), (0xFFFE , 0xFFFF ),
22
- ]
23
- if sys .maxunicode >= 0x10000 : # not narrow build
23
+ ]
24
+ if sys .maxunicode >= 0x10000 : # not narrow build
24
25
_illegal_unichrs .extend ([
25
- (0x1FFFE , 0x1FFFF ), (0x2FFFE , 0x2FFFF ),
26
- (0x3FFFE , 0x3FFFF ), (0x4FFFE , 0x4FFFF ),
27
- (0x5FFFE , 0x5FFFF ), (0x6FFFE , 0x6FFFF ),
28
- (0x7FFFE , 0x7FFFF ), (0x8FFFE , 0x8FFFF ),
29
- (0x9FFFE , 0x9FFFF ), (0xAFFFE , 0xAFFFF ),
30
- (0xBFFFE , 0xBFFFF ), (0xCFFFE , 0xCFFFF ),
31
- (0xDFFFE , 0xDFFFF ), (0xEFFFE , 0xEFFFF ),
26
+ (0x1FFFE , 0x1FFFF ), (0x2FFFE , 0x2FFFF ),
27
+ (0x3FFFE , 0x3FFFF ), (0x4FFFE , 0x4FFFF ),
28
+ (0x5FFFE , 0x5FFFF ), (0x6FFFE , 0x6FFFF ),
29
+ (0x7FFFE , 0x7FFFF ), (0x8FFFE , 0x8FFFF ),
30
+ (0x9FFFE , 0x9FFFF ), (0xAFFFE , 0xAFFFF ),
31
+ (0xBFFFE , 0xBFFFF ), (0xCFFFE , 0xCFFFF ),
32
+ (0xDFFFE , 0xDFFFF ), (0xEFFFE , 0xEFFFF ),
32
33
(0xFFFFE , 0xFFFFF ), (0x10FFFE , 0x10FFFF ),
33
- ])
34
+ ])
34
35
35
36
_illegal_ranges = [
36
37
"%s-%s" % (six .unichr (low ), six .unichr (high ))
37
38
for (low , high ) in _illegal_unichrs
38
39
]
39
40
40
- INVALID_XML_1_0_UNICODE_RE = re .compile (u'[%s]' % u'' .join (_illegal_ranges ))
41
+ INVALID_XML_1_0_UNICODE_RE = re .compile (u'[%s]' % u'' .join (_illegal_ranges ))
41
42
42
43
43
44
STDOUT_LINE = '\n Stdout:\n %s'
@@ -94,6 +95,7 @@ def __init__(self, test_result, test_method, outcome=SUCCESS, err=None, subTest=
94
95
self .test_result = test_result
95
96
self .outcome = outcome
96
97
self .elapsed_time = 0
98
+ self .timestamp = datetime .datetime .min .replace (microsecond = 0 ).isoformat ()
97
99
if err :
98
100
if self .outcome != _TestInfo .SKIP :
99
101
self .test_exception_name = safe_unicode (err [0 ].__name__ )
@@ -124,6 +126,8 @@ def test_finished(self):
124
126
"""
125
127
self .elapsed_time = \
126
128
self .test_result .stop_time - self .test_result .start_time
129
+ timestamp = datetime .datetime .fromtimestamp (self .test_result .stop_time )
130
+ self .timestamp = timestamp .replace (microsecond = 0 ).isoformat ()
127
131
128
132
def get_description (self ):
129
133
"""
@@ -343,6 +347,10 @@ def _report_testsuite(suite_name, tests, xml_document, parentElement,
343
347
testsuite .setAttribute (
344
348
'time' , '%.3f' % sum (map (lambda e : e .elapsed_time , tests ))
345
349
)
350
+ if tests :
351
+ testsuite .setAttribute (
352
+ 'timestamp' , max (map (lambda e : e .timestamp , tests ))
353
+ )
346
354
failures = filter (lambda e : e .outcome == e .FAILURE , tests )
347
355
testsuite .setAttribute ('failures' , str (len (list (failures ))))
348
356
@@ -351,7 +359,7 @@ def _report_testsuite(suite_name, tests, xml_document, parentElement,
351
359
352
360
skips = filter (lambda e : e .outcome == _TestInfo .SKIP , tests )
353
361
testsuite .setAttribute ('skipped' , str (len (list (skips ))))
354
-
362
+
355
363
_XMLTestResult ._report_testsuite_properties (
356
364
testsuite , xml_document , properties )
357
365
@@ -420,6 +428,7 @@ def _report_testcase(test_result, xml_testsuite, xml_document):
420
428
'name' , _XMLTestResult ._test_method_name (test_result .test_id )
421
429
)
422
430
testcase .setAttribute ('time' , '%.3f' % test_result .elapsed_time )
431
+ testcase .setAttribute ('timestamp' , test_result .timestamp )
423
432
424
433
if (test_result .outcome != test_result .SUCCESS ):
425
434
elem_name = ('failure' , 'error' , 'skipped' )[test_result .outcome - 1 ]
0 commit comments