Skip to content

Commit a11dd14

Browse files
committed
[tests] Add basic XMLWriter tests
1 parent cf1ea53 commit a11dd14

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

test/test_xml_writer.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import os
2+
import shutil
3+
import tempfile
4+
import unittest
5+
6+
import odml
7+
8+
from odml.tools.xmlparser import XML_HEADER, EXTERNAL_STYLE_HEADER, \
9+
INFILE_STYLE_HEADER, INFILE_STYLE_TEMPLATE
10+
from odml.tools import XMLWriter
11+
12+
13+
class TestXMLWriter(unittest.TestCase):
14+
def setUp(self):
15+
# Set up test environment
16+
dir_path = os.path.dirname(os.path.realpath(__file__))
17+
18+
self.xmlfile = os.path.join(dir_path, "resources", "version_conversion_int.xml")
19+
20+
self.tmp_dir = tempfile.mkdtemp(suffix=".odml")
21+
self.outfile = os.path.join(self.tmp_dir, "xml_writer.xml")
22+
23+
doc = odml.Document()
24+
sec = doc.create_section(name="sec", type="test")
25+
_ = sec.create_property(name="prop", value=['a', 'b', 'c'])
26+
27+
self.doc = doc
28+
self.writer = XMLWriter(doc)
29+
30+
def tearDown(self):
31+
if os.path.exists(self.tmp_dir):
32+
shutil.rmtree(self.tmp_dir)
33+
34+
def test_write_default(self):
35+
self.writer.write_file(self.outfile)
36+
37+
# make sure the file can be read again without errors
38+
doc = odml.load(self.outfile)
39+
self.assertEqual(doc, self.doc)
40+
41+
def test_write_style_default(self):
42+
self.writer.write_file(self.outfile, local_style=True)
43+
44+
# make sure the file can be read again without errors
45+
doc = odml.load(self.outfile)
46+
self.assertEqual(doc, self.doc)
47+
48+
def test_write_style_custom(self):
49+
# template stub just to see if its written properly; will not render anything
50+
cust_tmpl = "<xsl:template></xsl:template>"
51+
52+
self.writer.write_file(self.outfile, local_style=True, custom_template=cust_tmpl)
53+
54+
# make sure the file can be read again without errors
55+
doc = odml.load(self.outfile)
56+
self.assertEqual(doc, self.doc)
57+
58+
# test second possible way to save
59+
self.writer.write_file(self.outfile, local_style=False, custom_template=cust_tmpl)
60+
61+
# make sure the file can be read again without errors
62+
doc = odml.load(self.outfile)
63+
self.assertEqual(doc, self.doc)

0 commit comments

Comments
 (0)