def test_store_report(self):
file_open = mock.mock_open()
- with self.subTest(file=None), mock.patch("market.open", file_open):
- m = market.Market(self.ccxt, user_id=1)
+ m = market.Market(self.ccxt, user_id=1)
+ with self.subTest(file=None),\
+ mock.patch.object(m, "report") as report,\
+ mock.patch("market.open", file_open):
m.store_report()
+ report.merge.assert_called_with(store.Portfolio.report)
file_open.assert_not_called()
+ report.reset_mock()
file_open = mock.mock_open()
m = market.Market(self.ccxt, report_path="present", user_id=1)
with self.subTest(file="present"),\
file_open.assert_any_call("present/2018-02-25T00:00:00_1.json", "w")
file_open().write.assert_called_once_with("json_content")
m.report.to_json.assert_called_once_with()
+ report.merge.assert_called_with(store.Portfolio.report)
+
+ report.reset_mock()
m = market.Market(self.ccxt, report_path="error", user_id=1)
with self.subTest(file="error"),\
mock.patch("market.open") as file_open,\
+ mock.patch.object(m, "report") as report,\
mock.patch('sys.stdout', new_callable=StringIO) as stdout_mock:
file_open.side_effect = FileNotFoundError
m.store_report()
+ report.merge.assert_called_with(store.Portfolio.report)
self.assertRegex(stdout_mock.getvalue(), "impossible to store report file: FileNotFoundError;")
def test_print_orders(self):
report_store.set_verbose(False)
self.assertFalse(report_store.verbose_print)
+ def test_merge(self):
+ report_store1 = market.ReportStore(self.m, verbose_print=False)
+ report_store2 = market.ReportStore(None, verbose_print=False)
+
+ report_store2.log_stage("1")
+ report_store1.log_stage("2")
+ report_store2.log_stage("3")
+
+ report_store1.merge(report_store2)
+
+ self.assertEqual(3, len(report_store1.logs))
+ self.assertEqual(["1", "2", "3"], list(map(lambda x: x["stage"], report_store1.logs)))
+
def test_print_log(self):
report_store = market.ReportStore(self.m)
with self.subTest(verbose=True),\