aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2018-04-04 12:02:13 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2018-04-04 12:38:28 +0200
commit90d7423eec074a0ed0af680c223180f8d7e1d4e6 (patch)
tree9180ce9db30705eeea1d0139c0f580d5b09e15e7
parent341a4b07e8c205711fff0e93dd3679708828a961 (diff)
downloadTrader-90d7423eec074a0ed0af680c223180f8d7e1d4e6.tar.gz
Trader-90d7423eec074a0ed0af680c223180f8d7e1d4e6.tar.zst
Trader-90d7423eec074a0ed0af680c223180f8d7e1d4e6.zip
Add logging at market instance creation
-rw-r--r--.gitattributes2
-rw-r--r--market.py3
-rw-r--r--store.py11
-rw-r--r--test.py22
4 files changed, 38 insertions, 0 deletions
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..227f825
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,2 @@
1*.py diff=python
2/store.py export-subst
diff --git a/market.py b/market.py
index ac3aa14..10d1ad8 100644
--- a/market.py
+++ b/market.py
@@ -28,6 +28,9 @@ class Market:
28 for key in ["user_id", "market_id", "report_path", "pg_config"]: 28 for key in ["user_id", "market_id", "report_path", "pg_config"]:
29 setattr(self, key, kwargs.get(key, None)) 29 setattr(self, key, kwargs.get(key, None))
30 30
31 self.report.log_market(self.args, self.user_id, self.market_id,
32 self.report_path, self.debug)
33
31 @classmethod 34 @classmethod
32 def from_config(cls, config, args, **kwargs): 35 def from_config(cls, config, args, **kwargs):
33 config["apiKey"] = config.pop("key", None) 36 config["apiKey"] = config.pop("key", None)
diff --git a/store.py b/store.py
index b3ada45..2b5c18a 100644
--- a/store.py
+++ b/store.py
@@ -209,6 +209,17 @@ class ReportStore:
209 "action": action, 209 "action": action,
210 }) 210 })
211 211
212 def log_market(self, args, user_id, market_id, report_path, debug):
213 self.add_log({
214 "type": "market",
215 "commit": "$Format:%H$",
216 "args": vars(args),
217 "user_id": user_id,
218 "market_id": market_id,
219 "report_path": report_path,
220 "debug": debug,
221 })
222
212class BalanceStore: 223class BalanceStore:
213 def __init__(self, market): 224 def __init__(self, market):
214 self.market = market 225 self.market = market
diff --git a/test.py b/test.py
index a9a80c5..29403d4 100644
--- a/test.py
+++ b/test.py
@@ -1181,9 +1181,12 @@ class MarketTest(WebMockTestCase):
1181 with self.subTest(quiet=False): 1181 with self.subTest(quiet=False):
1182 m = market.Market(self.ccxt, self.market_args(quiet=False)) 1182 m = market.Market(self.ccxt, self.market_args(quiet=False))
1183 report_store.assert_called_with(m, verbose_print=True) 1183 report_store.assert_called_with(m, verbose_print=True)
1184 report_store().log_market.assert_called_once()
1185 report_store.reset_mock()
1184 with self.subTest(quiet=True): 1186 with self.subTest(quiet=True):
1185 m = market.Market(self.ccxt, self.market_args(quiet=True)) 1187 m = market.Market(self.ccxt, self.market_args(quiet=True))
1186 report_store.assert_called_with(m, verbose_print=False) 1188 report_store.assert_called_with(m, verbose_print=False)
1189 report_store().log_market.assert_called_once()
1187 1190
1188 @mock.patch("market.ccxt") 1191 @mock.patch("market.ccxt")
1189 def test_from_config(self, ccxt): 1192 def test_from_config(self, ccxt):
@@ -4346,6 +4349,25 @@ class ReportStoreTest(WebMockTestCase):
4346 'response': 'Hey' 4349 'response': 'Hey'
4347 }) 4350 })
4348 4351
4352 @mock.patch.object(market.ReportStore, "add_log")
4353 def test_log_market(self, add_log):
4354 report_store = market.ReportStore(self.m)
4355 class Args:
4356 def __init__(self):
4357 self.debug = True
4358 self.quiet = False
4359
4360 report_store.log_market(Args(), 4, 1, "report", True)
4361 add_log.assert_called_once_with({
4362 "type": "market",
4363 "commit": "$Format:%H$",
4364 "args": { "debug": True, "quiet": False },
4365 "user_id": 4,
4366 "market_id": 1,
4367 "report_path": "report",
4368 "debug": True
4369 })
4370
4349 @mock.patch.object(market.ReportStore, "print_log") 4371 @mock.patch.object(market.ReportStore, "print_log")
4350 @mock.patch.object(market.ReportStore, "add_log") 4372 @mock.patch.object(market.ReportStore, "add_log")
4351 def test_log_error(self, add_log, print_log): 4373 def test_log_error(self, add_log, print_log):