Skip to content

Commit 9251f19

Browse files
authored
Testsuite list (#13)
* use ordered dictionary for sub_suites * fix flake8 issues * minor changes from review
1 parent 4b8017f commit 9251f19

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

python_testspace_xml/testspace_xml.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import print_function
22
import base64
33
import gzip
4+
import collections
45
import os
56
import io
67
from io import BytesIO
@@ -184,7 +185,7 @@ def add_annotation(self, annotation):
184185
class TestSuite:
185186
def __init__(self, name):
186187
# optional sub-suites
187-
self.sub_suites = {}
188+
self.sub_suites = collections.OrderedDict()
188189
self.is_root_suite = False
189190
self.name = name
190191
self.description = ''
@@ -290,9 +291,9 @@ def _write_suite(self, parent_node, test_suite):
290291
for tc in test_suite.test_cases:
291292
self._write_test_case(suite_elem, tc)
292293

293-
# write child suites, sort by name
294-
for ts in sorted(test_suite.sub_suites.keys()):
295-
self._write_suite(suite_elem, test_suite.sub_suites[ts])
294+
# write child suites
295+
for v in test_suite.sub_suites.values():
296+
self._write_suite(suite_elem, v)
296297

297298
def _write_test_case(self, parent_node, test_case):
298299
elem_tc = self.dom.createElement('test_case')

tests/test_testspace_report_xsd.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66

77

88
class TestTestspaceReportXsd:
9+
testsuite_list = ['z testsuite',
10+
'1 testsuite',
11+
'Example Suite',
12+
'A test suite',
13+
'aa test suite']
14+
915
annotation_tuple = [
1016
('zannotation warning example', 'warn', 'to confirm order of annotations'),
1117
('annotation info example', 'info', 'description of annotation'),
@@ -23,6 +29,9 @@ class TestTestspaceReportXsd:
2329
def setup_class(cls):
2430
testspace_report = testspace_xml.TestspaceReport()
2531

32+
for suite in cls.testsuite_list:
33+
testspace_report.add_test_suite(suite)
34+
2635
example_suite = testspace_report.get_or_add_test_suite('Example Suite')
2736
example_suite.add_link_annotation(path='https://help.testspace.com')
2837
example_suite.add_string_buffer_annotation(
@@ -78,12 +87,17 @@ def teardown_class(cls):
7887
os.remove('testspace.xml')
7988

8089
def test_number_testsuites(self):
81-
test_cases = self.testspace_xml_root.xpath("//test_suite")
82-
assert len(test_cases) is 1
90+
test_suites = self.testspace_xml_root.xpath("//test_suite")
91+
assert len(test_suites) is 5
92+
93+
def test_testsuites_order(self):
94+
test_suites = self.testspace_xml_root.xpath("//test_suite")
95+
for idx, tests_suite in enumerate(test_suites):
96+
assert tests_suite.get('name') == self.testsuite_list[idx]
8397

8498
def test_number_testsuite_annotations(self):
85-
test_cases = self.testspace_xml_root.xpath("//test_suite/annotation")
86-
assert len(test_cases) is 5
99+
test_suites = self.testspace_xml_root.xpath("//test_suite/annotation")
100+
assert len(test_suites) is 5
87101

88102
def test_testsuite_duration(self):
89103
suite_element = self.testspace_xml_root.xpath("//test_suite[@duration]")
@@ -125,7 +139,8 @@ def test_annotation_order(self):
125139
assert annotation.get('name') == self.annotation_tuple[idx][0]
126140

127141
def test_testcase_duration(self):
128-
suite_element = self.testspace_xml_root.xpath("//test_suite/test_case[@name='passing case 2']")
142+
suite_element = self.testspace_xml_root.xpath(
143+
"//test_suite/test_case[@name='passing case 2']")
129144
assert float(suite_element[0].attrib['duration']) == self.duration
130145

131146
def test_validate_xsd(self):

0 commit comments

Comments
 (0)