I have a method called export
that depends heavily on the DB table schema. And by “depends heavily” I mean I know that adding the new column to certain table often (very often) leads to the export
method change (usually you should add the new field to the export data as well).
My goal is to make programmer explicitly say whether he forgot to look at the export
method or just don't want to add field to the export data.
I have two ideas, but both of them have flaws.
Smart "Read all" wrapper
I can create the smart wrapper that makes sure all data is explicitly read.
Something like this:
def export():
checker = AllReadChecker.new(table_row)
name = checker.get('name')
surname = checker.get('surname')
checker.i_dont_need('age') # explicitly ignore the "age" field
result = [name, surname] # or whatever
checker.i_am_done() # check all is read
return result
So, checker
asserts if table_row
contains another fields that were not read. But all this thing look kind of heavy and (maybe) affects perfomance.
“Check that method” unittest
I can just create the unittest that remembers the last table condition and fails every time the table is changes. In that case programmer would see something like “don't forget to check out the export
method”. To stop that warning to appear programmer would (or wouldn't — that's a problem) check out export
and manually (that's another problem) fix the test by adding new fields into it.
P. S.
The above problem is just the example of the more wide class of problems I encounter from time to time. I want to bind some pieces of code and/or infrastructure so changing one of them immediately alerts programmer to check another one.
Aucun commentaire:
Enregistrer un commentaire