File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44import pytest
55
66import bids2table ._indexing as indexing
7+ from bids2table ._pathlib import cloudpathlib_is_available
78
89BIDS_EXAMPLES = Path (__file__ ).parents [1 ] / "bids-examples"
910
@@ -54,6 +55,16 @@ def test_index_dataset(root: str, expected_count: int):
5455 assert len (table ) == expected_count
5556
5657
58+ @pytest .mark .skipif (
59+ not cloudpathlib_is_available (), reason = "cloudpathlib not installed"
60+ )
61+ def test_index_dataset_s3 ():
62+ root = "s3://openneuro.org/ds000102"
63+ expected_count = 130
64+ table = indexing .index_dataset (root )
65+ assert len (table ) == expected_count
66+
67+
5768@pytest .mark .parametrize ("max_workers" , [0 , 2 ])
5869def test_index_dataset_parallel (max_workers : int ):
5970 root , expected_count = "ds102" , 130
Original file line number Diff line number Diff line change 1+ import shlex
2+ import sys
3+ from contextlib import contextmanager
4+ from pathlib import Path
5+ from typing import List
6+
7+ import pytest
8+
9+ from bids2table import __main__ as cli
10+
11+ BIDS_EXAMPLES = Path (__file__ ).parents [1 ] / "bids-examples"
12+
13+ COMMANDS = [
14+ "find {examples}" ,
15+ "index -o {out_dir}/ds102.parquet {examples}/ds102" ,
16+ "index -o {out_dir}/ds101_ds102.parquet {examples}/ds101 {examples}/ds102" ,
17+ "index -o {out_dir}/ds10N.parquet '{examples}/ds10?'" ,
18+ ]
19+
20+
21+ @contextmanager
22+ def patch_argv (argv : List [str ]):
23+ old_argv = sys .argv
24+ try :
25+ sys .argv = argv .copy ()
26+ yield
27+ finally :
28+ sys .argv = old_argv
29+
30+
31+ @pytest .mark .parametrize (
32+ "cmd,output" ,
33+ [
34+ ("find {examples}" , None ),
35+ ("index -o {out_dir}/ds102.parquet {examples}/ds102" , "ds102.parquet" ),
36+ (
37+ "index -o {out_dir}/ds101_ds102.parquet {examples}/ds101 {examples}/ds102" ,
38+ "ds101_ds102.parquet" ,
39+ ),
40+ ("index -o {out_dir}/ds10N.parquet '{examples}/ds10?'" , "ds10N.parquet" ),
41+ ],
42+ )
43+ def test_main (cmd : str , output : str | None , tmp_path : Path ):
44+ cmd_fmt = cmd .format (out_dir = tmp_path , examples = BIDS_EXAMPLES )
45+ prog = str (Path (cli .__file__ ).absolute ())
46+ argv = [prog ] + shlex .split (cmd_fmt )
47+ with patch_argv (argv ):
48+ cli .main ()
49+
50+ if output :
51+ assert (tmp_path / output ).exists ()
You can’t perform that action at this time.
0 commit comments