aboutsummaryrefslogtreecommitdiff
path: root/tests/helper.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/helper.py')
-rw-r--r--tests/helper.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/helper.py b/tests/helper.py
new file mode 100644
index 0000000..4cf1b41
--- /dev/null
+++ b/tests/helper.py
@@ -0,0 +1,59 @@
1import sys
2import unittest
3from decimal import Decimal as D
4from unittest import mock
5import requests_mock
6from io import StringIO
7import portfolio, market, main, store
8
9__all__ = ["limits", "unittest", "WebMockTestCase", "mock", "D",
10 "StringIO"]
11
12limits = ["acceptance", "unit"]
13for test_type in limits:
14 if "--no{}".format(test_type) in sys.argv:
15 sys.argv.remove("--no{}".format(test_type))
16 limits.remove(test_type)
17 if "--only{}".format(test_type) in sys.argv:
18 sys.argv.remove("--only{}".format(test_type))
19 limits = [test_type]
20 break
21
22class WebMockTestCase(unittest.TestCase):
23 import time
24
25 def market_args(self, debug=False, quiet=False, report_path=None, **kwargs):
26 return main.configargparse.Namespace(report_path=report_path,
27 debug=debug, quiet=quiet, **kwargs)
28
29 def setUp(self):
30 super().setUp()
31 self.wm = requests_mock.Mocker()
32 self.wm.start()
33
34 # market
35 self.m = mock.Mock(name="Market", spec=market.Market)
36 self.m.debug = False
37
38 self.patchers = [
39 mock.patch.multiple(market.Portfolio,
40 data=store.LockedVar(None),
41 liquidities=store.LockedVar({}),
42 last_date=store.LockedVar(None),
43 report=mock.Mock(),
44 worker=None,
45 worker_notify=None,
46 worker_started=False,
47 callback=None),
48 mock.patch.multiple(portfolio.Computation,
49 computations=portfolio.Computation.computations),
50 ]
51 for patcher in self.patchers:
52 patcher.start()
53
54 def tearDown(self):
55 for patcher in self.patchers:
56 patcher.stop()
57 self.wm.stop()
58 super().tearDown()
59