X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2Ftest_main.py;h=d2f80297b37f6b499289944d723020e889e01be9;hb=4d597c5f302fc4621bc0950c5421dbe5309bef28;hp=6396c07728e3d01677962627e86e1add5203a947;hpb=c682bdf4a02a45312ef1aadf8aa26136cf308414;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FCryptoportfolio%2FTrader.git diff --git a/tests/test_main.py b/tests/test_main.py index 6396c07..d2f8029 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -179,7 +179,8 @@ class MainTest(WebMockTestCase): mock.patch("main.parse_config") as parse_config,\ mock.patch("main.fetch_markets") as fetch_markets,\ mock.patch("main.process") as process,\ - mock.patch("store.Portfolio.start_worker") as start: + mock.patch("store.Portfolio.start_worker") as start,\ + mock.patch("store.Portfolio.stop_worker") as stop: args_mock = mock.Mock() args_mock.parallel = True @@ -196,6 +197,7 @@ class MainTest(WebMockTestCase): parse_config.assert_called_with(args_mock) fetch_markets.assert_called_with("pg_config", "user") + stop.assert_called_once_with() start.assert_called_once_with() self.assertEqual(2, process.call_count) process.assert_has_calls([ @@ -204,6 +206,48 @@ class MainTest(WebMockTestCase): mock.call.__bool__(), mock.call("config2", 1, 2, args_mock, "pg_config"), ]) + with self.subTest(quiet=True): + with mock.patch("main.parse_args") as parse_args,\ + mock.patch("main.parse_config") as parse_config,\ + mock.patch("main.fetch_markets") as fetch_markets,\ + mock.patch("store.Portfolio.report") as report,\ + mock.patch("main.process") as process: + + args_mock = mock.Mock() + args_mock.parallel = False + args_mock.quiet = True + args_mock.user = "user" + parse_args.return_value = args_mock + + parse_config.return_value = "pg_config" + + fetch_markets.return_value = [[3, "config1", 1], [1, "config2", 2]] + + main.main(["Foo", "Bar"]) + + report.set_verbose.assert_called_once_with(False) + + with self.subTest(quiet=False): + with mock.patch("main.parse_args") as parse_args,\ + mock.patch("main.parse_config") as parse_config,\ + mock.patch("main.fetch_markets") as fetch_markets,\ + mock.patch("store.Portfolio.report") as report,\ + mock.patch("main.process") as process: + + args_mock = mock.Mock() + args_mock.parallel = False + args_mock.quiet = False + args_mock.user = "user" + parse_args.return_value = args_mock + + parse_config.return_value = "pg_config" + + fetch_markets.return_value = [[3, "config1", 1], [1, "config2", 2]] + + main.main(["Foo", "Bar"]) + + report.set_verbose.assert_called_once_with(True) + @mock.patch.object(main.sys, "exit") @mock.patch("main.os")