Skip to content

Commit 329588a

Browse files
committed
[test] Adapt Tests to Section Type Requirement
1 parent a920a49 commit 329588a

File tree

4 files changed

+34
-29
lines changed

4 files changed

+34
-29
lines changed

test/test_doc_integration.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,25 +104,26 @@ def test_children(self):
104104
"""
105105
This test checks the correct saving and loading of Section children of a Document.
106106
"""
107+
s_type = "type"
107108
# Lvl 1 child Sections
108-
sec_lvl_11 = odml.Section(name="sec_11", parent=self.doc)
109-
_ = odml.Section(name="sec_12", parent=self.doc)
109+
sec_lvl_11 = odml.Section(name="sec_11", type=s_type, parent=self.doc)
110+
_ = odml.Section(name="sec_12", type=s_type, parent=self.doc)
110111

111112
# Lvl 2 child Sections
112-
sec_lvl_21 = odml.Section(name="sec_21", parent=sec_lvl_11)
113-
_ = odml.Section(name="sec_22", parent=sec_lvl_11)
114-
_ = odml.Section(name="sec_23", parent=sec_lvl_11)
113+
sec_lvl_21 = odml.Section(name="sec_21", type=s_type, parent=sec_lvl_11)
114+
_ = odml.Section(name="sec_22", type=s_type, parent=sec_lvl_11)
115+
_ = odml.Section(name="sec_23", type=s_type, parent=sec_lvl_11)
115116

116117
# Lvl 2 child Properties
117118
_ = odml.Property(name="prop_21", parent=sec_lvl_11)
118119
_ = odml.Property(name="prop_22", parent=sec_lvl_11)
119120
_ = odml.Property(name="prop_23", parent=sec_lvl_11)
120121

121122
# Lvl 3 child Sections
122-
_ = odml.Section(name="sec_31", parent=sec_lvl_21)
123-
_ = odml.Section(name="sec_32", parent=sec_lvl_21)
124-
_ = odml.Section(name="sec_33", parent=sec_lvl_21)
125-
_ = odml.Section(name="sec_34", parent=sec_lvl_21)
123+
_ = odml.Section(name="sec_31", type=s_type, parent=sec_lvl_21)
124+
_ = odml.Section(name="sec_32", type=s_type, parent=sec_lvl_21)
125+
_ = odml.Section(name="sec_33", type=s_type, parent=sec_lvl_21)
126+
_ = odml.Section(name="sec_34", type=s_type, parent=sec_lvl_21)
126127

127128
# Lvl 3 child Properties
128129
_ = odml.Property(name="prop_31", parent=sec_lvl_21)

test/test_dumper.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,19 @@ def setUp(self):
1616
self.captured_stdout = StringIO()
1717
sys.stdout = self.captured_stdout
1818

19+
s_type = "type"
20+
1921
self.doc = odml.Document(author='Rave', version='1.0')
20-
s1 = odml.Section(name='Cell')
22+
s1 = odml.Section(name='Cell', type=s_type)
2123
p1 = odml.Property(name='Type', values='Rechargeable')
2224
s1.append(p1)
2325

24-
s2 = odml.Section(name='Electrolyte')
26+
s2 = odml.Section(name='Electrolyte', type=s_type)
2527
p2 = odml.Property(name='Composition', values='Ni-Cd')
2628
s2.append(p2)
2729
s1.append(s2)
2830

29-
s3 = odml.Section(name='Electrode')
31+
s3 = odml.Section(name='Electrode', type=s_type)
3032
p3 = odml.Property(name='Material', values='Nickel')
3133
p4 = odml.Property(name='Models', values=['AA', 'AAA'])
3234
s3.append(p3)
@@ -41,11 +43,11 @@ def test_dump_doc(self):
4143
odml.tools.dumper.dump_doc(self.doc)
4244
output = [x.strip() for x in self.captured_stdout.getvalue().split('\n') if x]
4345
expected_output = []
44-
expected_output.append("*Cell ()")
46+
expected_output.append("*Cell (type='type')")
4547
expected_output.append(":Type (values=Rechargeable, dtype='string')")
46-
expected_output.append("*Electrolyte ()")
48+
expected_output.append("*Electrolyte (type='type')")
4749
expected_output.append(":Composition (values=Ni-Cd, dtype='string')")
48-
expected_output.append("*Electrode ()")
50+
expected_output.append("*Electrode (type='type')")
4951
expected_output.append(":Material (values=Nickel, dtype='string')")
5052
expected_output.append(":Models (values=[AA,AAA], dtype='string')")
5153
self.assertEqual(len(output), len(expected_output))

test/test_section_integration.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ def save_load(self):
5151
def test_id(self):
5252
# Test correct save and load of generated id.
5353
sec_name = "empty_id"
54-
sec = odml.Section(name=sec_name, parent=self.doc)
54+
sec_type = "type"
55+
sec = odml.Section(name=sec_name, type=sec_type, parent=self.doc)
5556

5657
jdoc, xdoc, ydoc = self.save_load()
5758

@@ -62,7 +63,7 @@ def test_id(self):
6263
# Test correct save and load of assigned id.
6364
sec_name = "assigned_id"
6465
assigned_id = "79b613eb-a256-46bf-84f6-207df465b8f7"
65-
_ = odml.Section(name=sec_name, oid=assigned_id, parent=self.doc)
66+
_ = odml.Section(name=sec_name, oid=assigned_id, type=sec_type, parent=self.doc)
6667

6768
jdoc, xdoc, ydoc = self.save_load()
6869

@@ -116,31 +117,32 @@ def test_children(self):
116117
This test checks correct writing and loading of Section and Property
117118
children of a Section.
118119
"""
119-
root = odml.Section(name="root", parent=self.doc)
120+
s_type = "type"
121+
root = odml.Section(name="root", type=s_type, parent=self.doc)
120122

121123
# Lvl 1 child Sections
122-
sec_lvl_11 = odml.Section(name="sec_11", parent=root)
123-
_ = odml.Section(name="sec_12", parent=root)
124+
sec_lvl_11 = odml.Section(name="sec_11", type=s_type, parent=root)
125+
_ = odml.Section(name="sec_12", type=s_type, parent=root)
124126

125127
# Lvl 1 child Properties
126128
_ = odml.Property(name="prop_11", parent=root)
127129
_ = odml.Property(name="prop_12", parent=root)
128130

129131
# Lvl 2 child Sections
130-
sec_lvl_21 = odml.Section(name="sec_21", parent=sec_lvl_11)
131-
_ = odml.Section(name="sec_22", parent=sec_lvl_11)
132-
_ = odml.Section(name="sec_23", parent=sec_lvl_11)
132+
sec_lvl_21 = odml.Section(name="sec_21", type=s_type, parent=sec_lvl_11)
133+
_ = odml.Section(name="sec_22", type=s_type, parent=sec_lvl_11)
134+
_ = odml.Section(name="sec_23", type=s_type, parent=sec_lvl_11)
133135

134136
# Lvl 2 child Properties
135137
_ = odml.Property(name="prop_21", parent=sec_lvl_11)
136138
_ = odml.Property(name="prop_22", parent=sec_lvl_11)
137139
_ = odml.Property(name="prop_23", parent=sec_lvl_11)
138140

139141
# Lvl 3 child Sections
140-
_ = odml.Section(name="sec_31", parent=sec_lvl_21)
141-
_ = odml.Section(name="sec_32", parent=sec_lvl_21)
142-
_ = odml.Section(name="sec_33", parent=sec_lvl_21)
143-
_ = odml.Section(name="sec_34", parent=sec_lvl_21)
142+
_ = odml.Section(name="sec_31", type=s_type, parent=sec_lvl_21)
143+
_ = odml.Section(name="sec_32", type=s_type, parent=sec_lvl_21)
144+
_ = odml.Section(name="sec_33", type=s_type, parent=sec_lvl_21)
145+
_ = odml.Section(name="sec_34", type=s_type, parent=sec_lvl_21)
144146

145147
# Lvl 3 child Properties
146148
_ = odml.Property(name="prop_31", parent=sec_lvl_21)

test/test_validation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ def test_standalone_section(self):
135135

136136
sec_one = odml.Section("sec1")
137137

138-
for err in validate(sec_one).errors:
139-
assert not err.is_error
138+
res = validate(sec_one)
139+
self.assertError(res, "Section type undefined")
140140

141141
doc = samplefile.parse("""s1[undefined]""")
142142
res = validate(doc)

0 commit comments

Comments
 (0)