Skip to content

Commit

Permalink
chore(prompt): prompt_on_access test
Browse files Browse the repository at this point in the history
  • Loading branch information
lt-mayonesa committed Nov 6, 2023
1 parent f08a51e commit 46f1295
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 7 deletions.
44 changes: 44 additions & 0 deletions tests_e2e/__specs/execute_tool_with_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,3 +588,47 @@ def test_should_prompt_fuzzy_file_search():
.input("file_c")
.exit()
)


def test_should_handle_prompt_on_access_true():
(
as_a_user(__file__)
.run_hexagon(["prompt-on-access"])
.then_output_should_be(
[
"Enter name:",
]
)
.input("John")
.then_output_should_be(
[
"Enter name: John",
"name: John",
],
)
.then_output_should_be(
[
"Enter age:",
]
)
.input("24")
.then_output_should_be(
[
"Enter age: 24",
"age: 24",
]
)
.then_output_should_be(
[
"Enter age:",
]
)
.input("45")
.then_output_should_be(
[
"Enter age: 45",
"age 2: 45",
]
)
.exit()
)
8 changes: 7 additions & 1 deletion tests_e2e/execute_tool_with_args/app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,10 @@ tools:
action: python_module_prompt
type: shell
alias: p
long_name: Python Module Script With Prompt
long_name: Python Module Script With Prompt

- name: prompt-on-access
action: python_module_prompt_on_access
type: shell
alias: poa
long_name: Python Module Script With Prompt On Access
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ class Args(ToolArgs):
they get parsed loaded automatically by hexagon
"""

name: OptionalArg[str]
age: OptionalArg[str]
country: OptionalArg[Union[str, int]]
likes: OptionalArg[List[str]]
name: OptionalArg[str] = None
age: OptionalArg[int] = None

class Config:
prompt_on_access = True


def main(
Expand All @@ -24,7 +25,9 @@ def main(
env_args: Any = None,
cli_args: Args = None,
):
# if prompt_on_access is set to True, the prompt will be shown when accessing the value
log.result(f"name: {cli_args.name}")
log.result(f"age: {cli_args.age}")
log.result(f"country: {cli_args.country}")
log.result(f"likes: {cli_args.likes}")

# if arg has already been accessed, subsequent prompt should work as expected
log.result(f"age 2: {cli_args.age.prompt()}")

0 comments on commit 46f1295

Please sign in to comment.