Skip to content

Commit a0c4b08

Browse files
committed
[test/parser_yaml] Add prepare file func
1 parent bbfe0bc commit a0c4b08

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

test/test_parser_yaml.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1+
"""
2+
This module supplies basic tests for the odml.dict_parser.DictReader
3+
reading from yaml files.
4+
"""
5+
16
import os
7+
import tempfile
28
import unittest
39
import yaml
410

@@ -14,6 +20,25 @@ def setUp(self):
1420

1521
self.yaml_reader = dict_parser.DictReader()
1622

23+
dir_name = "odml_%s" % os.path.basename(os.path.splitext(__file__)[0])
24+
tmp_dir_path = os.path.join(tempfile.gettempdir(), dir_name)
25+
26+
if not os.path.exists(tmp_dir_path):
27+
os.mkdir(tmp_dir_path)
28+
29+
self.tmp_dir_path = tmp_dir_path
30+
31+
def _prepare_doc(self, file_name, file_content):
32+
file_path = os.path.join(self.tmp_dir_path, file_name)
33+
34+
with open(file_path, "w") as dump_file:
35+
dump_file.write(file_content)
36+
37+
with open(file_path) as raw_data:
38+
parsed_doc = yaml.safe_load(raw_data)
39+
40+
return parsed_doc
41+
1742
def test_missing_root(self):
1843
filename = "missing_root.yaml"
1944
message = "Missing root element"

0 commit comments

Comments
 (0)