Skip to content

Commit f37a83f

Browse files
committed
Add true unit tests
1 parent 9f5a5e8 commit f37a83f

File tree

13 files changed

+833
-223
lines changed

13 files changed

+833
-223
lines changed

conda/dev.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ dependencies:
1010
- six=1.16.0
1111
- globus-sdk=3.2.1
1212
- fair-research-login=0.2.6
13+
# Testing
14+
# =======================
15+
- pytest
16+
- pytest-cov
1317
# Developer Tools
1418
# =================
1519
# If versions are updated, also update 'rev' in `.pre-commit.config.yaml`

tests/test_functions.py

Lines changed: 0 additions & 69 deletions
This file was deleted.

tests_unit/test_chgrp.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from zstash.chgrp import setup_chgrp
2+
3+
4+
def test_setup_chgrp():
5+
args_str = "zstash chgrp 775 my_path".split(" ")
6+
args = setup_chgrp(args_str)
7+
assert args.group == "775"
8+
assert args.hpss == "my_path"
9+
assert args.R is None
10+
assert args.verbose is False
11+
12+
args_str = "zstash chgrp 775 my_path -R".split(" ")
13+
args = setup_chgrp(args_str)
14+
assert args.group == "775"
15+
assert args.hpss == "my_path"
16+
assert args.R is True
17+
assert args.verbose is False
18+
19+
args_str = "zstash chgrp 775 my_path -v".split(" ")
20+
args = setup_chgrp(args_str)
21+
assert args.group == "775"
22+
assert args.hpss == "my_path"
23+
assert args.R is None
24+
assert args.verbose is True
25+
26+
args_str = "zstash chgrp 775 my_path -R -v".split(" ")
27+
args = setup_chgrp(args_str)
28+
assert args.group == "775"
29+
assert args.hpss == "my_path"
30+
assert args.R is True
31+
assert args.verbose is True

tests_unit/test_create.py

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
from zstash.create import setup_create
2+
from zstash.utils import CommandInfo, HPSSType
3+
4+
5+
def test_setup_create():
6+
# Test required parameters
7+
args_str = "zstash create dir_to_archive --hpss=none".split(" ")
8+
command_info = CommandInfo("create")
9+
args = setup_create(command_info, args_str)
10+
assert args.path == "dir_to_archive"
11+
assert args.hpss == "none"
12+
assert args.include is None
13+
assert args.exclude is None
14+
assert args.maxsize == 256
15+
assert args.keep is True
16+
assert args.cache is None
17+
assert args.non_blocking is False
18+
assert args.verbose is False
19+
assert args.no_tars_md5 is False
20+
assert args.follow_symlinks is False
21+
assert command_info.cache_dir == "zstash"
22+
assert command_info.keep is True
23+
assert command_info.config.path.endswith("dir_to_archive")
24+
assert command_info.dir_to_archive_relative == "dir_to_archive"
25+
assert command_info.config.maxsize == 274877906944
26+
assert command_info.config.hpss == "none"
27+
assert command_info.hpss_type == HPSSType.NO_HPSS
28+
29+
args_str = "zstash create dir_to_archive --hpss=my_path".split(" ")
30+
command_info = CommandInfo("create")
31+
args = setup_create(command_info, args_str)
32+
assert args.hpss == "my_path"
33+
assert args.keep is False
34+
assert command_info.keep is False
35+
assert command_info.config.hpss == "my_path"
36+
assert command_info.hpss_type == HPSSType.SAME_MACHINE_HPSS
37+
38+
args_str = "zstash create dir_to_archive --hpss=globus://my_path".split(" ")
39+
command_info = CommandInfo("create")
40+
args = setup_create(command_info, args_str)
41+
assert args.hpss == "globus://my_path"
42+
assert args.keep is False
43+
assert command_info.keep is False
44+
assert command_info.config.hpss == "globus://my_path"
45+
assert command_info.hpss_type == HPSSType.GLOBUS
46+
assert command_info.globus_info.hpss_path == "globus://my_path"
47+
48+
# Test required parameters, with --keep
49+
args_str = "zstash create dir_to_archive --hpss=none --keep".split(" ")
50+
command_info = CommandInfo("create")
51+
args = setup_create(command_info, args_str)
52+
assert args.keep is True
53+
assert command_info.keep is True
54+
55+
args_str = "zstash create dir_to_archive --hpss=my_path --keep".split(" ")
56+
command_info = CommandInfo("create")
57+
args = setup_create(command_info, args_str)
58+
assert args.keep is True
59+
assert command_info.keep is True
60+
61+
args_str = "zstash create dir_to_archive --hpss=globus://my_path --keep".split(" ")
62+
command_info = CommandInfo("create")
63+
args = setup_create(command_info, args_str)
64+
assert args.keep is True
65+
assert command_info.keep is True
66+
67+
# Test optional parameters
68+
args_str = "zstash create dir_to_archive --hpss=none --include=file1.txt,file2.txt,file3.txt".split(
69+
" "
70+
)
71+
command_info = CommandInfo("create")
72+
args = setup_create(command_info, args_str)
73+
assert args.include == "file1.txt,file2.txt,file3.txt"
74+
assert args.exclude is None
75+
76+
args_str = "zstash create dir_to_archive --hpss=none --exclude=file1.txt,file2.txt,file3.txt".split(
77+
" "
78+
)
79+
command_info = CommandInfo("create")
80+
args = setup_create(command_info, args_str)
81+
assert args.include is None
82+
assert args.exclude == "file1.txt,file2.txt,file3.txt"
83+
84+
args_str = "zstash create dir_to_archive --hpss=none --include=file1.txt,file2.txt --exclude=file3.txt,file4.txt".split(
85+
" "
86+
)
87+
command_info = CommandInfo("create")
88+
args = setup_create(command_info, args_str)
89+
assert args.include == "file1.txt,file2.txt"
90+
assert args.exclude == "file3.txt,file4.txt"
91+
92+
args_str = "zstash create dir_to_archive --hpss=none --maxsize=1024".split(" ")
93+
command_info = CommandInfo("create")
94+
args = setup_create(command_info, args_str)
95+
assert args.maxsize == 1024
96+
assert command_info.config.maxsize == 1024**4
97+
98+
args_str = "zstash create dir_to_archive --hpss=none --cache=my_cache".split(" ")
99+
command_info = CommandInfo("create")
100+
args = setup_create(command_info, args_str)
101+
assert args.cache == "my_cache"
102+
assert command_info.cache_dir == "my_cache"
103+
104+
args_str = "zstash create dir_to_archive --hpss=none --non-blocking".split(" ")
105+
command_info = CommandInfo("create")
106+
args = setup_create(command_info, args_str)
107+
assert args.non_blocking is True
108+
109+
args_str = "zstash create dir_to_archive --hpss=none --verbose".split(" ")
110+
command_info = CommandInfo("create")
111+
args = setup_create(command_info, args_str)
112+
assert args.verbose is True
113+
114+
args_str = "zstash create dir_to_archive --hpss=none --no_tars_md5".split(" ")
115+
command_info = CommandInfo("create")
116+
args = setup_create(command_info, args_str)
117+
assert args.no_tars_md5 is True
118+
119+
args_str = "zstash create dir_to_archive --hpss=none --follow-symlinks".split(" ")
120+
command_info = CommandInfo("create")
121+
args = setup_create(command_info, args_str)
122+
assert args.follow_symlinks is True

0 commit comments

Comments
 (0)