Skip to content

Commit 5126475

Browse files
committed
fix test_get_values_one_industry
1 parent 52f6b77 commit 5126475

3 files changed

Lines changed: 28 additions & 9 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ There are two different ways to download data retrieved from RegCensusAPI:
176176

177177
1. Use the pandas `df.to_csv(outpath)` function, which allows the user to download a csv of the data, with the given outpath. See the pandas [documentation][3] for more features.
178178

179-
2. The __get_values__ function includes a `download` argument, which allows the user to simply download a csv of the data in the same line as the API call. See below for an example of this call.
179+
2. As of version 0.2.0, the __get_values__ function includes a `download` argument, which allows the user to simply download a csv of the data in the same line as the API call. See below for an example of this call.
180180

181181
```
182182
rc.get_values(series = [1,2], jurisdiction = 38, date = [2010, 2019], download='regdata2010to2019.csv')

regcensus/api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ def get_values(series, jurisdiction, date, filtered=True, summary=True,
136136
# Prints error message if call fails
137137
if (output.columns[:3] == ['title', 'status', 'detail']).all():
138138
print('WARNING:', output.iloc[0][-1])
139+
return
139140
elif download:
140141
if type(download) == str:
141142
clean_columns(output).to_csv(download, index=False)

tests/test_api.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ def test_get_values_multiple_series():
6565

6666

6767
def test_get_values_incorrect_series(capsys):
68-
rc.get_values(series=None, jurisdiction=38, date=2019)
68+
results = rc.get_values(series=None, jurisdiction=38, date=2019)
69+
assert not results
6970
assert capsys.readouterr().out == (
7071
'Valid series ID required. Select from the following list:\n'
7172
)
@@ -99,14 +100,17 @@ def test_get_values_multiple_industries():
99100

100101
def test_get_values_one_industry():
101102
results = rc.get_values(
102-
series=9, jurisdiction=58, date=2019, industry='111', summary=False
103+
series=9, jurisdiction=58, date='2019-05-15',
104+
industry='111', summary=False
103105
)
104-
# No document-level industry results exists for this jurisdiction
105-
assert not results
106+
assert order_results(results, 'seriesValue') == [
107+
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
108+
]
106109

107110

108111
def test_get_values_incorrect_jurisdiction(capsys):
109-
rc.get_values(series=1, jurisdiction=None, date=2019)
112+
results = rc.get_values(series=1, jurisdiction=None, date=2019)
113+
assert not results
110114
assert capsys.readouterr().out == 'Valid jurisdiction ID required.\n'
111115

112116

@@ -128,7 +132,8 @@ def test_get_values_multiple_dates():
128132

129133

130134
def test_get_values_incorrect_dates(capsys):
131-
rc.get_values(series=1, jurisdiction=38, date=None)
135+
results = rc.get_values(series=1, jurisdiction=38, date=None)
136+
assert not results
132137
assert capsys.readouterr().out == 'Valid date is required.\n'
133138

134139

@@ -153,20 +158,33 @@ def test_get_values_multiple_agencies():
153158

154159

155160
def test_get_values_download():
156-
rc.get_values(
161+
results = rc.get_values(
157162
series=91, jurisdiction=38, date=2019, agency=195, download='test.csv'
158163
)
164+
assert not results
159165
assert os.path.exists('test.csv')
160166
os.remove('test.csv')
161167

162168

163169
def test_get_values_incorrect_download(capsys):
164-
rc.get_values(
170+
results = rc.get_values(
165171
series=91, jurisdiction=38, date=2019, agency=195, download=True
166172
)
173+
assert not results
167174
assert capsys.readouterr().out == 'Valid outpath required to download.\n'
168175

169176

177+
def test_get_values_error(capsys):
178+
results = rc.get_values(series=1, jurisdiction=38, date=1900)
179+
assert not results
180+
assert capsys.readouterr().out == (
181+
'WARNING: SeriesValue was not found for the specified parameters'
182+
'{parameters={jurisdiction=[38], date=[1900], industry=null, '
183+
'agency=null, dateIsRange=false, filteredOnly=true, summary=true, '
184+
'documentType=3, documentID=null}}\n'
185+
)
186+
187+
170188
def test_list_document_types():
171189
results = rc.list_document_types()
172190
assert results['All Regulations'] == 3

0 commit comments

Comments
 (0)