Skip to content

Commit

Permalink
Expanding Lark Support
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBurchLog committed May 29, 2024
1 parent 6bf883e commit f577980
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 2 deletions.
7 changes: 5 additions & 2 deletions brewtils/choices.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
GrammarError = ParseError
LexError = ParseError


choices_grammar = r"""
func: CNAME [func_args]
url: ADDRESS [url_args]
Expand All @@ -30,12 +29,16 @@
url_args: "?" arg_pair ("&" arg_pair)*
arg_pair: CNAME "=" ref
?ref: "${" CNAME "}"
?ref: var_ref
| ESCAPED_STRING
var_ref: "${" CNAME "}"
ADDRESS: /^http[^\?]*/
%import common.CNAME
%import common.WS
%import common.ESCAPED_STRING
%ignore WS
"""

Expand Down
96 changes: 96 additions & 0 deletions test/decorators_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,102 @@ def test_bad_partial_call(self, basic_param):
def func(foo):
return foo

class TestDynamicParameters(object):

def test_command_static_choices(self):

STATIC_CHOICES = ["a", "b", "c"]
@parameter(key="key", type="String", choices=STATIC_CHOICES)
def func1(key):
return key

cmd1 = _parse_method(func1)

assert(cmd1.parameters[0].choices.value == STATIC_CHOICES)
assert(cmd1.parameters[0].choices.type == 'static')

def test_command_url_choices(self):

CHOICES_URL = "http://example.com/api/choices.json"

@parameter(key="key", type="String", choices={"type": "url", "value": CHOICES_URL},)
def func1(key):
return key

cmd1 = _parse_method(func1)

assert(cmd1.parameters[0].choices.value == CHOICES_URL)
assert(cmd1.parameters[0].choices.type == 'url')

def test_command_command_choices(self):

@parameter(key="key", type="String", choices={"type": "command", "value": "get_choices"})
def func1(key):
return key

cmd1 = _parse_method(func1)

assert(cmd1.parameters[0].choices.value == "get_choices")
assert(cmd1.parameters[0].choices.type == 'command')

def test_command_reference_input(self):

STATIC_CHOICES = ["a", "b", "c"]

@parameter(
key="index", type="String", choices=STATIC_CHOICES, default="a"
)
@parameter(
key="key",
type="String",
optional=False,
choices={
"type": "command",
"display": "select",
"strict": True,
"value": "get_choices_with_argument(key=${index})",
},
)
def func1(index, key):
return {index: key}

cmd1 = _parse_method(func1)

assert(cmd1.parameters[0].choices.value == STATIC_CHOICES)
assert(cmd1.parameters[0].choices.type == 'static')

assert(cmd1.parameters[1].choices.value == "get_choices_with_argument(key=${index})")
assert(cmd1.parameters[1].choices.type == 'command')

def test_command_reference_and_static_inputs(self):

STATIC_CHOICES = ["a", "b", "c"]

@parameter(
key="index", type="String", choices=STATIC_CHOICES, default="a"
)
@parameter(
key="key",
type="String",
optional=False,
choices={
"type": "command",
"display": "select",
"strict": True,
"value": 'get_choices_with_argument(key=${index}, value="foo")',
},
)
def func1(index, key):
return {index: key}

cmd1 = _parse_method(func1)

assert(cmd1.parameters[0].choices.value == STATIC_CHOICES)
assert(cmd1.parameters[0].choices.type == 'static')

assert(cmd1.parameters[1].choices.value == 'get_choices_with_argument(key=${index}, value="foo")')
assert(cmd1.parameters[1].choices.type == 'command')


class TestParseMethod(object):
"""Test the various ways of marking a method as a Command"""
Expand Down

0 comments on commit f577980

Please sign in to comment.