def test_load_valid_csv(self): """ Test csv load module test type conversions """ with tempfile.NamedTemporaryFile() as f: f.write(b'date;project;hours;note\n' b'2000-01-01;Testproject;1.0;test note 1\n' b'2000-01-02;Testproject;2.5;test note 2\n') f.seek(0) lst = load_from_csv(f.name) self.assertEqual(2, len(lst)) for i, l in enumerate(lst): self.assertIn('date', l) self.assertEqual(date(2000, 1, i+1), l['date']) self.assertIn('project', l) self.assertEqual('Testproject', l['project']) self.assertIn('hours', l) hours = 1 + i + i * 0.5 self.assertEqual(hours, l['hours']) self.assertIn('note', l) self.assertEqual('test note %d' % (i+1), l['note'])
proj_settings = PROJECTS[project.lower()] return proj_settings.get(item, getattr(defaults, item, None)) vals = ['address', 'name', 'recipient', 'greeting', 'closing', 'currency', 'vat', 'iban', 'bic'] settings = {v: project_or_default_settings(project, v) for v in vals} settings.update(date=today, number=get_invoicenumber(today)) invoice = Invoice(**settings) # load csv try: lst = load_from_csv(args.inputfile) except ValueError as e: print(e) sys.exit(1) if len(lst) == 0: print('Nothing found in file') sys.exit(1) first_date = lst[0]['date'] date_range = get_date_range(first_date, **vars(args)) if date_range: print('From %s to %s' % date_range) rnd = args.round uncleared = args.uncleared