Repository: dandi/dandi-cli

Issue:
remove POSIX filenames assumptions in the tests
This is a follow up to https://github.com/dandi/dandi-cli/pull/210
where I did that in `test_upload`.  So the goal is to check other tests and provide the same (or similar?) changes in other test files.

Comments:

Patch:
diff --git a/dandi/cli/cmd_ls.py b/dandi/cli/cmd_ls.py
index 4d2c2c95..89c50d5c 100644
--- a/dandi/cli/cmd_ls.py
+++ b/dandi/cli/cmd_ls.py
@@ -68,7 +68,7 @@ def ls(paths, fields=None, format="auto", recursive=False):
 
     # For now we support only individual files
     if recursive:
-        files = list(find_files(".nwb$", paths))
+        files = list(find_files(r"\.nwb\Z", paths))
     else:
         files = paths
 
diff --git a/dandi/cli/cmd_organize.py b/dandi/cli/cmd_organize.py
index 9b0c0037..06e07ac2 100644
--- a/dandi/cli/cmd_organize.py
+++ b/dandi/cli/cmd_organize.py
@@ -151,7 +151,7 @@ def organize(
         # Our dumps of metadata
         metadata = load_jsonl(paths[0])
     else:
-        paths = list(find_files(r"\.nwb$", paths=paths))
+        paths = list(find_files(r"\.nwb\Z", paths=paths))
         lgr.info("Loading metadata from %d files", len(paths))
         # Done here so we could still reuse cached 'get_metadata'
         # without having two types of invocation and to guard against
diff --git a/dandi/cli/command.py b/dandi/cli/command.py
index 71cc8261..28ee656c 100644
--- a/dandi/cli/command.py
+++ b/dandi/cli/command.py
@@ -106,9 +106,7 @@ from .cmd_download import download  # noqa: E402
 from .cmd_validate import validate  # noqa: E402
 from .cmd_register import register  # noqa: E402
 
-main.add_command(ls)
-main.add_command(organize)
-main.add_command(upload)
-main.add_command(download)
-main.add_command(validate)
-main.add_command(register)
+__all_commands__ = (ls, organize, upload, download, validate, register)
+
+for cmd in __all_commands__:
+    main.add_command(cmd)
diff --git a/dandi/utils.py b/dandi/utils.py
index d0e0e317..baa8cde7 100644
--- a/dandi/utils.py
+++ b/dandi/utils.py
@@ -360,7 +360,8 @@ def move_file(src, dst):
 def find_dandi_files(paths):
     """Adapter to find_files to find files of interest to dandi project
     """
-    yield from find_files(r"(dandiset\.yaml|\.nwb)$", paths)
+    sep = re.escape(os.sep)
+    yield from find_files(rf"((^|{sep})dandiset\.yaml|\.nwb)\Z", paths)
 
 
 def find_parent_directory_containing(filename, path=None):


Test patch:
diff --git a/dandi/cli/tests/test_command.py b/dandi/cli/tests/test_command.py
index f16fd323..6721c0b0 100644
--- a/dandi/cli/tests/test_command.py
+++ b/dandi/cli/tests/test_command.py
@@ -1,11 +1,12 @@
+import os
+import re
 import sys
 from subprocess import Popen, PIPE
 
-from ..command import ls, validate
+from ..command import ls, validate, __all_commands__
 
 from click.testing import CliRunner
 import pytest
-import os
 
 
 @pytest.mark.parametrize("command", (ls, validate))
@@ -24,6 +25,16 @@ def test_smoke(simple2_nwb, command):
     assert r.exit_code == 0, f"Exited abnormally. out={r.stdout}"
 
 
+@pytest.mark.parametrize("command", __all_commands__)
+def test_smoke_help(command):
+    runner = CliRunner()
+    r = runner.invoke(command, ["--help"])
+    assert r.exit_code == 0, f"Exited abnormally. out={r.stdout}"
+    assert r.stdout, "There were no output whatsoever"
+
+    assert re.match("Usage: .*Options:.*--help", r.stdout, flags=re.DOTALL) is not None
+
+
 def test_no_heavy_imports():
     # Timing --version for being fast is unreliable, so we will verify that
     # no h5py or numpy (just in case) module is imported upon import of the
diff --git a/dandi/tests/test_organize.py b/dandi/tests/test_organize.py
index 19281434..e8377cb2 100644
--- a/dandi/tests/test_organize.py
+++ b/dandi/tests/test_organize.py
@@ -131,7 +131,7 @@ def test_organize_nwb_test_data(nwb_test_data, tmpdir, clirunner, mode):
     # this beast doesn't capture our logs ATM so cannot check anything there.
     # At the end we endup only with dandiset.yaml and a single file
     produced_paths = sorted(find_files(".*", paths=outdir))
-    produced_nwb_paths = sorted(find_files(".nwb$", paths=outdir))
+    produced_nwb_paths = sorted(find_files(r"\.nwb\Z", paths=outdir))
     produced_relpaths = [op.relpath(p, outdir) for p in produced_paths]
     if mode == "dry":
         assert produced_relpaths == []
diff --git a/dandi/tests/test_upload.py b/dandi/tests/test_upload.py
index addfcf6b..e7a3163e 100644
--- a/dandi/tests/test_upload.py
+++ b/dandi/tests/test_upload.py
@@ -1,3 +1,4 @@
+import os
 import pytest
 
 from .. import girder
@@ -8,7 +9,7 @@ from ..utils import yaml_load
 
 
 def test_upload(local_docker_compose_env, monkeypatch, organized_nwb_dir2):
-    nwb_files = list(organized_nwb_dir2.glob("*/*.nwb"))
+    nwb_files = list(organized_nwb_dir2.glob(f"*{os.sep}*.nwb"))
     assert len(nwb_files) == 2
     dirname1 = nwb_files[0].parent.name
     filename1 = nwb_files[0].name
@@ -43,7 +44,7 @@ def test_upload(local_docker_compose_env, monkeypatch, organized_nwb_dir2):
 def test_upload_existing_error(
     local_docker_compose_env, monkeypatch, organized_nwb_dir
 ):
-    nwb_file, = organized_nwb_dir.glob("*/*.nwb")
+    nwb_file, = organized_nwb_dir.glob(f"*{os.sep}*.nwb")
     dirname = nwb_file.parent.name
     dandi_instance_id = local_docker_compose_env["instance_id"]
     register(
@@ -69,7 +70,7 @@ def test_upload_existing_error(
 
 
 def test_upload_locks(local_docker_compose_env, mocker, monkeypatch, organized_nwb_dir):
-    nwb_file, = organized_nwb_dir.glob("*/*.nwb")
+    nwb_file, = organized_nwb_dir.glob(f"*{os.sep}*.nwb")
     dirname = nwb_file.parent.name
     dandi_instance_id = local_docker_compose_env["instance_id"]
     register(
@@ -92,7 +93,7 @@ def test_upload_locks(local_docker_compose_env, mocker, monkeypatch, organized_n
 
 
 def test_upload_unregistered(local_docker_compose_env, monkeypatch, organized_nwb_dir):
-    nwb_file, = organized_nwb_dir.glob("*/*.nwb")
+    nwb_file, = organized_nwb_dir.glob(f"*{os.sep}*.nwb")
     dirname = nwb_file.parent.name
     dandi_instance_id = local_docker_compose_env["instance_id"]
     (organized_nwb_dir / dandiset_metadata_file).write_text("identifier: '999999'\n")