forked from G-Node/python-odml
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_parser_yaml.py
More file actions
48 lines (32 loc) · 1.47 KB
/
Copy pathtest_parser_yaml.py
File metadata and controls
48 lines (32 loc) · 1.47 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
import os
import unittest
import yaml
from odml.tools import dict_parser
from odml.tools.parser_utils import ParserException, InvalidVersionException
class TestYAMLParser(unittest.TestCase):
def setUp(self):
dir_path = os.path.dirname(os.path.realpath(__file__))
self.basepath = os.path.join(dir_path, "resources")
self.yaml_reader = dict_parser.DictReader()
def test_missing_root(self):
filename = "missing_root.yaml"
message = "Missing root element"
with open(os.path.join(self.basepath, filename)) as raw_data:
parsed_doc = yaml.safe_load(raw_data)
with self.assertRaises(ParserException) as exc:
_ = self.yaml_reader.to_odml(parsed_doc)
self.assertIn(message, str(exc.exception))
def test_missing_version(self):
filename = "missing_version.yaml"
message = "Could not find odml-version"
with open(os.path.join(self.basepath, filename)) as raw_data:
parsed_doc = yaml.safe_load(raw_data)
with self.assertRaises(ParserException) as exc:
_ = self.yaml_reader.to_odml(parsed_doc)
self.assertIn(message, str(exc.exception))
def test_invalid_version(self):
filename = "invalid_version.yaml"
with open(os.path.join(self.basepath, filename)) as raw_data:
parsed_doc = yaml.safe_load(raw_data)
with self.assertRaises(InvalidVersionException):
_ = self.yaml_reader.to_odml(parsed_doc)