forked from G-Node/python-odml
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_dumper.py
More file actions
59 lines (48 loc) · 2.1 KB
/
Copy pathtest_dumper.py
File metadata and controls
59 lines (48 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import unittest
import sys
import odml
try:
from StringIO import StringIO
except ImportError:
from io import StringIO
class TestTypes(unittest.TestCase):
def setUp(self):
# Capture the output printed by the functions to STDOUT, and use it for
# testing purposes.
self.captured_stdout = StringIO()
sys.stdout = self.captured_stdout
s_type = "type"
self.doc = odml.Document(author='Rave', version='1.0')
s1 = odml.Section(name='Cell', type=s_type)
p1 = odml.Property(name='Type', values='Rechargeable')
s1.append(p1)
s2 = odml.Section(name='Electrolyte', type=s_type)
p2 = odml.Property(name='Composition', values='Ni-Cd')
s2.append(p2)
s1.append(s2)
s3 = odml.Section(name='Electrode', type=s_type)
p3 = odml.Property(name='Material', values='Nickel')
p4 = odml.Property(name='Models', values=['AA', 'AAA'])
s3.append(p3)
s3.append(p4)
s2.append(s3)
self.doc.append(s1)
def test_dump_doc(self):
# This test dumps the whole document and checks it word by word.
# If possible, maybe some better way of testing this ?
odml.tools.dumper.dump_doc(self.doc)
output = [x.strip() for x in self.captured_stdout.getvalue().split('\n') if x]
expected_output = []
expected_output.append("*Cell (type='type')")
expected_output.append(":Type (values=Rechargeable, dtype='string')")
expected_output.append("*Electrolyte (type='type')")
expected_output.append(":Composition (values=Ni-Cd, dtype='string')")
expected_output.append("*Electrode (type='type')")
expected_output.append(":Material (values=Nickel, dtype='string')")
expected_output.append(":Models (values=[AA,AAA], dtype='string')")
self.assertEqual(len(output), len(expected_output))
for i in range(len(output)):
self.assertEqual(output[i], expected_output[i])
# Discard the document output from stdout stream
self.captured_stdout.seek(0)
self.captured_stdout.truncate(0)