예제 #1
0
 def test_invalid_date_formats(self):
     self.assertFalse(
         LedgerThing.is_transaction_start('2013/5/12 abc store')
     )
     self.assertFalse(
         LedgerThing.is_transaction_start('2013/06/1 abc store')
     )
예제 #2
0
 def test_get_lines_dates(self):
     # same date
     lines = ('2016/10/24 blah', '  e: blurg')
     thing = LedgerThing(list(lines))
     self.assertEqual(lines, tuple(thing.get_lines()))
     # change date
     thing.thing_date = date(1998, 3, 8)
     self.assertEqual(
         ['1998/03/08 blah', '  e: blurg'],
         thing.get_lines()
     )
예제 #3
0
 def test_get_lines_indent_change(self):
     # status doesn't change, but indent does due to standard
     # uncleared
     lines = (
         '2016/10/24 glob',
         '  ; might as well test comment handling, too',
         '  e: blurg',
         '  a: smurg   $-25',
     )
     thing = LedgerThing(list(lines), 'smurg')
     expected = (
         '2016/10/24 glob',
         '  ; might as well test comment handling, too',
         '  e: blurg',
         '    a: smurg   $-25',
     )
     self.assertEqual(expected, tuple(thing.get_lines()))
     # pending
     lines = ('2016/10/24 glob', ' !e: blurg', '  a: smurg   $-25')
     thing = LedgerThing(list(lines), 'blurg')
     self.assertEqual(
         ('2016/10/24 glob', '  ! e: blurg', '  a: smurg   $-25'),
         tuple(thing.get_lines())
     )
     # cleared
     lines = ('2016/10/24 glob', ' *e: blurg', '  a: smurg   $-25')
     thing = LedgerThing(list(lines), 'blurg')
     self.assertEqual(
         ('2016/10/24 glob', '  * e: blurg', '  a: smurg   $-25'),
         tuple(thing.get_lines())
     )
예제 #4
0
 def test_get_lines_status_change_multiple_lines(self):
     lines = (
         '2016/10/24 glob',
         '  ; might as well test comment handling, too',
         '                 e: blurg   $50',
         ' a: smurg',
         '    a: smurg   $-25',
     )
     thing = LedgerThing(list(lines), 'smurg')
     thing.rec_status = LedgerThing.REC_PENDING
     expected = (
         '2016/10/24 glob',
         '  ; might as well test comment handling, too',
         '                 e: blurg   $50',
         '  ! a: smurg',
         '  ! a: smurg   $-25',
     )
     self.assertEqual(
         expected,
         tuple(thing.get_lines())
     )
     self.assertEqual('', self.redirect.getvalue().rstrip())
예제 #5
0
    def _read_file(self):
        self._test_writable()
        current_lines = []
        with open(self.filename, 'r') as the_file:
            for line in the_file:
                line = line.rstrip()
                if LedgerThing.is_new_thing(line):
                    self._add_thing_from_lines(
                        self._remove_trailing_blank_lines(current_lines)
                    )
                    current_lines = []

                current_lines.append(line)

        self._add_thing_from_lines(
            self._remove_trailing_blank_lines(current_lines)
        )
예제 #6
0
 def test_get_lines_reconciled_status_no_change(self):
     # uncleared
     lines = ('2016/10/24 glob', '  e: blurg', '    a: smurg   $-25')
     thing = LedgerThing(list(lines), 'smurg')
     self.assertEqual(lines, tuple(thing.get_lines()))
     # pending
     lines = ('2016/10/24 glob', '  ! e: blurg', '  a: smurg   $-25')
     thing = LedgerThing(list(lines), 'blurg')
     self.assertEqual(lines, tuple(thing.get_lines()))
     # cleared
     lines = ('2016/10/24 glob', '  * e: blurg', '  a: smurg   $-25')
     thing = LedgerThing(list(lines), 'blurg')
     self.assertEqual(lines, tuple(thing.get_lines()))
예제 #7
0
 def test_get_lines_status_changes(self):
     # uncleared -> pending
     lines = ('2016/10/24 abc', '  e: xyz', '     a: smurg   $-25')
     thing = LedgerThing(list(lines), 'smurg')
     thing.rec_status = LedgerThing.REC_PENDING
     self.assertEqual(
         ('2016/10/24 abc', '  e: xyz', '  ! a: smurg   $-25'),
         tuple(thing.get_lines())
     )
     # pending -> cleared
     thing.rec_status = LedgerThing.REC_CLEARED
     self.assertEqual(
         ('2016/10/24 abc', '  e: xyz', '  * a: smurg   $-25'),
         tuple(thing.get_lines())
     )
     # cleared -> uncleared
     thing.rec_status = LedgerThing.REC_UNCLEARED
     self.assertEqual(
         ('2016/10/24 abc', '  e: xyz', '    a: smurg   $-25'),
         tuple(thing.get_lines())
     )
예제 #8
0
 def test_transaction_code(self):
     self.assertTrue(
         LedgerThing.is_transaction_start('2016/10/20 (123) store')
     )
     self.assertTrue(
         LedgerThing.is_transaction_start('2016/10/20 (abc)store')
     )
     self.assertTrue(
         LedgerThing.is_transaction_start('2016/10/20 (123)')
     )
     self.assertTrue(
         LedgerThing.is_transaction_start('2016/10/20 (123)   ; xyz')
     )
     self.assertFalse(
         LedgerThing.is_transaction_start('2016/10/20(123)')
     )
     self.assertFalse(
         LedgerThing.is_transaction_start('2016/10/20someone')
     )
예제 #9
0
 def test_empty_line(self):
     self.assertFalse(LedgerThing.is_transaction_start(''))
예제 #10
0
 def test_get_lines(self):
     """lines can be entered and retrieved as is"""
     lines = ('abc\n', 'xyz\n')
     thing = LedgerThing(list(lines))
     self.assertEqual(lines, tuple(thing.get_lines()))
예제 #11
0
 def test_statuses(self):
     thing = LedgerThing(
         [
             '2016/10/23 blah',
             '    e: blurg      $10',
             '    e: glerb      $10',
             '    a: checking',
         ],
         'checking'
     )
     self.assertFalse(thing.is_pending())
     self.assertFalse(thing.is_cleared())
     thing.set_pending()
     self.assertTrue(thing.is_pending())
     self.assertFalse(thing.is_cleared())
     thing.set_cleared()
     self.assertFalse(thing.is_pending())
     self.assertTrue(thing.is_cleared())
     thing.set_uncleared()
     self.assertFalse(thing.is_pending())
     self.assertFalse(thing.is_cleared())
예제 #12
0
 def test_is_new_thing(self):
     self.assertTrue(LedgerThing.is_new_thing('2013/04/15 ab store'))
예제 #13
0
 def test_whitespace(self):
     self.assertFalse(
         LedgerThing.is_transaction_start('            \t    ')
     )
예제 #14
0
 def test_invalid_date(self):
     self.assertFalse(
         LedgerThing.is_transaction_start('2013/02/30 abc store')
     )
예제 #15
0
 def test_newline(self):
     line = '\n'
     self.assertFalse(
         LedgerThing.is_transaction_start(line)
     )
예제 #16
0
 def test_is_not_thing(self):
     self.assertFalse(LedgerThing.is_new_thing(''))
예제 #17
0
 def test_date_only(self):
     self.assertTrue(LedgerThing.is_transaction_start('2013/04/14 '))
     self.assertTrue(LedgerThing.is_transaction_start('2013/04/14'))
예제 #18
0
 def test_leading_white_space(self):
     """leading whitespace should return false"""
     self.assertFalse(
         LedgerThing.is_transaction_start('    2013/04/14 abc store')
     )
예제 #19
0
 def test_valid_transaction_start_with_tabs(self):
     """date recognized as the start of a transaction"""
     self.assertTrue(
         LedgerThing.is_transaction_start('2013/04/14\t\tabc store')
     )