def testRunEnterDaysLessThanOne(self): schedulefiledata = FileTester.read_file( FileTester.test_enter_lessthan1 ) tempschedulefile = FileTester.write_to_temp_file( FileTester.test_enter_lessthan1, schedulefiledata ) schedulefile = ScheduleFile(tempschedulefile) templedgerfile = FileTester.create_temp_file('') ledgerfile = LedgerFile(templedgerfile) scheduler = Scheduler(ledgerfile, schedulefile) scheduler.run() ledgerfile.write_file() schedulefile.write_file() schedulefile_actual = FileTester.read_file(tempschedulefile) schedulefile_expected = FileTester.read_file( FileTester.test_enter_lessthan1 ) os.remove(templedgerfile) os.remove(tempschedulefile) self.assertEqual( schedulefile_expected, schedulefile_actual )
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 )
def test_count_initial_non_transaction(self): """counts initial non-transaction (probably a comment)""" testdata = '''; blah ; blah blah blah 2013/05/06 payee name expenses: misc liabilities: credit card $-50 ''' tempfile = FileTester.create_temp_file(testdata) ledgerfile = LedgerFile(tempfile) remove(tempfile) self.assertEquals(2, ledgerfile.thing_counter)
def test_count_initial_transaction(self): """counts initial transaction""" testdata = '''2013/05/06 payee name expenses: misc liabilities: credit card $-50 ; blah blah blah 2013/05/06 payee name expenses: misc liabilities: credit card $-50 2013/02/30 invalid date (bonus test for thing date checking coverage) (will be lumped with previous; note is invalid ledger file...) ''' tempfile = FileTester.create_temp_file(testdata) ledgerfile = LedgerFile(tempfile) remove(tempfile) self.assertEquals(2, ledgerfile.thing_counter)
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 )
def test_assigned_thing_numbers(self): """thing numbers added in sequence starting at one""" testdata = '''; blah ; blah blah blah 2013/05/06 payee name expenses: misc liabilities: credit card $-50 ''' tempfile = FileTester.create_temp_file(testdata) ledgerfile = LedgerFile(tempfile) remove(tempfile) thing = LedgerThing([ '2011/01/01 beezlebub', ' assets: soul', ' liabilities: credit card $666', ]) ledgerfile.add_thing(thing) expected = '012' actual = '' for thing in ledgerfile.get_things(): actual += str(thing.thing_number) self.assertEquals(actual, expected)