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

assertSequenceEqual does not use _getAssertEqualityFunc #88982

Closed
Rarity mannequin opened this issue Aug 3, 2021 · 5 comments
Closed

assertSequenceEqual does not use _getAssertEqualityFunc #88982

Rarity mannequin opened this issue Aug 3, 2021 · 5 comments
Labels
3.9 only security fixes tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error

Comments

@Rarity
Copy link
Mannequin

Rarity mannequin commented Aug 3, 2021

BPO 44819
Nosy @rbtcollins, @ezio-melotti, @voidspace, @iritkatriel, @jdevries3133
Superseder
  • bpo-22452: addTypeEqualityFunc is not used in assertListEqual
  • Files
  • example.py
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-08-07.19:03:39.580>
    created_at = <Date 2021-08-03.20:24:40.648>
    labels = ['type-bug', 'tests', '3.9']
    title = 'assertSequenceEqual does not use _getAssertEqualityFunc'
    updated_at = <Date 2021-08-07.19:03:39.579>
    user = 'https://bugs.python.org/Rarity'

    bugs.python.org fields:

    activity = <Date 2021-08-07.19:03:39.579>
    actor = 'iritkatriel'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-08-07.19:03:39.580>
    closer = 'iritkatriel'
    components = ['Tests']
    creation = <Date 2021-08-03.20:24:40.648>
    creator = 'Rarity'
    dependencies = []
    files = ['50201']
    hgrepos = []
    issue_num = 44819
    keywords = []
    message_count = 5.0
    messages = ['398851', '398860', '398891', '398911', '399198']
    nosy_count = 6.0
    nosy_names = ['rbcollins', 'ezio.melotti', 'michael.foord', 'iritkatriel', 'jack__d', 'Rarity']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '22452'
    type = 'behavior'
    url = 'https://bugs.python.org/issue44819'
    versions = ['Python 3.6', 'Python 3.9']

    @Rarity
    Copy link
    Mannequin Author

    Rarity mannequin commented Aug 3, 2021

    Like the title says, TestCase.assertSequenceEqual does not behave like TestCase.assertEqual where it uses TestCase._getAssertEqualityFunc. Instead, TestCase.assertSequenceEqual uses item1 != item2. That way I can do something like this:

    def test_stuff(self):
       self.addTypeEqualityFunc(
          MyObject,
          comparison_method_which_compares_how_i_want,
       )
       self.assertListEqual(
          get_list_of_objects(),
          [MyObject(...), MyObject(...)],
       )
    

    @Rarity Rarity mannequin added 3.9 only security fixes tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error labels Aug 3, 2021
    @jdevries3133
    Copy link
    Mannequin

    jdevries3133 mannequin commented Aug 4, 2021

    Brian, can you be more specific about what problem is caused by the fact that assertSequenceEqual does not use _getAssertEqualityFunc? Also, I'm not sure what your example is trying to demonstrate. Can you provide a minimal example that shows the problem, but also defines what MyObject, etc. are?

    Let me know if I'm missing something.

    @iritkatriel
    Copy link
    Member

    That's correct, and apparently not mentioned in the doc: https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertSequenceEqual

    @Rarity
    Copy link
    Mannequin Author

    Rarity mannequin commented Aug 4, 2021

    I've attached an example of what I want. It contains a class, a function to be tested, and a test class which tests the function.

    What TestCase.addTypeEqualityFunc feels like it offers is a chance to compare objects however I feel like is needed for each test. Sometimes all I want is to compare the properties of the objects, and maybe not even all of the properties! When I have a list of these objects and I've added an equality function for the object, I was expecting the test class to use my equality function when comparing objects in the list.

    @iritkatriel
    Copy link
    Member

    Closing as duplicate of bpo-22452.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant