Comments (8)
Thanks @stdedos . I already checked the tests, but I was still unable to make my test case work. Honestly, I didn't look at it recently, may be I will give it another try...
from questionary.
try using pyprompttoolkits create_pipe_input
with create_pipe_input() as inp:
pipe = [
"answer 1",
"answer 2",
]
for p in pipe:
inp.send_text(p)
inp.send_text("\n")
run_prompt_session( )
as it is the core prompting library being abstracted
this isnt perfect either as if your input is too short it will hang and so you must thread tests to timeout when tests are ready so that they error
if you find a way to better handle this on pytests pls lmk
from questionary.
sorry one caveat
you basically need to pass in
input: Optional[Input] = None,
output: Optional[Output] = None,
confusing as f@#% as they are magically appended kwargs
with create_pipe_input() as inp:
pipe = []
for p in pipe:
inp.send_text(p)
inp.send_text("\n")
vars = questionary.prompt(
questions,
input=inp,
output=DummyOutput(),
)
from questionary.
Thank you @alexlatif
oosh! it is a bit more complicated than I thought, I need to change how I created my code. In my tutorial, I use wrapper functions to questionary prompts without giving the possibility to pass additional data :D
Another question, I saw in your tests, you prefer use \r
instead for \n
for Enter
, why?
from questionary.
Hum, I am struggling with this test. I don't want I'm doing wrong, but the confirm input just return True all the time. I try Enter with \n and \r without success. Do you have any idea?
def test_complicated():
def complicated_prompt(*, inputs, output) -> list[str]:
fruits = []
c = True
while c:
fruit = questionary.text("Fruit:", input=inputs[0], output=output).ask()
fruits.append(fruit)
c = questionary.confirm('add another fruit', default=True, input=inputs[1], output=output).ask()
return fruits
with create_pipe_input() as confirm_input, create_pipe_input() as text_input:
confirm_input.send_text('Y\nn\n')
text_input.send_text('apple\npineapple\n')
fruits = complicated_prompt(inputs=[text_input, confirm_input], output=DummyOutput())
assert fruits == ['apple', 'pineapple']
from questionary.
sorry for the delay. it actually depends on the question. so when its choices "" an empty string worked, but then i had to simulate the arrow keys and could not just pass in the value of the choice as it is obvs reading from the stdin.
it was so much trial and error for me too that i just gave up on testing it all as i would have liked. in reality it isn't this package's fault as much as it is a terribly handled feature of prompt_toolkit.
i've give up on python as a whole tbh and am is the magic land of Rust where annoyances like this are a thing of the past
from questionary.
I think I will just give up on testing. Effectively prompt_toolkit didn't well manage the testing part :(
Thank you for your time and I'm sad you're giving up on Python, it may have its quirks (like every programming language) but I think overall, it is still a pleasant language to use. Hope you will change your mind :)
from questionary.
Not an official documentation, but documented somehow? #253 (comment)
from questionary.
Related Issues (20)
- Require typed answer for confirm question HOT 3
- Flag to retain options on the screen even after the user has selected an option
- Publish documentation of 2.0.0 HOT 2
- Hide password with another flag for `questionary.password`
- Validating a checkbox with Alt-Enter makes it return the empty string
- Need Help in SELECTING Option HOT 2
- I wanted to Change Question Mark (qmark) in TITLE HOT 1
- Disable selected style but respect highlighted for default choice of select HOT 1
- Update prompt_toolkit to be compatible with ipython HOT 6
- Documentation for Autocomplete in Dictionary HOT 1
- Using questionary to wrap prompts for `click` HOT 1
- Refer to a previous answer as the default value of the next question HOT 1
- `path` parameter for `min_input_len` HOT 2
- Support for Mac keyboard layout in input prompt HOT 1
- Is there a way to modify defaults, or at least inherit them from previous Question? HOT 1
- Fix syntax error in documentation
- Inconsistency in Documentation or Bug for return value of questionary.prompt() after capture of Keyboard Interrupt (ctrl-c)
- Allow more convinient selection HOT 1
- Asking a blocking question in an async execution breaks the event loop (RuntimeError: This event loop is already running)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from questionary.