Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion neo/rawio/tdtrawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ def __init__(self, dirname="", sortname=""):
"""
BaseRawIO.__init__(self)
dirname = Path(dirname)
if dirname.is_dir():
tsq_files = [f for f in dirname.iterdir() if f.suffix.lower() == ".tsq"] if dirname.is_dir() else []
if dirname.is_dir() and is_tdtblock(dirname) and len(tsq_files) == 1:
# the directory is itself a single block, not a tank of blocks
self.dirname = tsq_files[0].with_suffix("")
self.tdt_block_mode = "single"
elif dirname.is_dir():
self.dirname = Path(dirname)
self.tdt_block_mode = "multi"
elif dirname.is_file():
Expand Down
16 changes: 16 additions & 0 deletions neo/test/rawiotest/test_tdtrawio.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import tempfile
import unittest
from pathlib import Path
from numpy.testing import assert_array_equal, assert_
Expand Down Expand Up @@ -62,5 +63,20 @@ def test_compare_load_multi_single_block(self):
)


class TestTdtRawIOBlockDirectory(unittest.TestCase):
def test_block_directory_is_single_block(self):
# a directory holding the files of one block (no sub-block folders), see issue 1970
with tempfile.TemporaryDirectory() as tmp:
block = Path(tmp) / "recording_name"
block.mkdir()
for ext in ("Tbk", "Tdx", "tev", "tsq"):
(block / f"recording_name.{ext}").touch()

rawio = TdtRawIO(block)

self.assertEqual(rawio.tdt_block_mode, "single")
self.assertEqual(rawio.dirname, block / "recording_name")


if __name__ == "__main__":
unittest.main()