@mock.patch("market.ReportStore.log_error")
@mock.patch("market.Market.store_report")
def test_process(self, store_report, log_error, process):
- m = market.Market(self.ccxt, self.market_args())
+ m = market.Market(self.ccxt, self.market_args(), options={"foo": "bar"})
with self.subTest(actions=[], before=False, after=False):
m.process([])
with self.subTest(before=True, after=False):
m.process(["foo"], before=True)
- process.assert_called_once_with("foo", steps="before")
+ process.assert_called_once_with("foo", options={"foo": "bar"}, steps="before")
store_report.assert_called_once()
log_error.assert_not_called()
with self.subTest(before=False, after=True):
m.process(["sell_all"], after=True)
- process.assert_called_once_with("sell_all", steps="after")
+ process.assert_called_once_with("sell_all", options={"foo": "bar"}, steps="after")
store_report.assert_called_once()
log_error.assert_not_called()
with self.subTest(before=False, after=False):
m.process(["foo"])
- process.assert_called_once_with("foo", steps="all")
+ process.assert_called_once_with("foo", options={"foo": "bar"}, steps="all")
store_report.assert_called_once()
log_error.assert_not_called()
with self.subTest(before=True, after=True):
m.process(["sell_all"], before=True, after=True)
- process.assert_called_once_with("sell_all", steps="all")
+ process.assert_called_once_with("sell_all", options={"foo": "bar"}, steps="all")
store_report.assert_called_once()
log_error.assert_not_called()
with self.subTest("nominal case"):
processor = market.Processor(self.m)
- processor.process("sell_all", foo="bar")
+ processor.process("sell_all", options="bar")
self.assertEqual(3, process_step.call_count)
steps = list(map(lambda x: x[1][1]["name"], process_step.mock_calls))
kwargs = list(map(lambda x: x[1][2], process_step.mock_calls))
self.assertEqual(["all_sell", "wait", "all_buy"], steps)
self.assertEqual(["sell_all", "sell_all", "sell_all"], scenario_names)
- self.assertEqual([{"foo":"bar"}, {"foo":"bar"}, {"foo":"bar"}], kwargs)
+ self.assertEqual(["bar", "bar", "bar"], kwargs)
process_step.reset_mock()
method_mock = mock.Mock()
method_arguments.return_value = [
method_mock,
- ["foo2", "foo", "foo3"]
+ ["foo2", "foo"]
]
- self.m.options = { "foo3": "coucou"}
method, args = processor.parse_args("action", {"foo": "bar", "foo2": "bar"}, {"foo": "bar2", "bla": "bla"})
self.assertEqual(method_mock, method)
- self.assertEqual({"foo": "bar2", "foo2": "bar", "foo3": "coucou"}, args)
+ self.assertEqual({"foo": "bar2", "foo2": "bar"}, args)
with mock.patch.object(processor, "method_arguments") as method_arguments:
method_mock = mock.Mock()