Skip to content

Commit 257760b

Browse files
committed
fixing bug with passing an incorrect variable to call
1 parent 306bcb2 commit 257760b

5 files changed

Lines changed: 39 additions & 24 deletions

File tree

geosupport/function_info.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def __contains__(self, name):
2626
)
2727

2828
def load_function_info():
29-
FUNCTIONS = FunctionDict()
29+
functions = FunctionDict()
3030

3131
alt_names = {}
3232

@@ -52,21 +52,21 @@ def load_function_info():
5252

5353
row['inputs'] = []
5454

55-
FUNCTIONS[function] = row
55+
functions[function] = row
5656

57-
FUNCTIONS.alt_names = alt_names
57+
functions.alt_names = alt_names
5858

5959
with open(FUNCTION_INPUTS_CSV) as f:
6060
csv = DictReader(f)
6161

6262
for row in csv:
6363
if row['function']:
64-
FUNCTIONS[row['function']]['inputs'].append({
64+
functions[row['function']]['inputs'].append({
6565
'name': row['field'],
6666
'comment': row['comments']
6767
})
6868

69-
return FUNCTIONS
69+
return functions
7070

7171
def list_functions():
7272
s = sorted([
@@ -139,13 +139,13 @@ def input_help():
139139
return '\n'.join(s)
140140

141141
def load_work_area_layouts():
142-
WORK_AREA_LAYOUTS = {}
143-
INPUT = []
142+
work_area_layouts = {}
143+
inputs = []
144144

145145
for csv in glob.glob(path.join(WORK_AREA_LAYOUTS_PATH, '*', '*.csv')):
146146
directory = path.basename(path.dirname(csv))
147-
if directory not in WORK_AREA_LAYOUTS:
148-
WORK_AREA_LAYOUTS[directory] = {}
147+
if directory not in work_area_layouts:
148+
work_area_layouts[directory] = {}
149149

150150
layout = {}
151151
name = path.basename(csv).split('.')[0]
@@ -159,7 +159,7 @@ def load_work_area_layouts():
159159

160160
functions = functions.split('_')
161161
for function in functions:
162-
WORK_AREA_LAYOUTS[directory][function + mode] = layout
162+
work_area_layouts[directory][function + mode] = layout
163163

164164
with open(csv) as f:
165165
rows = DictReader(f)
@@ -191,14 +191,14 @@ def load_work_area_layouts():
191191
layout[n.lower()] = v
192192

193193
if directory == 'input':
194-
INPUT.append({
194+
inputs.append({
195195
'name': name,
196196
'alt_names': alt_names,
197197
'functions': row['functions'],
198198
'value': row['value']
199199
})
200200

201-
return WORK_AREA_LAYOUTS, INPUT
201+
return work_area_layouts, inputs
202202

203203
MODES = ['regular', 'extended', 'long', 'long+tpad']
204204
AUXILIARY_SEGMENT_LENGTH = 500

geosupport/function_info/work_area_layouts/input/WA1.csv

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ Low House Number - Sort Format,11,46,56,"D*, Internal Use",,,,
77
"B10SC-1 (includes Borough Code 1, B5SC-1 and B7SC-1):",11,57,67,See next 2 entries,,"borough, borough_1,b5sc,b5sc_1,b7sc,b7sc_1,b10sc,b10sc_1",borough,
88
Borough Code-1,1,57,57,"Required for All Functions but BL, BN. Ignored if Fn 2 has Node Number input",,"borough_code, borough_code_1",borough,"'1'=Manhattan, '2'=Bronx, '3'=Brooklyn, '4'=Queens, '5'=Staten Island"
99
10SC-1,10,58,67,"All but 1N, B*",,"street_code, street_code_1",,
10-
Street Name-1,32,68,99,"All but BL, BN, D*",,"street_name, street, street_name_1, on",,
10+
Street Name-1,32,68,99,"All but BL, BN, D*",,"street_name, street, street_name_1, on, street_1",,
1111
"B10SC-2 (includes Borough Code 2, B5SC-2 and B7SC-2):",11,100,110,"2, 3*, D*",,"borough_2,b5sc_2,b7sc_2,b10sc_2",borough,
1212
Borough Code-2,1,100,100,"2, 3*, D*",,borough_code_2,borough,"'1'=Manhattan, '2'=Bronx, '3'=Brooklyn, '4'=Queens, '5'=Staten Island"
1313
10SC-2,10,101,110,"2, 3*, D*",,street_code_2,,
14-
Street Name-2,32,111,142,"2, 3*",,"street_name_2, from",,
14+
Street Name-2,32,111,142,"2, 3*",,"street_name_2, from, street_2",,
1515
"B10SC-3 (includes Borough Code 3, B5SC-3 and B7SC-3):",11,143,153,"3*, D*",,"borough_3,b5sc_3,b7sc_3,b10sc_3",borough,
1616
Borough Code-3,1,143,143,"3*, D*",,borough_code_3,borough,"'1'=Manhattan, '2'=Bronx, '3'=Brooklyn, '4'=Queens, '5'=Staten Island"
1717
10SC-3,10,144,153,"3*, D*",,street_code_3,,
18-
Street Name-3,32,154,185,3*,,"street_name_3, to",,
18+
Street Name-3,32,154,185,3*,,"street_name_3, to, street_3",,
1919
BOROUGH BLOCK LOT (BBL),10,186,195,BL,,bbl,,
2020
Borough Code,1,186,186,BL,,bbl_borough,,
2121
Tax Block,5,187,191,BL,,bbl_block,,

geosupport/geosupport.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ def _call_geolib(self, wa1, wa2):
5959

6060
return wa1, wa2
6161

62-
def call(self, kwargs_dict={}, mode=None, **kwargs):
62+
def call(self, kwargs_dict=None, mode=None, **kwargs):
63+
if kwargs_dict is None:
64+
kwargs_dict = {}
6365
kwargs_dict.update(kwargs)
6466
kwargs_dict.update(set_mode(mode))
6567

geosupport/io.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
from functools import partial
2-
import glob
3-
from os import path
42

53
from .config import BOROUGHS
64
from .error import GeosupportError
@@ -143,7 +141,7 @@ def create_wa1(kwargs):
143141

144142
layout = WORK_AREA_LAYOUTS['input']['WA1']
145143

146-
for key,value in kwargs.items():
144+
for key, value in kwargs.items():
147145
formatter = get_formatter(layout[key]['formatter'])
148146
value = '' if value is None else str(formatter(value))
149147

@@ -160,7 +158,7 @@ def create_wa2(flags):
160158
return None
161159

162160
if flags['auxseg']:
163-
length += AUXILIARY_SEGMENT_LENGTH
161+
length += AUXILIARY_SEGMENT_LENGTH
164162

165163
return ' ' * length
166164

@@ -199,13 +197,13 @@ def parse_output(flags, wa1, wa2):
199197

200198
output.update(parse_workarea(WORK_AREA_LAYOUTS['output']['WA1'], wa1))
201199

202-
function = flags['function']
203-
if function in WORK_AREA_LAYOUTS['output']:
200+
function_name = flags['function']
201+
if function_name in WORK_AREA_LAYOUTS['output']:
204202
output.update(parse_workarea(
205-
WORK_AREA_LAYOUTS['output'][function], wa2
203+
WORK_AREA_LAYOUTS['output'][function_name], wa2
206204
))
207205

208-
function_mode = function + '-' + flags['mode']
206+
function_mode = function_name + '-' + flags['mode']
209207
if function_mode in WORK_AREA_LAYOUTS['output']:
210208
output.update(parse_workarea(
211209
WORK_AREA_LAYOUTS['output'][function_mode], wa2

tests/functional/test_call_alternate.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,18 @@ def test_call_invalid_function(self):
109109

110110
with self.assertRaises(AttributeError):
111111
self.geosupport['fake']({})
112+
113+
def test_call_invalid_key(self):
114+
with self.assertRaises(KeyError):
115+
self.geosupport.intersection(
116+
borough_code='BK', street1='east 19 st', street_2='ave h'
117+
)
118+
119+
with self.assertRaises(KeyError):
120+
self.geosupport.intersection(
121+
borough_code='BK', street_1='east 19 st', street2='ave h'
122+
)
123+
124+
self.geosupport.intersection(
125+
borough_code='BK', street_name_1='east 19 st', street_name_2='ave h'
126+
)

0 commit comments

Comments
 (0)