Skip to content

Commit

Permalink
test(io): test confirm_file_type
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjayankur31 committed Nov 6, 2024
1 parent 302d22c commit b01fcbf
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions tests/test_io.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env python3
"""
Tests for io methods
File: tests/test_io.py
Copyright 2024 NeuroML contributors
"""

import logging
import os

from pyneuroml.errors import NMLFileTypeError
from pyneuroml.io import confirm_file_type

from . import BaseTestCase

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)


class TestIo(BaseTestCase):
"""Test io module"""

def test_confirm_file_type(self):
"""Test confirm_file_type method."""

# LEMS file with xml extension
test_lems_file = "a_test_lems_file.xml"
with open(test_lems_file, "w") as f:
print("<LEMS> </LEMS>", file=f)
confirm_file_type(test_lems_file, ["xml"])

# lems file with non xml extension but provided tag
test_lems_file2 = "a_test_lems_file.lems"
with open(test_lems_file2, "w") as f:
print("<LEMS> </LEMS>", file=f)

confirm_file_type(test_lems_file2, ["xml"], "lems")

# lems file with non xml and bad tag: should fail
with self.assertRaises(NMLFileTypeError):
test_lems_file3 = "a_bad_test_lems_file.lems"
with open(test_lems_file3, "w") as f:
print("<LAMS> </LAMS>", file=f)

confirm_file_type(test_lems_file3, ["xml"], "lems")

os.unlink(test_lems_file)
os.unlink(test_lems_file2)
os.unlink(test_lems_file3)

0 comments on commit b01fcbf

Please sign in to comment.