Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android tests refactoring #940

Merged
merged 6 commits into from
Oct 25, 2017
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions lbrynet/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,8 @@ def _parse_environment(environment):
return env_settings

def _assert_valid_data_type(self, data_type):
assert data_type in self._data, KeyError('{} in is not a valid data type'.format(data_type))
if not data_type in self._data:
raise KeyError('{} in is not a valid data type'.format(data_type))

def get_valid_setting_names(self):
return self._data[TYPE_DEFAULT].keys()
Expand All @@ -361,8 +362,8 @@ def _is_valid_setting(self, name):
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 KeyError('{} is not a valid setting'.format(name))

def _validate_settings(self, data):
invalid_settings = set(data.keys()) - set(self.get_valid_setting_names())
Expand All @@ -371,8 +372,8 @@ def _validate_settings(self, data):

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 ValueError('{} is not an editable setting'.format(name))

def _validate_currency(self, currency):
if currency not in self._fixed_defaults['CURRENCIES'].keys():
Expand Down
2 changes: 1 addition & 1 deletion lbrynet/daemon/Daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,7 @@ def jsonrpc_help(self, command=None):
)

return self._render_response({
'help': textwrap.dedent(fn.__doc__)
'help': textwrap.dedent(fn.__doc__ or '')
})

def jsonrpc_commands(self):
Expand Down
6 changes: 4 additions & 2 deletions lbrynet/daemon/ExchangeRateManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@

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])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might as well make these of type ValueError for clarity (first is because timestamp is too dated, second is because spot must be more than 0)

self.spot = spot
self.ts = ts
Expand Down
4 changes: 2 additions & 2 deletions lbrynet/tests/unit/test_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ def test_setting_is_in_dict(self):

def test_invalid_setting_raises_exception(self):
settings = self.get_mock_config_instance()
self.assertRaises(AssertionError, settings.set, 'invalid_name', 123)
self.assertRaises(KeyError, settings.set, 'invalid_name', 123)

def test_invalid_data_type_raises_exception(self):
settings = self.get_mock_config_instance()
self.assertIsNone(settings.set('test', 123))
self.assertRaises(AssertionError, settings.set, 'test', 123, ('fake_data_type',))
self.assertRaises(KeyError, settings.set, 'test', 123, ('fake_data_type',))

def test_setting_precedence(self):
settings = self.get_mock_config_instance()
Expand Down