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