Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hook to update io.input.stream to sys.stdin if it is None. #5647

Merged

Conversation

chadac
Copy link
Contributor

@chadac chadac commented May 19, 2022

Pull Request Check List

Resolves: #5633

  • Added tests for changed code.
  • Updated documentation for changed code.

@chadac chadac marked this pull request as ready for review May 19, 2022 20:25
src/poetry/console/commands/command.py Outdated Show resolved Hide resolved
Secrus
Secrus previously approved these changes May 19, 2022
@Secrus Secrus requested a review from a team May 19, 2022 22:45
@abn
Copy link
Member

abn commented May 20, 2022

Is this something we can add a meaningful test for?

@chadac
Copy link
Contributor Author

chadac commented May 20, 2022

@abn

I could create a new test_command.py with these tests or add them to an existing file:

def test_command_with_no_io_stream(mocker: MockerFixture):
    command = Command()
    mocker.patch.object(
        BaseCommand,
        "run",
        return_value=[1]
    )
    io = IO(input=Input(), output=None, error_output=None)
    io.input.set_stream(None)
    command.run(io)
    assert io.input.stream == sys.stdin


def test_command_with_existing_io_stream(mocker: MockerFixture):
    command = Command()
    mocker.patch.object(
        BaseCommand,
        "run",
        return_value=[1]
    )
    io = IO(input=Input(), output=None, error_output=None)
    io.input.set_stream(sys.stdout)
    command.run(io)
    assert io.input.stream == sys.stdout

What would y'all recommend?

@abn
Copy link
Member

abn commented May 20, 2022

I was wondering if we could create a more functional test. Similar to one of the other interactive command test cases.

@chadac
Copy link
Contributor Author

chadac commented May 20, 2022

Sure, lemme take a crack at that. There currently aren't any tests for cache clear at the moment, I can see if I can get it fully covered in the integration tests.

@chadac
Copy link
Contributor Author

chadac commented May 20, 2022

I've gone ahead and added some tests for the cache clear command, but incidentally it actually doesn't capture the issue this PR fixes. The main issue is that the CommandTester in cleo don't actually trigger the problematic code in cleo.application.Application:L425. It's possible that this could be caught by migrating to using ApplicationTester instead, although I don't know what y'all think about that. It would be a divergence from what most of the other commands do.

@neersighted
Copy link
Member

I've gone ahead and added some tests for the cache clear command, but incidentally it actually doesn't capture the issue this PR fixes. The main issue is that the CommandTester in cleo don't actually trigger the problematic code in cleo.application.Application:L425. It's possible that this could be caught by migrating to using ApplicationTester instead, although I don't know what y'all think about that. It would be a divergence from what most of the other commands do.

I would rather have a good regression test for this, even if it's a bit divergent from the other tests.

@chadac
Copy link
Contributor Author

chadac commented May 23, 2022

Sounds good, I've gone ahead and swapped it over. I I did have to add one attribute to the Application class in order to ensure that the "original" input object is sufficiently preserved, so that the command code can property specify either sys.stdin or the proper test StringIO stream. I'm open to other ideas, though. It's technically less brittle now as the hardcoded sys.stdin is gone, but technically it should be unneeded when cleo merges in this PR and has the same tests.

@branchvincent
Copy link
Member

@chadac we plan to have a new cleo release soon with your merged fix. Could we update this pr to temporarily depend on cleo's master branch to verify your tests also pass here? Then we can update again once it's released

@branchvincent branchvincent added area/cli Related to the command line Dependency status/external-issue Issue is caused by external project (platform, dep, etc) labels Jun 2, 2022
@neersighted
Copy link
Member

The Cleo release is now in master -- this can just be converted to a regression test only.

@chadac chadac force-pushed the bugfix/5633-cache-clear-fails branch from 4b1c48f to da4a269 Compare June 4, 2022 15:00
@neersighted neersighted merged commit 8776993 into python-poetry:master Jun 4, 2022
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/cli Related to the command line status/external-issue Issue is caused by external project (platform, dep, etc)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cache clear fails without waiting for input
5 participants