Beispiel #1
0
 def test_already_sorted_file_unchanged(self):
     """file output after sorting is identical to sorted input"""
     expected = FileTester.read_file(FileTester.sortedfile)
     tempfile = FileTester.copy_to_temp_file(FileTester.sortedfile)
     ledgerfile = LedgerFile(tempfile)
     ledgerfile.sort()
     ledgerfile.write_file()
     actual = FileTester.read_file(tempfile)
     remove(tempfile)
     self.assertEqual(expected, actual)
Beispiel #2
0
 def test_initial_non_transaction_date(self):
     """1st thing in file is a non-transaction, has default date"""
     tempfile = FileTester.create_temp_file('blah\nblah blah blah')
     ledgerfile = LedgerFile(tempfile)
     # non-transaction dates are only populated with sort
     ledgerfile.sort()
     remove(tempfile)
     self.assertEqual(
         LedgerFile.STARTING_DATE,
         ledgerfile.get_things()[0].thing_date
     )
Beispiel #3
0
 def test_sorting(self):
     """test sorting"""
     expected = FileTester.read_file(FileTester.alpha_sortedfile)
     tempfile = FileTester.copy_to_temp_file(
         FileTester.alpha_unsortedfile
     )
     ledgerfile = LedgerFile(tempfile)
     ledgerfile.sort()
     ledgerfile.write_file()
     actual = FileTester.read_file(tempfile)
     remove(tempfile)
     self.assertEqual(expected, actual)
Beispiel #4
0
    def process_file(self):

        if self.args.next_scheduled_date:
            if not self.args.schedule_file:
                print('error: -S/--schedule-file is required')
                return 8

            schedule_file = ScheduleFile(self.args.schedule_file)
            print(schedule_file.next_scheduled_date())
            return 0

        if not self.args.file:
            print('error: -f/--file is required')
            return 16

        try:
            ledgerfile = LedgerFile(self.args.file, self.args.reconcile)
        except LdgReconcilerMoreThanOneMatchingAccount as e:
            print('Reconcile error. More than one matching account:')
            for account in e.message:
                print('    ' + account)
            return 2
        except LdgReconcilerMultipleStatuses as e:
            print(str(e))
            return 4

        if self.args.schedule_file:
            schedule_file = ScheduleFile(self.args.schedule_file)
            scheduler = Scheduler(ledgerfile, schedule_file)
            scheduler.run()
            schedule_file.write_file()
            ledgerfile.write_file()

        if self.args.sort:
            ledgerfile.sort()
            ledgerfile.write_file()

        if self.args.reconcile:
            if ledgerfile.rec_account_matches:  # pragma: no cover
                reconciler = Reconciler(ledgerfile)
                reconciler.cmdloop()
            else:
                print('No matching account found for "{acct}"'.format(
                    acct=self.args.reconcile
                ))

        return 0
Beispiel #5
0
    def test_later_non_transaction_date(self):
        """later non-transaction things inherit preceding thing date"""
        testdata = '''2013/05/06 payee name
    expenses: misc
    liabilities: credit card  $-1
2013/05/07 payee name
    expenses: misc
    liabilities: credit card  $-2
'''
        tempfile = FileTester.create_temp_file(testdata)
        ledgerfile = LedgerFile(tempfile)
        ledgerfile._add_thing_from_lines(
            ['; blah blah blah', '; and so on...']
        )
        # non-transaction dates are only populated with sort
        ledgerfile.sort()
        remove(tempfile)
        self.assertEqual(
            ledgerfile.get_things()[1].thing_date,
            ledgerfile.get_things()[2].thing_date
        )