Skip to content

sorting in _assert_equal not working for mixed None values #34

@mcnick

Description

@mcnick

Problem

When calling BaseMockTable.assert_equal with expected data that contains both None values and not-None values for the same key an Exception can be raised. It's caused by sorting of the list when ignore_order=True, which isn't possible with different data types.

.../sql_mock/table_mocks.py:315: in assert_equal
    self._assert_equal(
.../sql_mock/table_mocks.py:259: in _assert_equal
>           expected = sorted(expected, key=lambda d: sorted(d.items()))
E           TypeError: '<' not supported between instances of 'str' and 'NoneType'
.../sql_mock/table_mocks.py:259: TypeError

The same thing will probably happen for the query result data as well in a similar case (I didn't test that yet).

Example

expected_output = [{'foo': 'bar'}, {'foo': None}]
mock_table.assert_equal(expected) # raises TypeError (see above)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions