-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest_parameterparsing.py
91 lines (73 loc) · 3.19 KB
/
test_parameterparsing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import snykjar
def test_arg_parsing_works_for_single_dot():
cl_args = ['.']
args = snykjar.parse_command_line_args(cl_args)
assert len(args.jar_path) == 1
assert args.jar_path[0] == '.'
cl_args = ['--orgId=123', '.']
args = snykjar.parse_command_line_args(cl_args)
assert args.orgId == '123'
assert len(args.jar_path) == 1
assert args.jar_path[0] == '.'
def test_arg_parsing_works_for_single_directory():
cl_args = ['/Users/foo/some/directory']
args = snykjar.parse_command_line_args(cl_args)
assert len(args.jar_path) == 1
assert args.jar_path[0] == '/Users/foo/some/directory'
cl_args = ['--orgId=123', '/Users/foo/some/directory']
args = snykjar.parse_command_line_args(cl_args)
assert args.orgId == '123'
assert len(args.jar_path) == 1
assert args.jar_path[0] == '/Users/foo/some/directory'
def test_arg_parsing_works_for_single_jar():
cl_args = ['somejar.jar']
args = snykjar.parse_command_line_args(cl_args)
assert len(args.jar_path) == 1
assert args.jar_path[0] == 'somejar.jar'
cl_args = ['./somejar.jar']
args = snykjar.parse_command_line_args(cl_args)
assert len(args.jar_path) == 1
assert args.jar_path[0] == './somejar.jar'
cl_args = ['/some/fully/qualified/path/somejar.jar']
args = snykjar.parse_command_line_args(cl_args)
assert len(args.jar_path) == 1
assert args.jar_path[0] == '/some/fully/qualified/path/somejar.jar'
# Now with --orgId
cl_args = ['--orgId=123', 'somejar.jar']
args = snykjar.parse_command_line_args(cl_args)
assert args.orgId == '123'
assert len(args.jar_path) == 1
assert args.jar_path[0] == 'somejar.jar'
cl_args = ['--orgId=123', './somejar.jar']
args = snykjar.parse_command_line_args(cl_args)
assert args.orgId == '123'
assert len(args.jar_path) == 1
assert args.jar_path[0] == './somejar.jar'
cl_args = ['--orgId=123', '/some/fully/qualified/path/somejar.jar']
args = snykjar.parse_command_line_args(cl_args)
assert args.orgId == '123'
assert len(args.jar_path) == 1
assert args.jar_path[0] == '/some/fully/qualified/path/somejar.jar'
def test_arg_parsing_handles_multiple_jars():
cl_args = ['somejar1.jar', 'somejar2.jar', 'somejar3.jar']
args = snykjar.parse_command_line_args(cl_args)
assert len(args.jar_path) == 3
assert args.jar_path[0] == cl_args[0]
assert args.jar_path[1] == cl_args[1]
assert args.jar_path[2] == cl_args[2]
# Now with --orgId
cl_args = ['--orgId=123', 'somejar1.jar', 'somejar2.jar', 'somejar3.jar']
args = snykjar.parse_command_line_args(cl_args)
assert args.orgId == '123'
assert len(args.jar_path) == 3
assert args.jar_path[0] == 'somejar1.jar'
assert args.jar_path[1] == 'somejar2.jar'
assert args.jar_path[2] == 'somejar3.jar'
def test_arg_parsing_handles_outputPom_parameter():
cl_args = ['--outputPom=output-pom.xml', 'somejar1.jar', 'somejar2.jar', 'somejar3.jar']
args = snykjar.parse_command_line_args(cl_args)
assert args.outputPom == 'output-pom.xml'
assert len(args.jar_path) == 3
assert args.jar_path[0] == cl_args[1]
assert args.jar_path[1] == cl_args[2]
assert args.jar_path[2] == cl_args[3]