aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2018-08-04 20:33:16 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2018-08-04 20:33:16 +0200
commit445185355d0d13d8d7251fa9add8e249c5361aa7 (patch)
treefd139a1304dbb0bdb56a5019bc916dd2c6565a3c /tests
parentef8fa5e5454a17c49fe14f6a2c1cffa9cd985bdb (diff)
downloadTrader-445185355d0d13d8d7251fa9add8e249c5361aa7.tar.gz
Trader-445185355d0d13d8d7251fa9add8e249c5361aa7.tar.zst
Trader-445185355d0d13d8d7251fa9add8e249c5361aa7.zip
Refactor a bit the options passing process
Diffstat (limited to 'tests')
-rw-r--r--tests/test_market.py19
1 files changed, 9 insertions, 10 deletions
diff --git a/tests/test_market.py b/tests/test_market.py
index aeb9f8e..49d159c 100644
--- a/tests/test_market.py
+++ b/tests/test_market.py
@@ -883,7 +883,7 @@ class MarketTest(WebMockTestCase):
883 @mock.patch("market.ReportStore.log_error") 883 @mock.patch("market.ReportStore.log_error")
884 @mock.patch("market.Market.store_report") 884 @mock.patch("market.Market.store_report")
885 def test_process(self, store_report, log_error, process): 885 def test_process(self, store_report, log_error, process):
886 m = market.Market(self.ccxt, self.market_args()) 886 m = market.Market(self.ccxt, self.market_args(), options={"foo": "bar"})
887 with self.subTest(actions=[], before=False, after=False): 887 with self.subTest(actions=[], before=False, after=False):
888 m.process([]) 888 m.process([])
889 889
@@ -897,7 +897,7 @@ class MarketTest(WebMockTestCase):
897 with self.subTest(before=True, after=False): 897 with self.subTest(before=True, after=False):
898 m.process(["foo"], before=True) 898 m.process(["foo"], before=True)
899 899
900 process.assert_called_once_with("foo", steps="before") 900 process.assert_called_once_with("foo", options={"foo": "bar"}, steps="before")
901 store_report.assert_called_once() 901 store_report.assert_called_once()
902 log_error.assert_not_called() 902 log_error.assert_not_called()
903 903
@@ -907,7 +907,7 @@ class MarketTest(WebMockTestCase):
907 with self.subTest(before=False, after=True): 907 with self.subTest(before=False, after=True):
908 m.process(["sell_all"], after=True) 908 m.process(["sell_all"], after=True)
909 909
910 process.assert_called_once_with("sell_all", steps="after") 910 process.assert_called_once_with("sell_all", options={"foo": "bar"}, steps="after")
911 store_report.assert_called_once() 911 store_report.assert_called_once()
912 log_error.assert_not_called() 912 log_error.assert_not_called()
913 913
@@ -917,7 +917,7 @@ class MarketTest(WebMockTestCase):
917 with self.subTest(before=False, after=False): 917 with self.subTest(before=False, after=False):
918 m.process(["foo"]) 918 m.process(["foo"])
919 919
920 process.assert_called_once_with("foo", steps="all") 920 process.assert_called_once_with("foo", options={"foo": "bar"}, steps="all")
921 store_report.assert_called_once() 921 store_report.assert_called_once()
922 log_error.assert_not_called() 922 log_error.assert_not_called()
923 923
@@ -927,7 +927,7 @@ class MarketTest(WebMockTestCase):
927 with self.subTest(before=True, after=True): 927 with self.subTest(before=True, after=True):
928 m.process(["sell_all"], before=True, after=True) 928 m.process(["sell_all"], before=True, after=True)
929 929
930 process.assert_called_once_with("sell_all", steps="all") 930 process.assert_called_once_with("sell_all", options={"foo": "bar"}, steps="all")
931 store_report.assert_called_once() 931 store_report.assert_called_once()
932 log_error.assert_not_called() 932 log_error.assert_not_called()
933 933
@@ -1010,7 +1010,7 @@ class ProcessorTest(WebMockTestCase):
1010 with self.subTest("nominal case"): 1010 with self.subTest("nominal case"):
1011 processor = market.Processor(self.m) 1011 processor = market.Processor(self.m)
1012 1012
1013 processor.process("sell_all", foo="bar") 1013 processor.process("sell_all", options="bar")
1014 self.assertEqual(3, process_step.call_count) 1014 self.assertEqual(3, process_step.call_count)
1015 1015
1016 steps = list(map(lambda x: x[1][1]["name"], process_step.mock_calls)) 1016 steps = list(map(lambda x: x[1][1]["name"], process_step.mock_calls))
@@ -1018,7 +1018,7 @@ class ProcessorTest(WebMockTestCase):
1018 kwargs = list(map(lambda x: x[1][2], process_step.mock_calls)) 1018 kwargs = list(map(lambda x: x[1][2], process_step.mock_calls))
1019 self.assertEqual(["all_sell", "wait", "all_buy"], steps) 1019 self.assertEqual(["all_sell", "wait", "all_buy"], steps)
1020 self.assertEqual(["sell_all", "sell_all", "sell_all"], scenario_names) 1020 self.assertEqual(["sell_all", "sell_all", "sell_all"], scenario_names)
1021 self.assertEqual([{"foo":"bar"}, {"foo":"bar"}, {"foo":"bar"}], kwargs) 1021 self.assertEqual(["bar", "bar", "bar"], kwargs)
1022 1022
1023 process_step.reset_mock() 1023 process_step.reset_mock()
1024 1024
@@ -1126,13 +1126,12 @@ class ProcessorTest(WebMockTestCase):
1126 method_mock = mock.Mock() 1126 method_mock = mock.Mock()
1127 method_arguments.return_value = [ 1127 method_arguments.return_value = [
1128 method_mock, 1128 method_mock,
1129 ["foo2", "foo", "foo3"] 1129 ["foo2", "foo"]
1130 ] 1130 ]
1131 self.m.options = { "foo3": "coucou"}
1132 method, args = processor.parse_args("action", {"foo": "bar", "foo2": "bar"}, {"foo": "bar2", "bla": "bla"}) 1131 method, args = processor.parse_args("action", {"foo": "bar", "foo2": "bar"}, {"foo": "bar2", "bla": "bla"})
1133 1132
1134 self.assertEqual(method_mock, method) 1133 self.assertEqual(method_mock, method)
1135 self.assertEqual({"foo": "bar2", "foo2": "bar", "foo3": "coucou"}, args) 1134 self.assertEqual({"foo": "bar2", "foo2": "bar"}, args)
1136 1135
1137 with mock.patch.object(processor, "method_arguments") as method_arguments: 1136 with mock.patch.object(processor, "method_arguments") as method_arguments:
1138 method_mock = mock.Mock() 1137 method_mock = mock.Mock()