Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

📚 The CoCalc Library - books, templates and other resources

132928 views
License: OTHER
1
from nose.tools import assert_equal
2
from ..transform_util import TransformUtil
3
4
5
class TestTransformUtil():
6
7
states = [' Alabama ', 'Georgia!', 'Georgia', 'georgia', \
8
'FlOrIda', 'south carolina##', 'West virginia?']
9
10
expected_output = ['Alabama',
11
'Georgia',
12
'Georgia',
13
'Georgia',
14
'Florida',
15
'South Carolina',
16
'West Virginia']
17
18
def test_remove_punctuation(self):
19
assert_equal(TransformUtil.remove_punctuation('!#?'), '')
20
21
def test_map_remove_punctuation(self):
22
# Map applies a function to a collection
23
output = map(TransformUtil.remove_punctuation, self.states)
24
assert_equal('!#?' not in output, True)
25
26
def test_clean_strings(self):
27
clean_ops = [str.strip, TransformUtil.remove_punctuation, str.title]
28
output = TransformUtil.clean_strings(self.states, clean_ops)
29
assert_equal(output, self.expected_output)
30