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

test_help_preview_generation fails with rich==13.8.1 #133

Closed
mweinelt opened this issue Oct 12, 2024 · 1 comment · Fixed by #135
Closed

test_help_preview_generation fails with rich==13.8.1 #133

mweinelt opened this issue Oct 12, 2024 · 1 comment · Fixed by #135
Labels
bug Something isn't working rich Concerns rich

Comments

@mweinelt
Copy link

Hi!

We are using rich-argparse 1.5.2 and after upgrading rich from 13.7.1 to 13.8.1 in nixpkgs the following test started failing:

_________________________ test_help_preview_generation _________________________

tmp_path = PosixPath('/build/pytest-of-nixbld/pytest-0/test_help_preview_generation0')

    def test_help_preview_generation(tmp_path):
        parser = ArgumentParser("PROG", formatter_class=RichHelpFormatter)
        parser.add_argument("--foo", help="foo help")
        preview_action = parser.add_argument("--generate", action=HelpPreviewAction)
        default_path = tmp_path / "default-preview.svg"
        parser.add_argument("--generate-with-default", action=HelpPreviewAction, path=str(default_path))
    
        # No namespace pollution
        args = parser.parse_args(["--foo", "FOO"])
        assert vars(args) == {"foo": "FOO"}
    
        # No help pollution
        assert "--generate" not in parser.format_help()
    
        # No file, error
        with pytest.raises(SystemExit) as exc_info:
            parser.parse_args(["--generate"])
        assert exc_info.value.code == 1
    
        # Default file, ok
        with pytest.raises(SystemExit) as exc_info:
            parser.parse_args(["--generate-with-default"])
        assert exc_info.value.code == 0
        assert default_path.exists()
    
        # SVG file
        svg_file = tmp_path / "preview.svg"
        with pytest.raises(SystemExit) as exc_info:
            parser.parse_args(["--generate", str(svg_file)])
        assert exc_info.value.code == 0
        assert svg_file.exists()
        assert svg_file.read_text().startswith("<svg")
    
        # HTML file
        preview_action.export_kwds = {}
        html_file = tmp_path / "preview.html"
        with pytest.raises(SystemExit) as exc_info:
            parser.parse_args(["--generate", str(html_file)])
        assert exc_info.value.code == 0
        assert html_file.exists()
        assert html_file.read_text().startswith("<!DOCTYPE html>")
    
        # TXT file
        preview_action.export_kwds = {}
        txt_file = tmp_path / "preview.txt"
        with pytest.raises(SystemExit) as exc_info:
            parser.parse_args(["--generate", str(txt_file)])
        assert exc_info.value.code == 0
        assert txt_file.exists()
>       assert txt_file.read_text().startswith("Usage:")
E       AssertionError: assert False
E        +  where False = <built-in method startswith of str object at 0x7ffff7f51c90>('Usage:')
E        +    where <built-in method startswith of str object at 0x7ffff7f51c90> = ''.startswith
E        +      where '' = read_text()
E        +        where read_text = PosixPath('/build/pytest-of-nixbld/pytest-0/test_help_preview_generation0/preview.txt').read_text

tests/test_argparse.py:992: AssertionError
----------------------------- Captured stderr call -----------------------------
error: help preview path is not provided
Help preview saved to /build/pytest-of-nixbld/pytest-0/test_help_preview_generation0/default-preview.svg
Help preview saved to /build/pytest-of-nixbld/pytest-0/test_help_preview_generation0/preview.svg
Help preview saved to /build/pytest-of-nixbld/pytest-0/test_help_preview_generation0/preview.html
Help preview saved to /build/pytest-of-nixbld/pytest-0/test_help_preview_generation0/preview.txt
@hamdanal
Copy link
Owner

Thanks for the issue. This looks like an upstream bug with rich, I filed Textualize/rich#3540.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working rich Concerns rich
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants