annotate clipkit_repo/tests/unit/test_args_parsing.py @ 0:49b058e85902 draft

"planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
author padge
date Fri, 25 Mar 2022 13:04:31 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
1 import pytest
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
2 from argparse import Namespace
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
3 from clipkit.modes import TrimmingMode
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
4 from clipkit.args_processing import process_args
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
5
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
6
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
7 @pytest.fixture
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
8 def args():
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
9 kwargs = dict(
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
10 complementary=False,
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
11 gaps=None,
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
12 input="tests/integration/samples/simple.fa",
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
13 input_file_format=None,
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
14 log=False,
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
15 mode=None,
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
16 output="output/simple",
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
17 output_file_format=None,
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
18 )
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
19 return Namespace(**kwargs)
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
20
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
21
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
22 class TestArgsProcessing(object):
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
23 def test_process_args_input_file_dne(self, args):
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
24 args.input = "some/file/that/doesnt/exist"
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
25 with pytest.raises(SystemExit):
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
26 process_args(args)
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
27
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
28 def test_process_args_in_equals_out(self, args):
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
29 args.output = args.input
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
30 with pytest.raises(SystemExit):
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
31 process_args(args)
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
32
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
33 def test_process_args_default_mode(self, args):
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
34 res = process_args(args)
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
35 assert res["mode"] == TrimmingMode.smart_gap
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
36
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
37 def test_process_args_default_complementary(self, args):
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
38 args.complementary = None
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
39 res = process_args(args)
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
40 assert res["complement"] is False
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
41
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
42 def test_process_args_default_gaps(self, args):
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
43 res = process_args(args)
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
44 assert res["gaps"] == 0.9
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
45
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
46 def test_process_args_default_use_logs(self, args):
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
47 args.log = None
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
48 res = process_args(args)
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
49 assert res["use_log"] is False
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
50
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
51 def test_process_args_default_output_file(self, args):
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
52 args.output = None
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
53 res = process_args(args)
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
54 assert res["output_file"] == f"{args.input}.clipkit"
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
55
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
56 def test_process_args_expected_keywords(self, args):
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
57 res = process_args(args)
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
58 expected_keys = [
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
59 "input_file",
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
60 "output_file",
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
61 "input_file_format",
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
62 "output_file_format",
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
63 "complement",
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
64 "gaps",
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
65 "mode",
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
66 "use_log",
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
67 ]
49b058e85902 "planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
padge
parents:
diff changeset
68 assert sorted(res.keys()) == sorted(expected_keys)