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

tests are failing with Python 3.10.0a7 due to change in repr() #5995

Closed
hrnciar opened this issue Apr 22, 2021 · 5 comments · Fixed by #6042
Closed

tests are failing with Python 3.10.0a7 due to change in repr() #5995

hrnciar opened this issue Apr 22, 2021 · 5 comments · Fixed by #6042

Comments

@hrnciar
Copy link

hrnciar commented Apr 22, 2021

There were some changes in repr() in 7th alpha of Python 3.10.
https://docs.python.org/3.10/whatsnew/changelog.html#python-3-10-0-alpha-7

bpo-40066: Enum: adjust repr() to show only enum and member name (not value, nor angle brackets) and str() to show only member name. Update and improve documentation to match.

bpo-40066: Enum’s repr() and str() have changed: repr() is now EnumClass.MemberName and str() is MemberName. Additionally, stdlib Enum’s whose contents are available as module attributes, such as RegexFlag.IGNORECASE, have their repr() as module.name, e.g. re.IGNORECASE.
https://bugs.python.org/issue40066

=================================== FAILURES ===================================
___________________________ TestTLSFeature.test_repr ___________________________

self = <tests.x509.test_x509_ext.TestTLSFeature object at 0x7f157d40cbe0>

    def test_repr(self):
        ext1 = x509.TLSFeature([x509.TLSFeatureType.status_request])
>       assert repr(ext1) == (
            "<TLSFeature(features=[<TLSFeatureType.status_request: 5>])>"
        )
E       AssertionError: assert '<TLSFeature(...us_request])>' == '<TLSFeature(...equest: 5>])>'
E         - <TLSFeature(features=[<TLSFeatureType.status_request: 5>])>
E         ?                       -                             ----
E         + <TLSFeature(features=[TLSFeatureType.status_request])>

tests/x509/test_x509_ext.py:150: AssertionError
___________________________ TestCRLReason.test_repr ____________________________

self = <tests.x509.test_x509_ext.TestCRLReason object at 0x7f157d40ece0>

    def test_repr(self):
        reason1 = x509.CRLReason(x509.ReasonFlags.unspecified)
>       assert repr(reason1) == ("<CRLReason(reason=ReasonFlags.unspecified)>")
E       AssertionError: assert '<CRLReason(r...unspecified)>' == '<CRLReason(r...unspecified)>'
E         - <CRLReason(reason=ReasonFlags.unspecified)>
E         ?                   ------------
E         + <CRLReason(reason=unspecified)>

tests/x509/test_x509_ext.py:344: AssertionError
_______________________ TestDistributionPoint.test_repr ________________________

self = <tests.x509.test_x509_ext.TestDistributionPoint object at 0x7f157d23eb00>

    def test_repr(self):
        dp = x509.DistributionPoint(
            None,
            x509.RelativeDistinguishedName(
                [x509.NameAttribute(NameOID.COMMON_NAME, "myCN")]
            ),
            frozenset([x509.ReasonFlags.ca_compromise]),
            [
                x509.DirectoryName(
                    x509.Name(
                        [
                            x509.NameAttribute(
                                NameOID.COMMON_NAME, "Important CA"
                            )
                        ]
                    )
                )
            ],
        )
>       assert repr(dp) == (
            "<DistributionPoint(full_name=None, relative_name=<RelativeDis"
            "tinguishedName(CN=myCN)>, reasons=frozenset({<ReasonFlags.ca_"
            "compromise: 'cACompromise'>}), crl_issuer=[<DirectoryName(val"
            "ue=<Name(CN=Important CA)>)>])>"
        )
E       AssertionError: assert '<Distributio...ant CA)>)>])>' == '<Distributio...ant CA)>)>])>'
E         Skipping 96 identical leading characters in diff, use -v to show
E         - rozenset({<ReasonFlags.ca_compromise: 'cACompromise'>}), crl_issuer=[<DirectoryName(value=<Name(CN=Important CA)>)>])>
E         ?           -                         -----------------
E         + rozenset({ReasonFlags.ca_compromise}), crl_issuer=[<DirectoryName(value=<Name(CN=Important CA)>)>])>

tests/x509/test_x509_ext.py:3806: AssertionError
__________________________ TestFreshestCRL.test_repr ___________________________

self = <tests.x509.test_x509_ext.TestFreshestCRL object at 0x7f157d40c280>

    def test_repr(self):
        fcrl = x509.FreshestCRL(
            [
                x509.DistributionPoint(
                    [x509.UniformResourceIdentifier("ftp://domain")],
                    None,
                    frozenset([x509.ReasonFlags.key_compromise]),
                    None,
                ),
            ]
        )
>       assert repr(fcrl) == (
            "<FreshestCRL([<DistributionPoint(full_name=[<Unifo"
            "rmResourceIdentifier(value='ftp://domain')>], relative"
            "_name=None, reasons=frozenset({<ReasonFlags.key_compromise: "
            "'keyCompromise'>}), crl_issuer=None)>])>"
        )
E       AssertionError: assert '<FreshestCRL...uer=None)>])>' == '<FreshestCRL...uer=None)>])>'
E         Skipping 125 identical leading characters in diff, use -v to show
E         - rozenset({<ReasonFlags.key_compromise: 'keyCompromise'>}), crl_issuer=None)>])>
E         ?           -                          ------------------
E         + rozenset({ReasonFlags.key_compromise}), crl_issuer=None)>])>

tests/x509/test_x509_ext.py:3909: AssertionError
_____________________ TestCRLDistributionPoints.test_repr ______________________

self = <tests.x509.test_x509_ext.TestCRLDistributionPoints object at 0x7f157d2655a0>

    def test_repr(self):
        cdp = x509.CRLDistributionPoints(
            [
                x509.DistributionPoint(
                    [x509.UniformResourceIdentifier("ftp://domain")],
                    None,
                    frozenset([x509.ReasonFlags.key_compromise]),
                    None,
                ),
            ]
        )
>       assert repr(cdp) == (
            "<CRLDistributionPoints([<DistributionPoint(full_name=[<Unifo"
            "rmResourceIdentifier(value='ftp://domain')>], relative"
            "_name=None, reasons=frozenset({<ReasonFlags.key_compromise: "
            "'keyCompromise'>}), crl_issuer=None)>])>"
        )
E       AssertionError: assert '<CRLDistribu...uer=None)>])>' == '<CRLDistribu...uer=None)>])>'
E         Skipping 135 identical leading characters in diff, use -v to show
E         - rozenset({<ReasonFlags.key_compromise: 'keyCompromise'>}), crl_issuer=None)>])>
E         ?           -                          ------------------
E         + rozenset({ReasonFlags.key_compromise}), crl_issuer=None)>])>

tests/x509/test_x509_ext.py:4166: AssertionError
_______________ TestIssuingDistributionPointExtension.test_repr ________________

self = <tests.x509.test_x509_ext.TestIssuingDistributionPointExtension object at 0x7f157d58db40>

    def test_repr(self):
        idp = x509.IssuingDistributionPoint(
            None,
            None,
            False,
            False,
            frozenset([x509.ReasonFlags.key_compromise]),
            False,
            False,
        )
>       assert repr(idp) == (
            "<IssuingDistributionPoint(full_name=None, relative_name=None,"
            " only_contains_user_certs=False, only_contains_ca_certs=False"
            ", only_some_reasons=frozenset({<ReasonFlags.key_compromise: '"
            "keyCompromise'>}), indirect_crl=False, only_contains_attribut"
            "e_certs=False)>"
        )
E       AssertionError: assert '<IssuingDist...certs=False)>' == '<IssuingDist...certs=False)>'
E         Skipping 143 identical leading characters in diff, use -v to show
E         - rozenset({<ReasonFlags.key_compromise: 'keyCompromise'>}), indirect_crl=False, only_contains_attribute_certs=False)>
E         ?           -                          ------------------
E         + rozenset({ReasonFlags.key_compromise}), indirect_crl=False, only_contains_attribute_certs=False)>

Downstream report: https://bugzilla.redhat.com/show_bug.cgi?id=1952522

@alex
Copy link
Member

alex commented Apr 22, 2021

Grumble.

Ok, so we'll need to add an if there once we support Python 3.10. I guess the next step is to add an alpha to our CI.

@tiran
Copy link
Contributor

tiran commented Apr 22, 2021

You could check name and value of each member instead of repr().

@alex
Copy link
Member

alex commented Apr 22, 2021 via email

@encukou
Copy link

encukou commented Apr 22, 2021

If the repr is tested/guaranteed API, consider adding an explicit def __repr__ to the class.

@reaperhulk
Copy link
Member

reaperhulk commented Apr 22, 2021

We do define explicit repr, for example:

def __repr__(self) -> str:
return "<TLSFeature(features={0._features})>".format(self)

Edit: Oops I should really read the whole thing. We obviously don't have explicit reprs on our Enum subclasses. Adding those may be the path of least resistance. Certainly an option.

tiran added a commit to tiran/cryptography that referenced this issue May 10, 2021
Python 3.10 changed enum's object and string representation. PyCA
cryptography now uses a custom subclass of enum.Enum() will well-defined
__repr__ and __str__ from Python 3.9.

Related: https://bugs.python.org/issue40066
Fixes: pyca#5995
Signed-off-by: Christian Heimes <[email protected]>
tiran added a commit to tiran/cryptography that referenced this issue May 10, 2021
Python 3.10 changed enum's object and string representation. PyCA
cryptography now uses a custom subclass of enum.Enum() will well-defined
__repr__ and __str__ from Python 3.9.

Related: https://bugs.python.org/issue40066
Fixes: pyca#5995
Signed-off-by: Christian Heimes <[email protected]>
tiran added a commit to tiran/cryptography that referenced this issue May 11, 2021
Python 3.10 changed enum's object and string representation. PyCA
cryptography now uses a custom subclass of enum.Enum() will well-defined
__repr__ and __str__ from Python 3.9.

Related: https://bugs.python.org/issue40066
Fixes: pyca#5995
Signed-off-by: Christian Heimes <[email protected]>
tiran added a commit to tiran/cryptography that referenced this issue May 11, 2021
Python 3.10 changed enum's object and string representation. PyCA
cryptography now uses a custom subclass of enum.Enum() will well-defined
__repr__ and __str__ from Python 3.9.

Related: https://bugs.python.org/issue40066
Fixes: pyca#5995
Signed-off-by: Christian Heimes <[email protected]>
tiran added a commit to tiran/cryptography that referenced this issue May 11, 2021
Python 3.10 changed enum's object and string representation. PyCA
cryptography now uses a custom subclass of enum.Enum() will well-defined
__repr__ and __str__ from Python 3.9.

Related: https://bugs.python.org/issue40066
Fixes: pyca#5995
Signed-off-by: Christian Heimes <[email protected]>
alex pushed a commit that referenced this issue May 12, 2021
Python 3.10 changed enum's object and string representation. PyCA
cryptography now uses a custom subclass of enum.Enum() will well-defined
__repr__ and __str__ from Python 3.9.

Related: https://bugs.python.org/issue40066
Fixes: #5995
Signed-off-by: Christian Heimes <[email protected]>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 11, 2021
tiran added a commit to tiran/cryptography that referenced this issue Aug 16, 2021
Python 3.10 changed enum's object and string representation. PyCA
cryptography now uses a custom subclass of enum.Enum() will well-defined
__repr__ and __str__ from Python 3.9.

Related: https://bugs.python.org/issue40066
Fixes: pyca#5995
Signed-off-by: Christian Heimes <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging a pull request may close this issue.

5 participants