forked from jsfenfen/990-xml-reader
-
Notifications
You must be signed in to change notification settings - Fork 5
/
tests.py
242 lines (190 loc) · 7.08 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
import os
import json
from unittest import TestCase
from irs_reader.file_utils import validate_object_id
from irs_reader.filing import Filing
from irs_reader.settings import WORKING_DIRECTORY, ALLOWED_VERSIONSTRINGS
from irs_reader.standardizer import Standardizer
from irs_reader.sked_dict_reader import SkedDictReader
from irs_reader.type_utils import listType
from irs_reader.xmlrunner import XMLRunner
## Tests need to be reworked following IRS change in release.
# some test ids
from irs_reader.object_ids import object_ids_2017, \
object_ids_2016, object_ids_2015
# For running cli stuff
from irs_reader.irsx_cli import run_main as run_cli_main, \
get_parser as get_cli_parser
from irs_reader.irsx_index_cli import run_cli_index_main, \
get_cli_index_parser
# FILING_2015V21 = '201642229349300909'
# FILING_2015V21_skeds = [
# 'ReturnHeader990x', 'IRS990', 'IRS990ScheduleA',
# 'IRS990ScheduleB', 'IRS990ScheduleD', 'IRS990ScheduleM',
# 'IRS990ScheduleO'
# ]
# # SUTTER HEALTH SACRAMENTO REGION 2014 filing has multiple schedule K's.
# FILING_2014V50 = '201533089349301428'
# FILING_2014V50_skeds = [
# 'ReturnHeader990x', 'IRS990', 'IRS990ScheduleA', 'IRS990ScheduleB',
# 'IRS990ScheduleC', 'IRS990ScheduleD', 'IRS990ScheduleG',
# 'IRS990ScheduleH', 'IRS990ScheduleI', 'IRS990ScheduleJ',
# 'IRS990ScheduleK', 'IRS990ScheduleL', 'IRS990ScheduleM',
# 'IRS990ScheduleO', 'IRS990ScheduleR'
# ]
FILING_2022 = '202210409349301026'
# don't bother testing every filing in tests
TEST_DEPTH = 10
# When set to false don't test download files that are already there.
# Runs faster set to off!
DOWNLOAD = False
def test_valid_object_id():
result = validate_object_id(FILING_2022)
def test_process_from_id_only():
a = Filing(FILING_2022)
a.process()
# def test_process_from_id_only_2():
# a = Filing(FILING_2014V50)
# a.process()
# assert a.get_version() == '2014v5.0'
# def test_process_with_filepath():
# filename = "%s_public.xml" % FILING_2015V21
# filepath = os.path.join(WORKING_DIRECTORY, filename)
# a = Filing(FILING_2015V21, filepath=filepath)
# a.process()
# assert a.get_version() == '2015v2.1'
# test without runner
class TestConversion:
""" Still doesn't validate actual values, but... """
def setUp(self):
self.xml_runner = XMLRunner()
def test_case_1(self):
parsed_filing = self.xml_runner.run_filing(FILING_2022)
# def test_case_2(self):
# object_ids = object_ids_2017[:TEST_DEPTH] \
# + object_ids_2016[:TEST_DEPTH] + object_ids_2015[:TEST_DEPTH]
# for object_id in object_ids:
# self.xml_runner.run_filing(object_id)
# class TestRunner:
# """ Test using runner class """
# def setUp(self):
# self.xml_runner = XMLRunner()
# def test1(self):
# parsed_filing = self.xml_runner.run_filing(FILING_2022)
# assert parsed_filing.get_type()=='IRS990'
# parsed_filing_schedules = parsed_filing.list_schedules()
# for sked in FILING_2015V21_skeds:
# assert sked in parsed_filing_schedules
# parsed_filing.get_parsed_sked(sked)
# def test_multiple_sked_ks(self):
# parsed_filing = self.xml_runner.run_filing(FILING_2014V50)
# assert parsed_filing.get_type()=='IRS990'
# parsed_filing_schedules = parsed_filing.list_schedules()
# for sked in FILING_2014V50_skeds:
# assert sked in parsed_filing_schedules
# parsed_filing.get_parsed_sked(sked)
# def test_with_standardizer(self):
# standardizer = Standardizer()
# self.xml_runner = XMLRunner(standardizer=standardizer)
# class TestWithDownload:
# def setUp(self):
# self.filing = Filing(FILING_2015V21)
# if os.path.isfile(self.filing.get_filepath()):
# if DOWNLOAD:
# os.remove(self.filing.get_filepath())
# def test_case_1(self):
# self.filing.process()
# assert self.filing.get_version() == '2015v2.1'
# def test_case_2(self):
# self.filing.process()
# f_skeds = self.filing.list_schedules()
# assert f_skeds == FILING_2015V21_skeds
# for f_sked in f_skeds:
# self.filing.get_schedule(f_sked)
class TestCommandLine:
def setUp(self):
parser = get_cli_parser()
self.parser = parser
def test_cli_1(self):
args = self.parser.parse_args([FILING_2022, '--verbose'])
# Does it run? Output is to std out.
run_cli_main(args)
def test_cli_2(self):
# dump only main 990 in bare json format
test_args = ['--schedule', 'IRS990', '--xpath', '202210409349301026']
args = self.parser.parse_args(test_args)
run_cli_main(args)
def test_cli_3(self):
test_args = ['--schedule', 'IRS990', FILING_2022]
args = self.parser.parse_args(test_args)
run_cli_main(args)
"""Testing the csv option without file set somehow breaks
it seems like it's some interaction between how nose handles output
and how we're outputting? Point is, the script works when the test fails.
So only test with the --file output option...
"""
def test_cli_4(self):
test_args = [
'--schedule', 'IRS990',
'--format', 'csv',
'--file', 'testout.csv',
'202210409349301026'
]
args = self.parser.parse_args(test_args)
run_cli_main(args)
def test_cli_5(self):
test_args = [
'--schedule', 'IRS990',
'--format', 'txt',
'--file','testout.csv',
'--verbose',
'202210409349301026'
]
args = self.parser.parse_args(test_args)
run_cli_main(args)
def test_cli_6(self):
test_args = [
'--format', 'txt',
'202210409349301026'
]
args = self.parser.parse_args(test_args)
run_cli_main(args)
def test_cli_7(self):
test_args = [
'--format', 'txt',
'--xpath',
'--verbose',
'202210409349301026'
]
args = self.parser.parse_args(test_args)
run_cli_main(args)
def test_cli_8(self):
test_args = [
'--list_schedules',
'202210409349301026'
]
args = self.parser.parse_args(test_args)
run_cli_main(args)
def test_cli_8(self):
test_args = [
'--format', 'txt',
'202210409349301026'
]
args = self.parser.parse_args(test_args)
run_cli_main(args)
def test_cli_namespaced(self):
test_args = [
'--format', 'txt',
'202210409349301026' # tags start with "irs:"
]
args = self.parser.parse_args(test_args)
run_cli_main(args)
class TestCommandLine_Index:
def setUp(self):
parser = get_cli_index_parser()
self.parser = parser
def test_cli_index_1(self):
args = self.parser.parse_args(['--year', '2017'])
# Does it run? Output is to the 2017 index file.
if DOWNLOAD:
run_cli_index_main(args)