DeepLcom / sql-mock

A Python library to test your SQL models using mocked input data
MIT License
34 stars 5 forks source link

sorting in _assert_equal not working for mixed None values #34

Closed mcnick closed 9 months ago

mcnick commented 10 months ago

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)