1- import unittest
1+ """
2+ This file tests proper saving and loading of odML Documents
3+ with all supported odML parsers via the tools.odmlparser classes.
4+ """
5+
26import os
7+ import shutil
8+ import tempfile
9+ import unittest
10+
311from odml .tools import odmlparser
412
513
614class TestOdmlParser (unittest .TestCase ):
715
816 def setUp (self ):
17+ # Set up test environment
18+ self .tmp_dir = tempfile .mkdtemp (suffix = ".odml" )
19+
920 self .basepath = 'doc/example_odMLs/'
1021 self .basefile = 'doc/example_odMLs/THGTTG.odml'
1122
12- self .xml_file = 'doc/example_odMLs/THGTTG_xml.odml'
13- self .yaml_file = 'doc/example_odMLs/THGTTG_yaml.odml'
14- self .json_file = 'doc/example_odMLs/THGTTG_json.odml'
23+ self .json_file = os . path . join ( self . tmp_dir , "test.json" )
24+ self .xml_file = os . path . join ( self . tmp_dir , "test.xml" )
25+ self .yaml_file = os . path . join ( self . tmp_dir , "test.yaml" )
1526
1627 self .xml_reader = odmlparser .ODMLReader (parser = 'XML' )
1728 self .yaml_reader = odmlparser .ODMLReader (parser = 'YAML' )
@@ -24,14 +35,8 @@ def setUp(self):
2435 self .odml_doc = self .xml_reader .from_file (self .basefile )
2536
2637 def tearDown (self ):
27- if os .path .exists (self .xml_file ):
28- os .remove (self .xml_file )
29-
30- if os .path .exists (self .yaml_file ):
31- os .remove (self .yaml_file )
32-
33- if os .path .exists (self .json_file ):
34- os .remove (self .json_file )
38+ if os .path .exists (self .tmp_dir ):
39+ shutil .rmtree (self .tmp_dir )
3540
3641 def test_xml (self ):
3742 self .xml_writer .write_file (self .odml_doc , self .xml_file )
0 commit comments