Skip to content

Commit e8c622f

Browse files
committed
[test/scripts] Add odmlconvert cli args test
Added tests - for broken files - for recursive conversion
1 parent df84f4c commit e8c622f

5 files changed

Lines changed: 115 additions & 0 deletions

File tree

test/resources/scripts/odml_convert/test_broken/empty.xml

Whitespace-only changes.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="ISO-8859-1"?>
2+
<?xml-stylesheet type="text/xsl" href="odml.xsl" xmlns:odml="http://www.g-node.org/odml"?>
3+
<odML version="1">
4+
<repository>http://portal.g-node.org/odml/terminologies/v1.0/terminologies.xml</repository>
5+
<section>
6+
<type>Recording</type>
7+
<name>Recording-some-date-ah</name>
8+
<property>
9+
<name>Temperature</name>
10+
<value>24<type>float</type><unit><B0>C</unit></value>
11+
</property>
12+
</section>
13+
</odML>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<?xml-stylesheet type="text/xsl" href="odmlTerms.xsl"?>
3+
<?xml-stylesheet type="text/xsl" href="odml.xsl"?>
4+
<odML version="1">
5+
<section>
6+
<property>
7+
<value>0.0<unit>um</unit></value>
8+
<name>Depth</name>
9+
</property>
10+
<property>
11+
<value>P-unit</value>
12+
<name>CellType</name>
13+
</property>
14+
<property>
15+
<value>Nerve</value>
16+
<name>Structure</name>
17+
</property>
18+
<property>
19+
<value>0.1</value>
20+
<name>CV</name>
21+
</property>
22+
<property>
23+
<value>12.8<unit>Hz</unit></value>
24+
<name>Baseline rate</name>
25+
</property>
26+
<name>Cell</name>
27+
<type>Cell</type>
28+
</section>
29+
<author>tester</author>
30+
</odML>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<?xml-stylesheet type="text/xsl" href="odmlTerms.xsl"?>
3+
<?xml-stylesheet type="text/xsl" href="odml.xsl"?>
4+
<odML version="1">
5+
<section>
6+
<property>
7+
<value>0.0<unit>um</unit></value>
8+
<name>Depth</name>
9+
</property>
10+
<property>
11+
<value>P-unit</value>
12+
<name>CellType</name>
13+
</property>
14+
<property>
15+
<value>Nerve</value>
16+
<name>Structure</name>
17+
</property>
18+
<property>
19+
<value>0.1</value>
20+
<name>CV</name>
21+
</property>
22+
<property>
23+
<value>12.8<unit>Hz</unit></value>
24+
<name>Baseline rate</name>
25+
</property>
26+
<name>Cell</name>
27+
<type>Cell</type>
28+
</section>
29+
<author>tester</author>
30+
</odML>

test/test_script_odml_convert.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class TestScriptOdmlConvert(unittest.TestCase):
1414
def setUp(self):
1515
self.tmp_dir = util.create_test_dir(__file__)
1616
self.dir_files = os.path.join(util.TEST_RESOURCES_DIR, "scripts", "odml_convert")
17+
self.dir_broken = os.path.join(self.dir_files, "test_broken")
18+
self.dir_recursive = os.path.join(self.dir_files, "test_recursive")
1719

1820
def tearDown(self):
1921
if self.tmp_dir and os.path.exists(self.tmp_dir):
@@ -29,6 +31,25 @@ def test_script_exit(self):
2931
with self.assertRaises(SystemExit):
3032
odml_convert.main(["-h"])
3133

34+
with self.assertRaises(SystemExit):
35+
odml_convert.main(["--version"])
36+
37+
def test_broken(self):
38+
# make sure temp dir is empty
39+
self.assertListEqual(os.listdir(self.tmp_dir), [])
40+
41+
# run converter on directory with invalid files
42+
odml_convert.main(["-o", self.tmp_dir, self.dir_broken])
43+
44+
# make sure an output directory has been created
45+
out_dir_lst = os.listdir(self.tmp_dir)
46+
self.assertEqual(len(out_dir_lst), 1)
47+
out_dir = os.path.join(self.tmp_dir, out_dir_lst[0])
48+
self.assertTrue(os.path.isdir(out_dir))
49+
50+
# make sure no file has been created
51+
self.assertListEqual(os.listdir(out_dir), [])
52+
3253
def test_valid_conversion(self):
3354
# make sure temp dir is empty
3455
self.assertListEqual(os.listdir(self.tmp_dir), [])
@@ -49,3 +70,24 @@ def test_valid_conversion(self):
4970
# make sure the files are valid odml files
5071
_ = odml_load(os.path.join(out_dir, file_lst[0]))
5172
_ = odml_load(os.path.join(out_dir, file_lst[1]))
73+
74+
def test_recursive_conversion(self):
75+
# make sure temp dir is empty
76+
self.assertListEqual(os.listdir(self.tmp_dir), [])
77+
78+
# run converter on root directory containing two files
79+
odml_convert.main(["-r", "-o", self.tmp_dir, self.dir_recursive])
80+
81+
# make sure an output directory has been created
82+
out_dir_lst = os.listdir(self.tmp_dir)
83+
self.assertEqual(len(out_dir_lst), 1)
84+
out_dir = os.path.join(self.tmp_dir, out_dir_lst[0])
85+
self.assertTrue(os.path.isdir(out_dir))
86+
87+
# make sure two files have been created
88+
file_lst = os.listdir(out_dir)
89+
self.assertEqual(len(file_lst), 2)
90+
91+
# make sure the files are valid odml files
92+
_ = odml_load(os.path.join(out_dir, file_lst[0]))
93+
_ = odml_load(os.path.join(out_dir, file_lst[1]))

0 commit comments

Comments
 (0)