1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
__copyright__ = 'Copyright (c) 2020 Kristóf Marussy <kristof@marussy.com>'
__license__ = 'GNU GPLv2'
import unittest
from beancount.loader import load_doc
from beancount.parser import cmptest
class DefaultToleranceTest(cmptest.TestCase):
@load_doc()
def test_account_with_tolerance(self, entries, errors, options_map):
'''
plugin "beancount_extras_kris7t.plugins.default_tolerance"
2020-01-01 open Assets:Checking
default-balance-tolerance: 10
2020-01-01 balance Assets:Checking 0 USD
'''
self.assertEqualEntries('''
plugin "beancount_extras_kris7t.plugins.default_tolerance"
2020-01-01 open Assets:Checking
default-balance-tolerance: 10
2020-01-01 balance Assets:Checking 0 ~ 10 USD
''', entries)
@load_doc()
def test_account_with_tolerance_override(self, entries, errors, options_map):
'''
plugin "beancount_extras_kris7t.plugins.default_tolerance"
2020-01-01 open Assets:Checking
default-balance-tolerance: 10
2020-01-01 balance Assets:Checking 10 ~ 20 USD
'''
self.assertEqualEntries('''
plugin "beancount_extras_kris7t.plugins.default_tolerance"
2020-01-01 open Assets:Checking
default-balance-tolerance: 10
2020-01-01 balance Assets:Checking 10 ~ 20 USD
''', entries)
@load_doc()
def test_account_with_tolerance_override_zero(self, entries, errors, options_map):
'''
plugin "beancount_extras_kris7t.plugins.default_tolerance"
2020-01-01 open Assets:Checking
default-balance-tolerance: 10
2020-01-01 balance Assets:Checking 0 ~ 0 USD
'''
self.assertEqualEntries('''
plugin "beancount_extras_kris7t.plugins.default_tolerance"
2020-01-01 open Assets:Checking
default-balance-tolerance: 10
2020-01-01 balance Assets:Checking 0 ~ 0 USD
''', entries)
@load_doc()
def test_account_without_tolerance(self, entries, errors, options_map):
'''
plugin "beancount_extras_kris7t.plugins.default_tolerance"
2020-01-01 open Assets:Checking
2020-01-01 balance Assets:Checking 0 USD
2020-01-02 balance Assets:Checking 10 ~ 20 USD
'''
self.assertEqualEntries('''
plugin "beancount_extras_kris7t.plugins.default_tolerance"
2020-01-01 open Assets:Checking
2020-01-01 balance Assets:Checking 0 USD
2020-01-02 balance Assets:Checking 10 ~ 20 USD
''', entries)
@load_doc(expect_errors=True)
def test_account_with_invalid_tolerance(self, entries, errors, options_map):
'''
plugin "beancount_extras_kris7t.plugins.default_tolerance"
2020-01-01 open Assets:Checking
default-balance-tolerance: TRUE
2020-01-01 balance Assets:Checking 0 USD
'''
self.assertRegex(errors[0].message, '^default-balance-tolerance must be decimal')
if __name__ == '__main__':
unittest.main()
|