示例#1
0
 def test_read(self):
     file_path = 'test-data/1229017.fec'
     a_filter = {'filter_itemizations': ['SB']}
     parsed = fecfile.from_file(file_path, options=a_filter)
     self.assertEqual(parsed['filing']['report_code'], '12P')
     self.assertEqual(len(parsed['itemizations']['Schedule B']), 47)
     self.assertNotIn('Schedule A', parsed['itemizations'])
def from_file_speed(filepath, options={}):
    print('++++\nRunning speed test on {0} with {1}'.format(filepath, options))
    start = datetime.now()
    parsed = fecfile.from_file(filepath, options)
    end = datetime.now()
    num_itemizations = 0
    for itemization_type in parsed['itemizations'].keys():
        num_itemizations += len(parsed['itemizations'][itemization_type])
    print('parsed file with {0} itemizations in {1}'.format(
        num_itemizations,
        end - start,
    ))
示例#3
0
    def test_dates(self):
        file_path = 'test-data/1385191.fec'
        parsed = fecfile.from_file(file_path)

        sched_c = parsed['itemizations']['Schedule C'][0]
        self.assertIsInstance(sched_c['loan_incurred_date_terms'], datetime)

        sched_c = parsed['itemizations']['Schedule C'][2]
        self.assertIsInstance(sched_c['loan_incurred_date'], datetime)
        self.assertIsInstance(sched_c['loan_due_date'], str)
        self.assertIsInstance(sched_c['established_date'], datetime)
        self.assertIsInstance(sched_c['date_signed'], datetime)
        self.assertIsInstance(sched_c['authorized_date'], datetime)
        self.assertIsNone(sched_c['deposit_acct_auth_date_presidential'])
        self.assertIsNone(sched_c['loan_incurred_date_original'])
示例#4
0
 def test_convert(self):
     date_str = '20180616'
     z_file = 'test-data/{d}.zip'.format(d=date_str)
     fec_dir = 'test-data/{d}-fec'.format(d=date_str)
     os.mkdir(fec_dir)
     json_dir = 'test-data/{d}-json'.format(d=date_str)
     os.mkdir(json_dir)
     with zipfile.ZipFile(z_file, 'r') as zip_ref:
         zip_ref.extractall(fec_dir)
     files = os.listdir(fec_dir)
     num_files = len(files)
     for f in sorted(files):
         parsed = fecfile.from_file(fec_dir + '/' + f)
         self.assertIsInstance(parsed['filing']['date_signed'], datetime)
         outpath = json_dir + '/' + f[0:-3] + 'json'
         with open(outpath, 'w') as outf:
             outf.write(
                 json.dumps(parsed, sort_keys=True, indent=2, default=str))
     new_files = os.listdir(json_dir)
     self.assertEqual(len(new_files), num_files)
     shutil.rmtree(fec_dir)
     shutil.rmtree(json_dir)
示例#5
0
 def test_read(self):
     file_path = 'test-data/1260488.fec'
     parsed = fecfile.from_file(file_path)
     self.assertIsInstance(parsed['filing']['date_signed'], datetime)
     self.assertEqual(parsed['filing']['city'], 'Denton')