MCPcopy Index your code
hub / github.com/pyinvoke/invoke / parse_argv

Class parse_argv

tests/parser_parser.py:52–284  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50 assert Parser().ignore_unknown is False
51
52 class parse_argv:
53 def parses_sys_argv_style_list_of_strings(self) -> None:
54 "parses sys.argv-style list of strings"
55 # Doesn't-blow-up tests FTL
56 mytask = Context(name="mytask")
57 mytask.add_arg("arg")
58 p = Parser(contexts=[mytask])
59 p.parse_argv(["mytask", "--arg", "value"])
60
61 def returns_only_contexts_mentioned(self) -> None:
62 task1 = Context("mytask")
63 task2 = Context("othertask")
64 result = Parser((task1, task2)).parse_argv(["othertask"])
65 assert len(result) == 1
66 assert result[0].name == "othertask"
67
68 def raises_error_if_unknown_contexts_found(self) -> None:
69 with raises(ParseError):
70 Parser().parse_argv(["foo", "bar"])
71
72 def unparsed_does_not_share_state(self) -> None:
73 r = Parser(ignore_unknown=True).parse_argv(["self"])
74 assert r.unparsed == ["self"]
75 r2 = Parser(ignore_unknown=True).parse_argv(["contained"])
76 assert r.unparsed == ["self"] # NOT ['self', 'contained']
77 assert r2.unparsed == ["contained"] # NOT ['self', 'contained']
78
79 def ignore_unknown_returns_unparsed_argv_instead(self) -> None:
80 r = Parser(ignore_unknown=True).parse_argv(["foo", "bar", "--baz"])
81 assert r.unparsed == ["foo", "bar", "--baz"]
82
83 def ignore_unknown_does_not_mutate_rest_of_argv(self) -> None:
84 p = Parser([Context("ugh")], ignore_unknown=True)
85 r = p.parse_argv(["ugh", "what", "-nowai"])
86 # NOT: ['what', '-n', '-w', '-a', '-i']
87 assert r.unparsed == ["what", "-nowai"]
88
89 def always_includes_initial_context_if_one_was_given(self) -> None:
90 # Even if no core/initial flags were seen
91 t1 = Context("t1")
92 init = Context()
93 result = Parser((t1,), initial=init).parse_argv(["t1"])
94 assert result[0].name is None
95 assert result[1].name == "t1"
96
97 def returned_contexts_are_in_order_given(self) -> None:
98 t1, t2 = Context("t1"), Context("t2")
99 r = Parser((t1, t2)).parse_argv(["t2", "t1"])
100 assert [x.name for x in r] == ["t2", "t1"]
101
102 def returned_context_member_arguments_contain_given_values(
103 self,
104 ) -> None:
105 c = Context("mytask", args=(Argument("boolean", kind=bool),))
106 result = Parser((c,)).parse_argv(["mytask", "--boolean"])
107 assert result[0].args["boolean"].value is True
108
109 def inverse_bools_get_set_correctly(self) -> None:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…