Skip to content

Add tests to confirm activate.sh prompt modification behaviors - #1316

Closed
bskinn wants to merge 7 commits into
pypa:masterfrom
bskinn:bash-prompt-tests
Closed

bskinn wants to merge 7 commits into
pypa:masterfrom
bskinn:bash-prompt-tests

Conversation

@bskinn

@bskinn bskinn commented Feb 18, 2019 •

Copy link
Copy Markdown

THIS PR WAS OBSOLETED BY #1330.


Adds the tests called for in #1294. No changes to API/features. Ping @gaborbernat for review.

No changes yet to documentation; no news item added yet -- I would think neither is necessary for this, though?

Let me know if I should squash-rebase.

  • wrote descriptive pull request text
  • added/updated test(s)
  • updated/extended the documentation (???)
  • added news fragment in docs/changelog folder (???)

Also add some initial sanity-check tests for the env tmpdir
Prompt suppression for bash. Probably should be changed to
write/read the $PS1 from a temp file.

DEFINITELY needs to be skipped if on Windows.
MacOS doesn't provide 'dir', seems.
@gaborbernat

gaborbernat commented Feb 18, 2019 •

Copy link
Copy Markdown
Contributor

@bskinn activator script tests are here https://github.com/pypa/virtualenv/blob/master/tests/activation/test_activation.py, any reason why this needs to be separate? I would prefer to extend that rather than create a new place for such tests.

@bskinn

bskinn commented Feb 18, 2019

Copy link
Copy Markdown
Author

Mm, no, you're right - that's a much better place to put these. Should enable me to take advantage of the tooling for working with the other shells, too.

(I had started them out in a new module so that I'd have less chance of colliding with other PRs to master, and so that I could smash around in the file w/o having to worry about keeping track of what was already there.)

@bskinn

bskinn commented Feb 18, 2019

Copy link
Copy Markdown
Author

I figure I should cluster the new tests for each shell together with the pre-existing tests for that shell?

I.e., bash tests here, csh tests here, etc.?

@gaborbernat

Copy link
Copy Markdown
Contributor

It's here https://github.com/bskinn/virtualenv/blob/d5fed2304992a85b378e31b5cf26ce957b324976/tests/activation/test_activation.py#L90, would prefer per feature. Once you add test for one feature, you'll need to fix issues for all interpreters. This ensures our feature parity is uniform.

@bskinn

bskinn commented Feb 18, 2019

Copy link
Copy Markdown
Author

Hm... can you restate/clarify? I'm not sure what you're asking for.

Right now my testing strategy is to activate/deactivate the environment in a subprocess subshell, and, e.g., echo $PS1 > out_file at various points, then after the .call() is done inspect the contents of out_file.

If there's a different way you'd prefer me to go about it, I can reimplement... if I understand you correctly, though, you're suggesting inspecting the activate scripts themselves, rather than their effects on the prompt... and the syntaces of the various shells are different enough that it seems like that introspection would be difficult to implement in a single (parametrized?) test.

@gaborbernat

Copy link
Copy Markdown
Contributor

The way we test the activation scripts is already to create an env and then generate various commands: - see https://github.com/bskinn/virtualenv/blob/d5fed2304992a85b378e31b5cf26ce957b324976/tests/activation/test_activation.py#L92, your prompt tests should be part of this, e.g. by printing PS1, probably through python 👍

https://github.com/bskinn/virtualenv/blob/d5fed2304992a85b378e31b5cf26ce957b324976/tests/activation/test_activation.py#L94

      self.print_os_env_var("PS1"),

And then make asserts on that line 👍

@bskinn

bskinn commented Feb 18, 2019

Copy link
Copy Markdown
Author

Ok, gotcha -- I'll give it a go, trying to integrate them there.

Few things:

  1. One hassle that came up with $PS1 was that some of the escape sequences got parsed oddly... this probably won't be a problem as long as they're odd-parsed the same way before and after env activation... which they should be..?
  2. In the tests as they stand, are there environments created both with and without --prompt specified? When I looked around before it seemed like there was only an env created without --prompt
  3. The different shells use at minimum different env variables to hold the prompt... bash uses $PS1, csh uses (IIRC) $prompt... and IIRC fish uses some funny functional thing, fish_prompt() or whatever. (And that's just the Linux shells...!) I'm a bit worried that trying to implement these would be really ugly. Maybe all it'll take is some expansion of the __init__ of the Activation class, though?
  4. We'll need to discuss further about xonsh ([1168/1285] (TENTATIVE) Implement changes to prompt behavior of activate.xsh #1299), because it has special prompt handling stuff that I think will need to be tested in a fundamentally different way than the other shells.

@gaborbernat

Copy link
Copy Markdown
Contributor

One hassle that came up with $PS1 was that some of the escape sequences got parsed oddly... this probably won't be a problem as long as they're odd-parsed the same way before and after env activation... which they should be..?

you'll need to be specific, what oddities we need to pick from exactly?

In the tests as they stand, are there environments created both with and without --prompt specified? When I looked around before it seemed like there was only an env created without --prompt

we could though add a test parameter to be with or without though 👍

The different shells use at minimum different env variables to hold the prompt... bash uses $PS1, csh uses (IIRC) $prompt... and IIRC fish uses some funny functional thing, fish_prompt() or whatever. (And that's just the Linux shells...!) I'm a bit worried that trying to implement these would be really ugly. Maybe all it'll take is some expansion of the __init__ of the Activation class, though?

Each shells have their own activations scripts, etc too. The environment variable would be an argument on these classes, see https://github.com/bskinn/virtualenv/blob/d5fed2304992a85b378e31b5cf26ce957b324976/tests/activation/test_activation.py#L181

We'll need to discuss further about xonsh (#1299), because it has special prompt handling stuff that I think will need to be tested in a fundamentally different way than the other shells.

Let's talk concretes so we can plan accordingly.

@bskinn

bskinn commented Feb 18, 2019

Copy link
Copy Markdown
Author
  • Re escape sequence oddities, I'll just give a go at implementing the tests, and hopefully they'll just be a non-issue.

  • Re --prompt, I think I'll have to augment the fixturing around the temporary dir, to create a new venv with create_environment(..., prompt="foo")... then, yeah, it should hopefully be ~as simple as an extra parametrize-ation on the tests.

  • 👍 re env prompt variable as an init argument to the shell class

Do you want to discuss xonsh here, or under #1299?

@bskinn

bskinn commented Feb 19, 2019

Copy link
Copy Markdown
Author

Have an idea for handling xonsh. No need to discuss for now.

@bskinn

bskinn commented Feb 28, 2019 •

Copy link
Copy Markdown
Author

@gaborbernat I don't think I'm going to be able to get these tests to work by integrating them into the existing test_activation.py workflow.

The biggest problem is that the python -c '{script}' approach for querying environment variables &c. is not relevant to fish and posh, as those shells use shell-special functions/aliases to generate the prompt, not environment variables, and so print_os_env_var won't work. Inserting shell commands explicitly into commands also didn't work, b/c for mysterious reasons the output from those commands didn't show up as lines/elements in out.

FWIW, I'm pretty sure it's an additional problem that the test_activation tests are run under subprocess's shell=False default; in order for the prompts to be interrogated correctly, I think shell=True is needed.

TBH, in exploring the behavior of test_activation.py, I'm not at all sure that those tests are testing what they're intended to -- it seems like there's a LOT of spillover of the calling environment into what's passed to .check_output(...), that might be influencing things in funny ways. I didn't really explore/diagnose in that direction, though.

Anyways, I now have a rough-draft (lots of refactoring needed) unified, cross-shell framework put together for these prompt behavior tests, here. I believe it accurately reflects the state of the activation scripts as laid out in the tracking project on my fork. test_prompts.py could be easily relocated into activation/, but I think they should be kept separate from test_activation.py.

What do you think?

@gaborbernat

Copy link
Copy Markdown
Contributor

I think the first paragraph issues you enlist problems are solvable. That being said having it separate for now is still an improvement, let's put it under activation/test_prompts.py. My biggest issue with having it separate is overhead on running the CI time wise. It already takes 13 minutes to run Jython, creating new venvs will only increase that even more. That being said we can improve on time later. Feel free to make that PR.

@bskinn

bskinn commented Feb 28, 2019 •

Copy link
Copy Markdown
Author

Wouldn't surprise me if there is a way to fully integrate them -- I just don't think I'm going to be able to figure it out.

I'll relocate the test module, and I should be able to piggyback the non---prompt env onto clean_python without much trouble. I'll take care of the former and look into the latter before creating the PR.

But, I think creating a second venv for the --prompt-specified test cases will be unavoidable, because the __VIRTUAL_PROMPT__ field in the activate templates is replaced at venv creation-time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants