Skip to content

CliRunner isolation stdin has name and mode#1497

Merged
davidism merged 1 commit into
pallets:masterfrom
jyscao:clirunner_stdin_fix
Aug 14, 2020
Merged

CliRunner isolation stdin has name and mode#1497
davidism merged 1 commit into
pallets:masterfrom
jyscao:clirunner_stdin_fix

Conversation

@jyscao
Copy link
Copy Markdown
Contributor

@jyscao jyscao commented Mar 11, 2020

  • create subclass of io.TextIOWrapper, NamedTextIOWrapper, for PY3
  • use NamedTextIOWrapper instance for sys.stdin & sys.stdout inside
    of CliRunner's isolation contextmanager

fixes #1064

A few more notes:

  • 'name' & 'mode' are assigned to self.__dict__ as kv-pairs, and not as actual attributes to the self object, because b/c the io.TextIOWrapper object is not writable
  • then __getattribute__ is used to get the above 2 pseudo-attributes from self.__dict__
  • the bug behavior described stdin click.File has .name attribute when running from CLI, but doesn't when using CliRunner #1064 also exists in PY2, but this PR does not attempt to address that (since Python 2 support will eventually be dropped)
  • NamedTextIOWrapper is not applied to sys.stderr, since click does not readily make it available as a click.File parameter type

@davidism davidism changed the title Fix bug in CliRunner's isolation contextmanager CliRunner isolation stdin has name and mode Mar 11, 2020
@kdeldycke
Copy link
Copy Markdown
Collaborator

Can confirm the issue and the fix! 👍

@davidism davidism force-pushed the clirunner_stdin_fix branch from 70b8feb to 7d7809f Compare August 14, 2020 06:17
@davidism davidism added this to the 8.0.0 milestone Aug 14, 2020
@davidism davidism added the f:test runner feature: cli test runner label Aug 14, 2020
@davidism
Copy link
Copy Markdown
Member

Added changelog and test. Rewrote this to use properties instead of messing with __dict__ and __getattr__. Applied it to all three streams.

@davidism davidism merged commit 2571539 into pallets:master Aug 14, 2020
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

f:test runner feature: cli test runner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

stdin click.File has .name attribute when running from CLI, but doesn't when using CliRunner

3 participants