Skip to content

Commit 89a5536

Browse files
committed
[test_validation.py] Add Test for Section Init Validation Stdout
1 parent d3faa1f commit 89a5536

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

test/test_validation.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import unittest
22
import odml
33
import os
4+
import sys
45
import odml.validation
56
import odml.terminology
67
from . import test_samplefile as samplefile
78

9+
try:
10+
from StringIO import StringIO
11+
except ImportError:
12+
from io import StringIO
13+
814
validate = odml.validation.Validation
915

1016

@@ -176,6 +182,19 @@ def test_standalone_property(self):
176182
for err in validate(prop).errors:
177183
assert not err.is_error
178184

185+
def test_section_init(self):
186+
"""
187+
Test validation errors printed to stdout on section init.
188+
"""
189+
val_errs = StringIO()
190+
191+
old_stdout = sys.stdout
192+
sys.stdout = val_errs
193+
odml.Section(name="sec", type=None)
194+
sys.stdout = old_stdout
195+
196+
assert "Section type undefined" in val_errs.getvalue()
197+
179198
def test_prop_string_values(self):
180199
"""
181200
Test if property values set as dtype string but could be of different dtype

0 commit comments

Comments
 (0)