cleanup of basic filters from writing tests
This commit is contained in:
parent
079857c961
commit
30cb36e17e
@ -98,10 +98,6 @@ class ConditionalFilter(YieldFilter):
|
|||||||
returns True or False -- True indicating that the record should be
|
returns True or False -- True indicating that the record should be
|
||||||
passed through, and False preventing pass through.
|
passed through, and False preventing pass through.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
super(ConditionalFilter, self).__init__()
|
|
||||||
|
|
||||||
def process_record(self, record):
|
def process_record(self, record):
|
||||||
""" Yields all records for which self.test_record is true """
|
""" Yields all records for which self.test_record is true """
|
||||||
|
|
||||||
@ -208,13 +204,11 @@ class FieldAdder(Filter):
|
|||||||
self._replace = replace
|
self._replace = replace
|
||||||
|
|
||||||
def process_record(self, record):
|
def process_record(self, record):
|
||||||
if self._field_name not in record:
|
if self._field_name not in record or self._replace:
|
||||||
if callable(self._field_value):
|
if callable(self._field_value):
|
||||||
record[self._field_name] = self._field_value()
|
record[self._field_name] = self._field_value()
|
||||||
else:
|
else:
|
||||||
record[self._field_name] = self._field_value
|
record[self._field_name] = self._field_value
|
||||||
elif self._replace:
|
|
||||||
record[self._field_name] = self._field_value
|
|
||||||
return record
|
return record
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
@ -241,7 +235,6 @@ class FieldRenamer(Filter):
|
|||||||
""" Filter that renames one field to another.
|
""" Filter that renames one field to another.
|
||||||
|
|
||||||
Takes a dictionary mapping destination keys to source keys.
|
Takes a dictionary mapping destination keys to source keys.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def __init__(self, rename_mapping):
|
def __init__(self, rename_mapping):
|
||||||
super(FieldRenamer, self).__init__()
|
super(FieldRenamer, self).__init__()
|
||||||
@ -250,11 +243,7 @@ class FieldRenamer(Filter):
|
|||||||
def process_record(self, record):
|
def process_record(self, record):
|
||||||
# mapping is dest:source
|
# mapping is dest:source
|
||||||
for dest, source in self._rename_mapping.iteritems():
|
for dest, source in self._rename_mapping.iteritems():
|
||||||
try:
|
|
||||||
record[dest] = record.pop(source)
|
record[dest] = record.pop(source)
|
||||||
except KeyError:
|
|
||||||
# silently pass if source key didn't exist
|
|
||||||
pass
|
|
||||||
return record
|
return record
|
||||||
|
|
||||||
class Splitter(Filter):
|
class Splitter(Filter):
|
||||||
|
@ -175,7 +175,15 @@ class FilterTestCase(unittest.TestCase):
|
|||||||
{'x':1, 'y':10, 'c':100}]
|
{'x':1, 'y':10, 'c':100}]
|
||||||
self.assert_filter_result(fr, expected_data)
|
self.assert_filter_result(fr, expected_data)
|
||||||
|
|
||||||
|
# splitter
|
||||||
|
# flatteners?
|
||||||
|
# unique
|
||||||
|
# unicode filter
|
||||||
|
# string filter
|
||||||
|
|
||||||
|
# phone # cleaner
|
||||||
|
# date cleaner
|
||||||
|
# name cleaner
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
Reference in New Issue
Block a user