Skip to content

Allowing more flexibility for developer assertions #45

Open
@fgarzadeleon

Description

@fgarzadeleon

When using the library the following I thought of the following change.

Problem:
Currently the assertion to check if the data is correct is within the table_mocks.py when for a Mock you run assert_equal. When my assertion is not equal I don't receive more information about why they don't match.

Proposal:
It would be better to do the following:

  1. Separate the assertion from the generation of the query and data.

Currently assert_equal also has responsibility over running _generate_query and _get_results. I see benefits from separating these. We could have a method called generate_results so that we can access the query and result directly from the Mock object.

  1. Separate the cleaning logic in _assert_result and move it generate_results this way this usage could look like this:
# assuming we've successfully ran TableMock.from_mocks() we currently do

TableMock.assert_equal(expected_dict)

# I propose the following which allows de the developer to use other assertion tools
res_dict = TableMock.generate_result()

query = TableMock._sql_mock_data.last_query # I can inspect the query even before it fails if I want to

unittest.TestCase.assertDictEqual(res_dict, expected_dict) # I do my own assertion with whatever library I chose

In this case the more verbose unittest assertion solves my problem.

Conclusion
In a way I think BaseTableMock does not need an assert method within the object, you can expose the data and let the developers write their own assertion statement.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions