Skip to content

Commit b01fcbf

Browse files
committed
test(io): test confirm_file_type
1 parent 302d22c commit b01fcbf

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

tests/test_io.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Tests for io methods
4+
5+
File: tests/test_io.py
6+
7+
Copyright 2024 NeuroML contributors
8+
"""
9+
10+
import logging
11+
import os
12+
13+
from pyneuroml.errors import NMLFileTypeError
14+
from pyneuroml.io import confirm_file_type
15+
16+
from . import BaseTestCase
17+
18+
logger = logging.getLogger(__name__)
19+
logger.setLevel(logging.DEBUG)
20+
21+
22+
class TestIo(BaseTestCase):
23+
"""Test io module"""
24+
25+
def test_confirm_file_type(self):
26+
"""Test confirm_file_type method."""
27+
28+
# LEMS file with xml extension
29+
test_lems_file = "a_test_lems_file.xml"
30+
with open(test_lems_file, "w") as f:
31+
print("<LEMS> </LEMS>", file=f)
32+
confirm_file_type(test_lems_file, ["xml"])
33+
34+
# lems file with non xml extension but provided tag
35+
test_lems_file2 = "a_test_lems_file.lems"
36+
with open(test_lems_file2, "w") as f:
37+
print("<LEMS> </LEMS>", file=f)
38+
39+
confirm_file_type(test_lems_file2, ["xml"], "lems")
40+
41+
# lems file with non xml and bad tag: should fail
42+
with self.assertRaises(NMLFileTypeError):
43+
test_lems_file3 = "a_bad_test_lems_file.lems"
44+
with open(test_lems_file3, "w") as f:
45+
print("<LAMS> </LAMS>", file=f)
46+
47+
confirm_file_type(test_lems_file3, ["xml"], "lems")
48+
49+
os.unlink(test_lems_file)
50+
os.unlink(test_lems_file2)
51+
os.unlink(test_lems_file3)

0 commit comments

Comments
 (0)