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

Improve string representation of matcher in allure report #170

Merged
merged 5 commits into from
Oct 2, 2021

Conversation

Denis-Alexeev
Copy link
Contributor

Matchers in allure report now look like:
<hamcrest.core.core.isnot.IsNot object at 0x7f7262d17c40>

PR purpose:
Make it look more pretty

@offbyone
Copy link
Member

I would prefer something closer to this:

    def __repr__(self) -> str:
        """Returns the description."""
        return "<{}({})>".format(self.__class__.__name__, truncate(self.out, 60))

Basically, I don't think losing the type info is a good plan, and having the debug repr be an unbounded string also has issues. You'd need to implement the truncate method if we don't have one somewhere else in the library.

Also, if you do this, please put a oneliner in changelog.d for it, probably as a "feature".

@Denis-Alexeev
Copy link
Contributor Author

I've fixed the code according to you remarks. Not sure about the reason for CI failure. Could you please help me with that?

@brunns
Copy link
Member

brunns commented Mar 11, 2021

Re the CI failure - if you run tox -e lint before your commit, I believe black has some formatting changes.

I think this needs a test of some kind, too.

@brunns
Copy link
Member

brunns commented Mar 11, 2021

Tests (In BaseMatcherTest) might look something like:

    def testMatcherReprShouldDescribeMatcher(self):
        assert repr(FailingBaseMatcher()) == "FailingBaseMatcher(SOME DESCRIPTION)"

    def testMatcherReprShouldTruncateLongDescription(self):
        class LongDescriptionMatcher(BaseMatcher):
            def describe_to(self, description):
                description.append_text("1234 " * 13)
                
        assert repr(LongDescriptionMatcher()) == "LongDescriptionMatcher(1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 ...)"

@brunns
Copy link
Member

brunns commented Jun 30, 2021

The PR is just awaiting tests and a change log AFAIC.

@Denis-Alexeev
Copy link
Contributor Author

Hello guys! Sorry for the delay. Could you please take a look and give your comments if needed?

@brunns
Copy link
Member

brunns commented Oct 2, 2021

Absolutely - I'll take a look on Monday, when I'm back at my computer.

@offbyone offbyone merged commit dec33de into hamcrest:main Oct 2, 2021
@Denis-Alexeev Denis-Alexeev deleted the repr_to_stringdescription branch October 3, 2021 09:16
kraj pushed a commit to YoeDistro/meta-openembedded that referenced this pull request Jan 4, 2022
Changelog:
=========
  Features
-------------
 - * Adds the tests to the sdist. Fixed by openembedded#150

 openembedded#141 <hamcrest/PyHamcrest#141>
 - * Update the CI to test Python 3.10

 openembedded#160 <hamcrest/PyHamcrest#160>
 - * Add pretty string representation for matchers objects

 openembedded#170 <hamcrest/PyHamcrest#170>

 Bugfixes
------------
 - * Test coverage is now submitted to codecov.io.

 Fixed by openembedded#150

 openembedded#135 <hamcrest/PyHamcrest#135>
 - Change to the ``has_entry()`` matcher - if exactly one key matches,
   but the value does not, report only the mismatching value.

 Fixed by openembedded#157

 openembedded#156 <hamcrest/PyHamcrest#156>
 - * Fix is_() type annotations

 openembedded#180 <hamcrest/PyHamcrest#180>

 Misc
-------------
 - openembedded#150 <hamcrest/PyHamcrest#150>
   openembedded#159 <hamcrest/PyHamcrest#159>
   openembedded#162 <hamcrest/PyHamcrest#162>
   openembedded#163 <hamcrest/PyHamcrest#163>
   openembedded#166 <hamcrest/PyHamcrest#166>
   openembedded#175 <hamcrest/PyHamcrest#175>

Signed-off-by: Wang Mingyu <[email protected]>
Signed-off-by: Khem Raj <[email protected]>
kraj pushed a commit to YoeDistro/meta-openembedded that referenced this pull request Jan 4, 2022
Changelog:
=========
  Features
-------------
 - * Adds the tests to the sdist. Fixed by openembedded#150

 openembedded#141 <hamcrest/PyHamcrest#141>
 - * Update the CI to test Python 3.10

 openembedded#160 <hamcrest/PyHamcrest#160>
 - * Add pretty string representation for matchers objects

 openembedded#170 <hamcrest/PyHamcrest#170>

 Bugfixes
------------
 - * Test coverage is now submitted to codecov.io.

 Fixed by openembedded#150

 openembedded#135 <hamcrest/PyHamcrest#135>
 - Change to the ``has_entry()`` matcher - if exactly one key matches,
   but the value does not, report only the mismatching value.

 Fixed by openembedded#157

 openembedded#156 <hamcrest/PyHamcrest#156>
 - * Fix is_() type annotations

 openembedded#180 <hamcrest/PyHamcrest#180>

 Misc
-------------
 - openembedded#150 <hamcrest/PyHamcrest#150>
   openembedded#159 <hamcrest/PyHamcrest#159>
   openembedded#162 <hamcrest/PyHamcrest#162>
   openembedded#163 <hamcrest/PyHamcrest#163>
   openembedded#166 <hamcrest/PyHamcrest#166>
   openembedded#175 <hamcrest/PyHamcrest#175>

Signed-off-by: Wang Mingyu <[email protected]>
Signed-off-by: Khem Raj <[email protected]>
kraj pushed a commit to YoeDistro/meta-openembedded that referenced this pull request Jan 4, 2022
Changelog:
=========
  Features
-------------
 - * Adds the tests to the sdist. Fixed by openembedded#150

 openembedded#141 <hamcrest/PyHamcrest#141>
 - * Update the CI to test Python 3.10

 openembedded#160 <hamcrest/PyHamcrest#160>
 - * Add pretty string representation for matchers objects

 openembedded#170 <hamcrest/PyHamcrest#170>

 Bugfixes
------------
 - * Test coverage is now submitted to codecov.io.

 Fixed by openembedded#150

 openembedded#135 <hamcrest/PyHamcrest#135>
 - Change to the ``has_entry()`` matcher - if exactly one key matches,
   but the value does not, report only the mismatching value.

 Fixed by openembedded#157

 openembedded#156 <hamcrest/PyHamcrest#156>
 - * Fix is_() type annotations

 openembedded#180 <hamcrest/PyHamcrest#180>

 Misc
-------------
 - openembedded#150 <hamcrest/PyHamcrest#150>
   openembedded#159 <hamcrest/PyHamcrest#159>
   openembedded#162 <hamcrest/PyHamcrest#162>
   openembedded#163 <hamcrest/PyHamcrest#163>
   openembedded#166 <hamcrest/PyHamcrest#166>
   openembedded#175 <hamcrest/PyHamcrest#175>

Signed-off-by: Wang Mingyu <[email protected]>
Signed-off-by: Khem Raj <[email protected]>
halstead pushed a commit to openembedded/meta-openembedded that referenced this pull request Jan 5, 2022
Changelog:
=========
  Features
-------------
 - * Adds the tests to the sdist. Fixed by #150

 #141 <hamcrest/PyHamcrest#141>
 - * Update the CI to test Python 3.10

 #160 <hamcrest/PyHamcrest#160>
 - * Add pretty string representation for matchers objects

 #170 <hamcrest/PyHamcrest#170>

 Bugfixes
------------
 - * Test coverage is now submitted to codecov.io.

 Fixed by #150

 #135 <hamcrest/PyHamcrest#135>
 - Change to the ``has_entry()`` matcher - if exactly one key matches,
   but the value does not, report only the mismatching value.

 Fixed by #157

 #156 <hamcrest/PyHamcrest#156>
 - * Fix is_() type annotations

 #180 <hamcrest/PyHamcrest#180>

 Misc
-------------
 - #150 <hamcrest/PyHamcrest#150>
   #159 <hamcrest/PyHamcrest#159>
   #162 <hamcrest/PyHamcrest#162>
   #163 <hamcrest/PyHamcrest#163>
   #166 <hamcrest/PyHamcrest#166>
   #175 <hamcrest/PyHamcrest#175>

Signed-off-by: Wang Mingyu <[email protected]>
Signed-off-by: Khem Raj <[email protected]>
Signed-off-by: Trevor Gamblin <[email protected]>
daregit pushed a commit to daregit/yocto-combined that referenced this pull request May 22, 2024
Changelog:
=========
  Features
-------------
 - * Adds the tests to the sdist. Fixed by #150

 #141 <hamcrest/PyHamcrest#141>
 - * Update the CI to test Python 3.10

 #160 <hamcrest/PyHamcrest#160>
 - * Add pretty string representation for matchers objects

 #170 <hamcrest/PyHamcrest#170>

 Bugfixes
------------
 - * Test coverage is now submitted to codecov.io.

 Fixed by #150

 #135 <hamcrest/PyHamcrest#135>
 - Change to the ``has_entry()`` matcher - if exactly one key matches,
   but the value does not, report only the mismatching value.

 Fixed by #157

 #156 <hamcrest/PyHamcrest#156>
 - * Fix is_() type annotations

 #180 <hamcrest/PyHamcrest#180>

 Misc
-------------
 - #150 <hamcrest/PyHamcrest#150>
   #159 <hamcrest/PyHamcrest#159>
   #162 <hamcrest/PyHamcrest#162>
   #163 <hamcrest/PyHamcrest#163>
   #166 <hamcrest/PyHamcrest#166>
   #175 <hamcrest/PyHamcrest#175>

Signed-off-by: Wang Mingyu <[email protected]>
Signed-off-by: Khem Raj <[email protected]>
Signed-off-by: Trevor Gamblin <[email protected]>
daregit pushed a commit to daregit/yocto-combined that referenced this pull request May 22, 2024
Changelog:
=========
  Features
-------------
 - * Adds the tests to the sdist. Fixed by #150

 #141 <hamcrest/PyHamcrest#141>
 - * Update the CI to test Python 3.10

 #160 <hamcrest/PyHamcrest#160>
 - * Add pretty string representation for matchers objects

 #170 <hamcrest/PyHamcrest#170>

 Bugfixes
------------
 - * Test coverage is now submitted to codecov.io.

 Fixed by #150

 #135 <hamcrest/PyHamcrest#135>
 - Change to the ``has_entry()`` matcher - if exactly one key matches,
   but the value does not, report only the mismatching value.

 Fixed by #157

 #156 <hamcrest/PyHamcrest#156>
 - * Fix is_() type annotations

 #180 <hamcrest/PyHamcrest#180>

 Misc
-------------
 - #150 <hamcrest/PyHamcrest#150>
   #159 <hamcrest/PyHamcrest#159>
   #162 <hamcrest/PyHamcrest#162>
   #163 <hamcrest/PyHamcrest#163>
   #166 <hamcrest/PyHamcrest#166>
   #175 <hamcrest/PyHamcrest#175>

Signed-off-by: Wang Mingyu <[email protected]>
Signed-off-by: Khem Raj <[email protected]>
Signed-off-by: Trevor Gamblin <[email protected]>
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.

3 participants