aboutsummaryrefslogtreecommitdiff
path: root/test.py
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2018-03-12 02:54:54 +0100
committerIsmaël Bouya <ismael.bouya@normalesup.org>2018-03-12 02:54:54 +0100
commitb53f483d54367875bed3769d2e4817866fbde224 (patch)
tree25a045b1f77fc36e3bb794ed72dbf02406377a00 /test.py
parent83c698c925db9dcb2d347c2a625de88d85cfeb21 (diff)
parent718e3e919acb9b57269d3155543f9e8ad1b91324 (diff)
downloadTrader-b53f483d54367875bed3769d2e4817866fbde224.tar.gz
Trader-b53f483d54367875bed3769d2e4817866fbde224.tar.zst
Trader-b53f483d54367875bed3769d2e4817866fbde224.zip
Merge branch 'immae/store_logs' into dev
Diffstat (limited to 'test.py')
-rw-r--r--test.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/test.py b/test.py
index ac9a6cd..13bd332 100644
--- a/test.py
+++ b/test.py
@@ -1395,12 +1395,15 @@ class MarketTest(WebMockTestCase):
1395 mock.patch.object(market, "datetime") as time_mock: 1395 mock.patch.object(market, "datetime") as time_mock:
1396 1396
1397 time_mock.now.return_value = datetime.datetime(2018, 2, 25) 1397 time_mock.now.return_value = datetime.datetime(2018, 2, 25)
1398 report.print_logs = [[time_mock.now(), "Foo"], [time_mock.now(), "Bar"]]
1398 report.to_json.return_value = "json_content" 1399 report.to_json.return_value = "json_content"
1399 1400
1400 m.store_report() 1401 m.store_report()
1401 1402
1402 file_open.assert_any_call("present/2018-02-25T00:00:00_1.json", "w") 1403 file_open.assert_any_call("present/2018-02-25T00:00:00_1.json", "w")
1403 file_open().write.assert_called_once_with("json_content") 1404 file_open.assert_any_call("present/2018-02-25T00:00:00_1.log", "w")
1405 file_open().write.assert_any_call("json_content")
1406 file_open().write.assert_any_call("Foo\nBar")
1404 m.report.to_json.assert_called_once_with() 1407 m.report.to_json.assert_called_once_with()
1405 report.merge.assert_called_with(store.Portfolio.report) 1408 report.merge.assert_called_with(store.Portfolio.report)
1406 1409
@@ -3016,15 +3019,18 @@ class ReportStoreTest(WebMockTestCase):
3016 3019
3017 self.assertEqual(3, len(report_store1.logs)) 3020 self.assertEqual(3, len(report_store1.logs))
3018 self.assertEqual(["1", "2", "3"], list(map(lambda x: x["stage"], report_store1.logs))) 3021 self.assertEqual(["1", "2", "3"], list(map(lambda x: x["stage"], report_store1.logs)))
3022 self.assertEqual(6, len(report_store1.print_logs))
3019 3023
3020 def test_print_log(self): 3024 def test_print_log(self):
3021 report_store = market.ReportStore(self.m) 3025 report_store = market.ReportStore(self.m)
3022 with self.subTest(verbose=True),\ 3026 with self.subTest(verbose=True),\
3027 mock.patch.object(store, "datetime") as time_mock,\
3023 mock.patch('sys.stdout', new_callable=StringIO) as stdout_mock: 3028 mock.patch('sys.stdout', new_callable=StringIO) as stdout_mock:
3029 time_mock.now.return_value = datetime.datetime(2018, 2, 25, 2, 20, 10)
3024 report_store.set_verbose(True) 3030 report_store.set_verbose(True)
3025 report_store.print_log("Coucou") 3031 report_store.print_log("Coucou")
3026 report_store.print_log(portfolio.Amount("BTC", 1)) 3032 report_store.print_log(portfolio.Amount("BTC", 1))
3027 self.assertEqual(stdout_mock.getvalue(), "Coucou\n1.00000000 BTC\n") 3033 self.assertEqual(stdout_mock.getvalue(), "2018-02-25 02:20:10: Coucou\n2018-02-25 02:20:10: 1.00000000 BTC\n")
3028 3034
3029 with self.subTest(verbose=False),\ 3035 with self.subTest(verbose=False),\
3030 mock.patch('sys.stdout', new_callable=StringIO) as stdout_mock: 3036 mock.patch('sys.stdout', new_callable=StringIO) as stdout_mock: