data-science-ipython-notebooks/python-data/tests/test_transform_util.py

29 lines
1.0 KiB
Python
Raw Normal View History

from nose.tools import assert_equal
from ..transform_util import TransformUtil
class TestTransformUtil():
states = [' Alabama ', 'Georgia!', 'Georgia', 'georgia', \
'FlOrIda', 'south carolina##', 'West virginia?']
expected_output = ['Alabama',
'Georgia',
'Georgia',
'Georgia',
'Florida',
'South Carolina',
'West Virginia']
def test_remove_punctuation(self):
assert_equal(TransformUtil.remove_punctuation('!#?'), '')
2015-01-27 03:07:37 +08:00
def test_map_remove_punctuation(self):
# Map applies a function to a collection
2015-01-27 03:07:37 +08:00
output = map(TransformUtil.remove_punctuation, self.states)
assert_equal('!#?' not in output, True)
def test_clean_strings(self):
clean_ops = [str.strip, TransformUtil.remove_punctuation, str.title]
output = TransformUtil.clean_strings(self.states, clean_ops)
assert_equal(output, self.expected_output)