Skip to content

Commit 1b07791

Browse files
authored
Merge pull request #7 from docmarionum1/master
Fix for #6
2 parents 4f36494 + 67260c4 commit 1b07791

4 files changed

Lines changed: 33 additions & 11 deletions

File tree

geosupport/function_info.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def list_functions():
9090
)
9191
return '\n'.join(s)
9292

93-
def function_help(function):
93+
def function_help(function, return_as_string=False):
9494
function = FUNCTIONS[function]
9595

9696
s = [
@@ -117,7 +117,10 @@ def function_help(function):
117117

118118
s = "\n".join(s)
119119

120-
return s
120+
if return_as_string:
121+
return s
122+
else:
123+
print(s)
121124

122125
def input_help():
123126
s = [

geosupport/geosupport.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,18 @@ def __getattr__(self, name):
129129
def __getitem__(self, name):
130130
return self.__getattr__(name)
131131

132-
def help(self, name=None):
132+
def help(self, name=None, return_as_string=False):
133133
if name:
134134
if name.upper() == 'INPUT':
135-
return input_help()
135+
return_val = input_help()
136136
try:
137-
return function_help(name)
137+
return_val = function_help(name, return_as_string)
138138
except KeyError:
139-
return "Function '%s' does not exist." % name
139+
return_val = "Function '%s' does not exist." % name
140140
else:
141-
return list_functions()
141+
return_val = list_functions()
142+
143+
if return_as_string:
144+
return return_val
145+
elif return_val:
146+
print(return_val)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
setup(
1818
name='python-geosupport',
19-
version='1.0.2',
19+
version='1.0.3',
2020
url='https://github.com/ishiland/python-geosupport',
2121
description='Python bindings for NYC Geosupport Desktop Edition',
2222
long_description=long_description,

tests/unit/test_help.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1+
import io
2+
import sys
3+
14
from ..testcase import TestCase
25

36
class TestHelp(TestCase):
47

58
def test_get_function_list(self):
6-
h = self.geosupport.help()
9+
h = self.geosupport.help(return_as_string=True)
710

811
self.assertTrue("1" in h)
912
self.assertTrue("bbl" in h)
1013

1114
def test_function_help(self):
12-
h = self.geosupport.help("bbl")
15+
h = self.geosupport.help("bbl", return_as_string=True)
1316

1417
self.assertTrue("Function BL processes" in h)
1518
self.assertTrue("Input: Borough" in h)
@@ -18,6 +21,17 @@ def test_function_help(self):
1821
self.assertTrue("Mode Switch" in h)
1922

2023
def test_invalid_function_help(self):
21-
h = self.geosupport.help("fake")
24+
h = self.geosupport.help("fake", return_as_string=True)
2225

2326
self.assertEqual(h, "Function 'fake' does not exist.")
27+
28+
def test_print(self):
29+
h = io.StringIO()
30+
sys.stdout = h
31+
32+
o = self.geosupport.help()
33+
34+
sys.stdout = sys.__stdout__
35+
36+
self.assertTrue("bbl" in h.getvalue())
37+
self.assertTrue(o is None)

0 commit comments

Comments
 (0)