From 4f6f226b18e8442002ecb1d3a3ea4db63bc53241 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Mon, 9 Oct 2017 20:20:58 +0100 Subject: [PATCH] refactor asserts due to PYTHONOPTIMIZE flag --- CHANGELOG.md | 1 + lbrynet/conf.py | 8 ++++---- lbrynet/daemon/ExchangeRateManager.py | 6 ++++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d0a0de31..293096e51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ at anytime. * Announcing by head blob is turned on by default * Updated reflector server dns * Moved tests into the lbrynet package. + * Refactor some assert statements to accommodate the PYTHONOPTIMIZE flag set for Android. ### Added * Added WAL pragma to sqlite3 diff --git a/lbrynet/conf.py b/lbrynet/conf.py index 29f730f9b..35fb1fbf6 100644 --- a/lbrynet/conf.py +++ b/lbrynet/conf.py @@ -361,8 +361,8 @@ class Config(object): return name in self.get_valid_setting_names() def _assert_valid_setting(self, name): - assert self._is_valid_setting(name), \ - KeyError('{} is not a valid setting'.format(name)) + if not self._is_valid_setting(name): + raise AssertionError(KeyError('{} is not a valid setting'.format(name))) def _validate_settings(self, data): invalid_settings = set(data.keys()) - set(self.get_valid_setting_names()) @@ -371,8 +371,8 @@ class Config(object): def _assert_editable_setting(self, name): self._assert_valid_setting(name) - assert name not in self._fixed_defaults, \ - ValueError('{} is not an editable setting'.format(name)) + if name in self._fixed_defaults: + raise AssertionError(ValueError('{} is not an editable setting'.format(name))) def _validate_currency(self, currency): if currency not in self._fixed_defaults['CURRENCIES'].keys(): diff --git a/lbrynet/daemon/ExchangeRateManager.py b/lbrynet/daemon/ExchangeRateManager.py index 805df2db1..52fb1ab73 100644 --- a/lbrynet/daemon/ExchangeRateManager.py +++ b/lbrynet/daemon/ExchangeRateManager.py @@ -17,8 +17,10 @@ COINBASE_FEE = 0.0 #add fee class ExchangeRate(object): def __init__(self, market, spot, ts): - assert int(time.time()) - ts < 600 - assert spot > 0 + if not int(time.time()) - ts < 600: + raise AssertionError() + if not spot > 0: + raise AssertionError() self.currency_pair = (market[0:3], market[3:6]) self.spot = spot self.ts = ts