From c682bdf4a02a45312ef1aadf8aa26136cf308414 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Fri, 6 Apr 2018 21:08:06 +0200 Subject: Move tests to separate files --- tests/helper.py | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 tests/helper.py (limited to 'tests/helper.py') 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 @@ +import sys +import unittest +from decimal import Decimal as D +from unittest import mock +import requests_mock +from io import StringIO +import portfolio, market, main, store + +__all__ = ["limits", "unittest", "WebMockTestCase", "mock", "D", + "StringIO"] + +limits = ["acceptance", "unit"] +for test_type in limits: + if "--no{}".format(test_type) in sys.argv: + sys.argv.remove("--no{}".format(test_type)) + limits.remove(test_type) + if "--only{}".format(test_type) in sys.argv: + sys.argv.remove("--only{}".format(test_type)) + limits = [test_type] + break + +class WebMockTestCase(unittest.TestCase): + import time + + def market_args(self, debug=False, quiet=False, report_path=None, **kwargs): + return main.configargparse.Namespace(report_path=report_path, + debug=debug, quiet=quiet, **kwargs) + + def setUp(self): + super().setUp() + self.wm = requests_mock.Mocker() + self.wm.start() + + # market + self.m = mock.Mock(name="Market", spec=market.Market) + self.m.debug = False + + self.patchers = [ + mock.patch.multiple(market.Portfolio, + data=store.LockedVar(None), + liquidities=store.LockedVar({}), + last_date=store.LockedVar(None), + report=mock.Mock(), + worker=None, + worker_notify=None, + worker_started=False, + callback=None), + mock.patch.multiple(portfolio.Computation, + computations=portfolio.Computation.computations), + ] + for patcher in self.patchers: + patcher.start() + + def tearDown(self): + for patcher in self.patchers: + patcher.stop() + self.wm.stop() + super().tearDown() + -- cgit v1.2.3 From 1d72880c097ea8259ce9cc63cfe55e6cc7516bd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Sat, 7 Apr 2018 23:23:10 +0200 Subject: Add acceptance tests Fixes https://git.immae.eu/mantisbt/view.php?id=42 (new scenario files still need to be added to improve coverage) --- tests/helper.py | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) (limited to 'tests/helper.py') diff --git a/tests/helper.py b/tests/helper.py index 4cf1b41..fcb0e9d 100644 --- a/tests/helper.py +++ b/tests/helper.py @@ -6,19 +6,9 @@ import requests_mock from io import StringIO import portfolio, market, main, store -__all__ = ["limits", "unittest", "WebMockTestCase", "mock", "D", +__all__ = ["unittest", "WebMockTestCase", "mock", "D", "StringIO"] -limits = ["acceptance", "unit"] -for test_type in limits: - if "--no{}".format(test_type) in sys.argv: - sys.argv.remove("--no{}".format(test_type)) - limits.remove(test_type) - if "--only{}".format(test_type) in sys.argv: - sys.argv.remove("--only{}".format(test_type)) - limits = [test_type] - break - class WebMockTestCase(unittest.TestCase): import time -- cgit v1.2.3