Skip to content

Commit

Permalink
Add test cases for Title Case Except
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisCarriere committed Nov 1, 2015
1 parent c7f617e commit 46fc3ca
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
24 changes: 14 additions & 10 deletions etl2osm/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,18 @@ def read_config(config):


def titlecase_except(value, exceptions=cap_except):
word_list = re.split(' ', value)
final = []
if isinstance(value, (string_types, binary_type)):
word_list = re.split(' ', value)
final = []

for word in word_list:
if word in exceptions:
final.append(word)
else:
final.append(word.capitalize())
for word in word_list:
if word in exceptions:
final.append(word)
else:
final.append(word.capitalize())

return ' '.join(final)
return ' '.join(final)
return value


def clean_field(properties, conform):
Expand Down Expand Up @@ -203,8 +205,6 @@ def clean_field(properties, conform):
if field not in properties:
raise ValueError('Cannot find attribute [%s] using the Attribute Function.' % field)
value.append(properties[field])
else:
raise ValueError('Unknown Error - Cannot read your config file: \n %s' % conform)

# Attribute Functions
if 'function' in conform:
Expand Down Expand Up @@ -284,6 +284,10 @@ def clean_field(properties, conform):
except:
logging.warning('Cannot convert [%s] to float.' % value)

# Converts String to Integer [True/False]
if 'text' in conform:
value = conform['text']

return value


Expand Down
6 changes: 4 additions & 2 deletions examples/roads/lake_county.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
"website": "http://www.lakecountyfl.gov/departments/information_technology/geographic_information_services/datadownloads.aspx",
"license": "Public Domain",
"conform": {
"addr:street": [
"name": [
{"function": "direction", "field": "PrefixDire"},
"PrefixType",
{"function": "title", "field": "BaseStreet"},
{"function": "suffix", "field": "SuffixType"}
],
"lanes": {"int": "True", "field": "NumberOfLa"},
"oneway": "Oneway"
"oneway": "Oneway",
"source": {"text": "Lake County"},
"highway": {"text": "residential"}
}
}
16 changes: 15 additions & 1 deletion tests/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,27 @@ def test_transform_title():
properties = {'NAME': "3RD AVENUE"}
assert etl2osm.clean_field(properties, conform) == '3rd Avenue'

conform = {'function': 'title', 'field': "NAME"}
properties = {'NAME': None}
assert not etl2osm.clean_field(properties, conform)

conform = {'function': 'title', 'field': "NAME"}
properties = {'NAME': 2}
assert etl2osm.clean_field(properties, conform) == 2


def test_transform_mph():
conform = {'function': 'mph', 'field': "SPEED"}
properties = {'SPEED': "55"}
assert etl2osm.clean_field(properties, conform) == '55 mph'


def test_transform_text():
conform = {'text': 'Lake County'}
properties = {'NO': "CLUE"}
assert etl2osm.clean_field(properties, conform) == 'Lake County'


def test_transform_geojson():
data = etl2osm.extract(roads['lake_county'])
data.transform()
Expand Down Expand Up @@ -271,4 +285,4 @@ def test_transform_config_to_properties():
# test_transform_int()
# test_transform_float()
# test_transform_geojson_config()
test_transform_config_to_properties()
test_transform_title()

0 comments on commit 46fc3ca

Please sign in to comment.