Repository: NeuralEnsemble/python-neo

Issue:
neo.get_io fails on file yet to be written
**Describe the bug**
Calling neo.get_io no longer works with the name of a file yet to be written
which means it can no longer be uses before a 
io.write(... call

**To Reproduce**
import neo
neo.get_io("tobewritten.pkl")


**Expected behaviour**
return an io

**Environment:**
 - OS: [e.g. macOS, Linux, Windows]
 i think all but found with linux
 - Python version
 found with 3.11
 - Neo version
0.12.0
Worked in neo 0.10
 - 
 - NumPy version
not relevant

**Additional context**
our workaround is
def get_neo_io(file_or_folder):
    try:
        return neo.get_io(file_or_folder)
    except ValueError as ex:
        # As neo.get_io only works with existinf files
        _, suffix = os.path.splitext(file_or_folder)
        suffix = suffix[1:].lower()
        if suffix in neo.io_by_extension:
            writer_list = neo.io_by_extension[suffix]
            return writer_list[0](file_or_folder)



Comments:

Patch:
diff --git a/neo/io/__init__.py b/neo/io/__init__.py
index 22b6df66..4aa31692 100644
--- a/neo/io/__init__.py
+++ b/neo/io/__init__.py
@@ -451,8 +451,23 @@ def list_candidate_ios(file_or_folder, ignore_patterns=['*.ini', 'README.txt', '
     # if only file prefix was provided, e.g /mydatafolder/session1-
     # to select all files sharing the `session1-` prefix
     elif file_or_folder.parent.exists():
-        filenames = file_or_folder.parent.glob(file_or_folder.name + '*')
-
+        filenames = list(file_or_folder.parent.glob(file_or_folder.name + '*'))
+        # if filenames empty and suffix is provided then non-existent file
+        # may be written in current dir. So run check for io
+        if len(filenames)==0 and file_or_folder.suffix:
+            suffix = file_or_folder.suffix[1:].lower()
+            if suffix not in io_by_extension:
+                raise ValueError(f'{suffix} is not a supported format of any IO.')
+            return io_by_extension[suffix]
+
+    # If non-existent file in non-existent dir is given check if this 
+    # structure could be created with an io writing the file
+    elif file_or_folder.suffix:
+        suffix = file_or_folder.suffix[1:].lower()
+        if suffix not in io_by_extension:
+            raise ValueError(f'{suffix} is not a supported format of any IO.')
+        return io_by_extension[suffix]
+    
     else:
         raise ValueError(f'{file_or_folder} does not contain data files of a supported format')
 


Test patch:
diff --git a/neo/test/iotest/test_get_io.py b/neo/test/iotest/test_get_io.py
new file mode 100644
index 00000000..b43499b0
--- /dev/null
+++ b/neo/test/iotest/test_get_io.py
@@ -0,0 +1,41 @@
+from pathlib import Path
+from tempfile import TemporaryDirectory
+from neo.io import get_io, list_candidate_ios, NixIO
+
+
+def test_list_candidate_ios_non_existant_file():
+    # use plexon io suffix for testing here
+    non_existant_file = Path('non_existant_folder/non_existant_file.plx')
+    non_existant_file.unlink(missing_ok=True)
+    ios = list_candidate_ios(non_existant_file)
+
+    assert ios
+
+    # cleanup
+    non_existant_file.unlink(missing_ok=True)
+
+
+def test_list_candidate_ios_filename_stub():
+    # create dummy folder with dummy files
+    with TemporaryDirectory(prefix='filename_stub_test_') as test_folder:
+        test_folder = Path(test_folder)
+        test_filename = (test_folder / 'dummy_file.nix')
+        test_filename.touch()
+        filename_stub = test_filename.with_suffix('')
+
+        # check that io is found even though file suffix was not provided
+        ios = list_candidate_ios(filename_stub)
+
+        assert NixIO in ios
+
+
+def test_get_io_non_existant_file_writable_io():
+    # use nixio for testing with writable io
+    non_existant_file = Path('non_existant_file.nix')
+    non_existant_file.unlink(missing_ok=True)
+    io = get_io(non_existant_file)
+
+    assert isinstance(io, NixIO)
+
+    # cleanup
+    non_existant_file.unlink(missing_ok=True)