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

has_entry with nested matchers does not report excact cause #156

Closed
dz0 opened this issue Feb 19, 2021 · 5 comments
Closed

has_entry with nested matchers does not report excact cause #156

dz0 opened this issue Feb 19, 2021 · 5 comments
Assignees

Comments

@dz0
Copy link

dz0 commented Feb 19, 2021

Hi, simple example

data = {'level1': {'level2': 2}}
matcher_level2 = has_entries({'level2': 42})

Why has_entry does not display (block) deeper cause?:

assert_that(data, has_entry('level1', matcher_level2))

Expected: a dictionary containing ['level1': a dictionary containing {'level2': <42>}]
     but: was <{'level1': {'level2': 2}}>

As has_entries displays deepest cause:

assert_that(data['level1'], matcher_level2)

Expected: a dictionary containing {'level2': <42>}
     but: value for 'level2' was <2>

assert_that(data, has_entries({'level1': matcher_level2}))

Expected: a dictionary containing {'level1': a dictionary containing {'level2': <42>}}
     but: value for 'level1' value for 'level2' was <2>
@brunns brunns self-assigned this Feb 19, 2021
@dz0
Copy link
Author

dz0 commented Feb 22, 2021

ps.: I'd expect has_entry to be as

def has_entry(key, value_match):
    return has_entries({key: value_match})

@brunns
Copy link
Member

brunns commented Feb 22, 2021

Not quite that simple - has_entry() allows a matcher for the key as well as for the value. I'll take a look when I have some time.

@brunns
Copy link
Member

brunns commented Feb 22, 2021

Thinking about it, perhaps that's why has_entry() doesn't give better mismatch messages. Imagine that the key was specified as hamcrest.anything() - how should the message read then?

Still, if the key matched exactly once, we could probably give better messages in that special but common case.

@brunns
Copy link
Member

brunns commented Feb 24, 2021

Does #157 look any good, @dz0 and @offbyone?

offbyone pushed a commit that referenced this issue Mar 6, 2021
brunns added a commit that referenced this issue Mar 8, 2021
kraj pushed a commit to YoeDistro/meta-openembedded that referenced this issue 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 issue 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 issue 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 issue 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]>
@brunns
Copy link
Member

brunns commented Jun 2, 2023

This fix has been merged & released.

@brunns brunns closed this as completed Jun 2, 2023
daregit pushed a commit to daregit/yocto-combined that referenced this issue 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 issue 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

No branches or pull requests

2 participants