Magic Reduction
shawnbrown opened this issue · 3 comments
Issue #7 exposes the degree of magic that is currently present in the DataTestCase
methods. Removing (or at least reducing) magic where possible would make the behavior easier to understand and explain.
In cases where small amounts of magic are useful, methods should be renamed to better reflect what's happening.
Illustrating the Problem
This "magic" version:
def test_active(self):
self.assertDataSet('active', {'Y', 'N'})
...is roughly equivalent to:
def test_active(self):
subject = self.subject.set('active')
self.assertEqual(subject, {'Y', 'N'})
The magic version requires detailed knowledge about the method before a newcomer can guess what's happening. The later example is more explicit and easier to reason about.
Having said this, the magic versions of DataTestCase's methods can save a lot of typing. So what I plan to do is:
- Fully implement
assertEqual()
integration (see issue #7) as well as other standard unittest methods (assertGreater()
, etc.). - Rename the existing methods to clearly denote that they run on the subject data (e.g.,
assertDataSum()
→assertSubjectSum()
, etc.).
Removed assertDataCount()
method: 5d77fb2
This method is the most "magical" (and most confusing) of the assertion methods. Addition of the datatest-aware assertEqual()
method makes testing counts trivial.
The older, more confusing use:
def test_counts(self):
self.assertDataCount('col1', ['col2'])
Can now be achieved with more verbose but explicit and simpler to understand implementation:
def test_counts(self):
subj = self.subject.count('col1', ['col2'])
ref = self.reference.sum('col1', ['col2'])
self.assertEqual(subj, ref)
Renamed methods to clarify that they run on the subject
property: a407311
assertDataColumns()
→assertSubjectColumns()
assertDataSet()
→assertSubjectSet()
assertDataSum()
→assertSubjectSum()
assertDataRegex()
→assertSubjectRegex()
assertDataNotRegex()
→assertSubjectNotRegex()
assertDataUnique()
→assertSubjectUnique()
For the purpose of 0.7.0, I'm considering this issue closed. Further work along these lines will happen in a future update (see #20).