forked from LBRYCommunity/lbry-sdk
Merge branch 'android_tests_refactoring'
This commit is contained in:
commit
7ebfe77515
10 changed files with 46 additions and 20 deletions
|
@ -29,7 +29,8 @@ at anytime.
|
||||||
* Use the first port available for the peer and dht ports, starting with the provided values (defaults of 3333 and 4444). This allows multiple lbrynet instances in a LAN with UPnP.
|
* Use the first port available for the peer and dht ports, starting with the provided values (defaults of 3333 and 4444). This allows multiple lbrynet instances in a LAN with UPnP.
|
||||||
* Detect a UPnP redirect that didn't get cleaned up on a previous run and use it
|
* Detect a UPnP redirect that didn't get cleaned up on a previous run and use it
|
||||||
* Bumped jsonschema requirement to 2.6.0
|
* Bumped jsonschema requirement to 2.6.0
|
||||||
|
* Refactor some assert statements to accommodate the PYTHONOPTIMIZE flag set for Android.
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
|
|
@ -352,7 +352,8 @@ class Config(object):
|
||||||
return env_settings
|
return env_settings
|
||||||
|
|
||||||
def _assert_valid_data_type(self, data_type):
|
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):
|
def get_valid_setting_names(self):
|
||||||
return self._data[TYPE_DEFAULT].keys()
|
return self._data[TYPE_DEFAULT].keys()
|
||||||
|
@ -361,8 +362,8 @@ class Config(object):
|
||||||
return name in self.get_valid_setting_names()
|
return name in self.get_valid_setting_names()
|
||||||
|
|
||||||
def _assert_valid_setting(self, name):
|
def _assert_valid_setting(self, name):
|
||||||
assert self._is_valid_setting(name), \
|
if not self._is_valid_setting(name):
|
||||||
KeyError('{} is not a valid setting'.format(name))
|
raise KeyError('{} is not a valid setting'.format(name))
|
||||||
|
|
||||||
def _validate_settings(self, data):
|
def _validate_settings(self, data):
|
||||||
invalid_settings = set(data.keys()) - set(self.get_valid_setting_names())
|
invalid_settings = set(data.keys()) - set(self.get_valid_setting_names())
|
||||||
|
@ -371,8 +372,8 @@ class Config(object):
|
||||||
|
|
||||||
def _assert_editable_setting(self, name):
|
def _assert_editable_setting(self, name):
|
||||||
self._assert_valid_setting(name)
|
self._assert_valid_setting(name)
|
||||||
assert name not in self._fixed_defaults, \
|
if name in self._fixed_defaults:
|
||||||
ValueError('{} is not an editable setting'.format(name))
|
raise ValueError('{} is not an editable setting'.format(name))
|
||||||
|
|
||||||
def _validate_currency(self, currency):
|
def _validate_currency(self, currency):
|
||||||
if currency not in self._fixed_defaults['CURRENCIES'].keys():
|
if currency not in self._fixed_defaults['CURRENCIES'].keys():
|
||||||
|
|
|
@ -1231,7 +1231,7 @@ class Daemon(AuthJSONRPCServer):
|
||||||
)
|
)
|
||||||
|
|
||||||
return self._render_response({
|
return self._render_response({
|
||||||
'help': textwrap.dedent(fn.__doc__)
|
'help': textwrap.dedent(fn.__doc__ or '')
|
||||||
})
|
})
|
||||||
|
|
||||||
def jsonrpc_commands(self):
|
def jsonrpc_commands(self):
|
||||||
|
|
|
@ -17,8 +17,10 @@ COINBASE_FEE = 0.0 #add fee
|
||||||
|
|
||||||
class ExchangeRate(object):
|
class ExchangeRate(object):
|
||||||
def __init__(self, market, spot, ts):
|
def __init__(self, market, spot, ts):
|
||||||
assert int(time.time()) - ts < 600
|
if not int(time.time()) - ts < 600:
|
||||||
assert spot > 0
|
raise ValueError('The timestamp is too dated.')
|
||||||
|
if not spot > 0:
|
||||||
|
raise ValueError('Spot must be greater than 0.')
|
||||||
self.currency_pair = (market[0:3], market[3:6])
|
self.currency_pair = (market[0:3], market[3:6])
|
||||||
self.spot = spot
|
self.spot = spot
|
||||||
self.ts = ts
|
self.ts = ts
|
||||||
|
|
|
@ -33,7 +33,7 @@ from lbrynet.core.server.BlobRequestHandler import BlobRequestHandlerFactory
|
||||||
from lbrynet.core.server.ServerProtocol import ServerProtocolFactory
|
from lbrynet.core.server.ServerProtocol import ServerProtocolFactory
|
||||||
|
|
||||||
from lbrynet.tests import mocks
|
from lbrynet.tests import mocks
|
||||||
from lbrynet.tests.util import mk_db_and_blob_dir, rm_db_and_blob_dir
|
from lbrynet.tests.util import mk_db_and_blob_dir, rm_db_and_blob_dir, is_android
|
||||||
|
|
||||||
FakeNode = mocks.Node
|
FakeNode = mocks.Node
|
||||||
FakeWallet = mocks.Wallet
|
FakeWallet = mocks.Wallet
|
||||||
|
@ -490,6 +490,9 @@ class TestTransfer(TestCase):
|
||||||
|
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
@unittest.skipIf(is_android(),
|
||||||
|
'Test cannot pass on Android because multiprocessing '
|
||||||
|
'is not supported at the OS level.')
|
||||||
def test_lbry_transfer(self):
|
def test_lbry_transfer(self):
|
||||||
sd_hash_queue = Queue()
|
sd_hash_queue = Queue()
|
||||||
kill_event = Event()
|
kill_event = Event()
|
||||||
|
@ -577,6 +580,9 @@ class TestTransfer(TestCase):
|
||||||
|
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
@unittest.skipIf(is_android(),
|
||||||
|
'Test cannot pass on Android because multiprocessing '
|
||||||
|
'is not supported at the OS level.')
|
||||||
def test_last_blob_retrieval(self):
|
def test_last_blob_retrieval(self):
|
||||||
kill_event = Event()
|
kill_event = Event()
|
||||||
dead_event_1 = Event()
|
dead_event_1 = Event()
|
||||||
|
@ -659,6 +665,9 @@ class TestTransfer(TestCase):
|
||||||
d.addBoth(stop)
|
d.addBoth(stop)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
@unittest.skipIf(is_android(),
|
||||||
|
'Test cannot pass on Android because multiprocessing '
|
||||||
|
'is not supported at the OS level.')
|
||||||
def test_double_download(self):
|
def test_double_download(self):
|
||||||
sd_hash_queue = Queue()
|
sd_hash_queue = Queue()
|
||||||
kill_event = Event()
|
kill_event = Event()
|
||||||
|
|
|
@ -2,13 +2,15 @@ import StringIO
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
|
import unittest
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
from twisted.trial import unittest
|
from twisted import trial
|
||||||
|
|
||||||
from lbrynet.core import log_support
|
from lbrynet.core import log_support
|
||||||
|
from lbrynet.tests.util import is_android
|
||||||
|
|
||||||
|
|
||||||
class TestLogger(unittest.TestCase):
|
class TestLogger(trial.unittest.TestCase):
|
||||||
def raiseError(self):
|
def raiseError(self):
|
||||||
raise Exception('terrible things happened')
|
raise Exception('terrible things happened')
|
||||||
|
|
||||||
|
@ -26,12 +28,15 @@ class TestLogger(unittest.TestCase):
|
||||||
handler.setFormatter(logging.Formatter("%(filename)s:%(lineno)d - %(message)s"))
|
handler.setFormatter(logging.Formatter("%(filename)s:%(lineno)d - %(message)s"))
|
||||||
self.log.addHandler(handler)
|
self.log.addHandler(handler)
|
||||||
|
|
||||||
|
@unittest.skipIf(is_android(),
|
||||||
|
'Test cannot pass on Android because the tests package is compiled '
|
||||||
|
'which results in a different method call stack')
|
||||||
def test_can_log_failure(self):
|
def test_can_log_failure(self):
|
||||||
def output_lines():
|
def output_lines():
|
||||||
return self.stream.getvalue().split('\n')
|
return self.stream.getvalue().split('\n')
|
||||||
|
|
||||||
# the line number could change if this file gets refactored
|
# the line number could change if this file gets refactored
|
||||||
expected_first_line = 'test_log_support.py:18 - My message: terrible things happened'
|
expected_first_line = 'test_log_support.py:20 - My message: terrible things happened'
|
||||||
|
|
||||||
# testing the entirety of the message is futile as the
|
# testing the entirety of the message is futile as the
|
||||||
# traceback will depend on the system the test is being run on
|
# traceback will depend on the system the test is being run on
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
import mock
|
import mock
|
||||||
import json
|
import json
|
||||||
|
import unittest
|
||||||
|
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
from twisted.trial import unittest
|
from twisted import trial
|
||||||
|
|
||||||
from lbryschema.decode import smart_decode
|
from lbryschema.decode import smart_decode
|
||||||
from lbrynet import conf
|
from lbrynet import conf
|
||||||
|
@ -14,6 +15,8 @@ from lbrynet.tests.mocks import mock_conf_settings, FakeNetwork
|
||||||
from lbrynet.tests.mocks import BlobAvailabilityTracker as DummyBlobAvailabilityTracker
|
from lbrynet.tests.mocks import BlobAvailabilityTracker as DummyBlobAvailabilityTracker
|
||||||
from lbrynet.tests.mocks import ExchangeRateManager as DummyExchangeRateManager
|
from lbrynet.tests.mocks import ExchangeRateManager as DummyExchangeRateManager
|
||||||
from lbrynet.tests.mocks import BTCLBCFeed, USDBTCFeed
|
from lbrynet.tests.mocks import BTCLBCFeed, USDBTCFeed
|
||||||
|
from lbrynet.tests.util import is_android
|
||||||
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
logging.getLogger("lbryum").setLevel(logging.WARNING)
|
logging.getLogger("lbryum").setLevel(logging.WARNING)
|
||||||
|
@ -63,7 +66,7 @@ def get_test_daemon(data_rate=None, generous=True, with_fee=False):
|
||||||
return daemon
|
return daemon
|
||||||
|
|
||||||
|
|
||||||
class TestCostEst(unittest.TestCase):
|
class TestCostEst(trial.unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
mock_conf_settings(self)
|
mock_conf_settings(self)
|
||||||
util.resetTime(self)
|
util.resetTime(self)
|
||||||
|
@ -96,7 +99,7 @@ class TestCostEst(unittest.TestCase):
|
||||||
self.assertEquals(daemon.get_est_cost("test", size).result, correct_result)
|
self.assertEquals(daemon.get_est_cost("test", size).result, correct_result)
|
||||||
|
|
||||||
|
|
||||||
class TestJsonRpc(unittest.TestCase):
|
class TestJsonRpc(trial.unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
def noop():
|
def noop():
|
||||||
return None
|
return None
|
||||||
|
@ -112,6 +115,8 @@ class TestJsonRpc(unittest.TestCase):
|
||||||
d = defer.maybeDeferred(self.test_daemon.jsonrpc_status)
|
d = defer.maybeDeferred(self.test_daemon.jsonrpc_status)
|
||||||
d.addCallback(lambda status: self.assertDictContainsSubset({'is_running': False}, status))
|
d.addCallback(lambda status: self.assertDictContainsSubset({'is_running': False}, status))
|
||||||
|
|
||||||
|
@unittest.skipIf(is_android(),
|
||||||
|
'Test cannot pass on Android because PYTHONOPTIMIZE removes the docstrings.')
|
||||||
def test_help(self):
|
def test_help(self):
|
||||||
d = defer.maybeDeferred(self.test_daemon.jsonrpc_help, command='status')
|
d = defer.maybeDeferred(self.test_daemon.jsonrpc_help, command='status')
|
||||||
d.addCallback(lambda result: self.assertSubstring('daemon status', result['help']))
|
d.addCallback(lambda result: self.assertSubstring('daemon status', result['help']))
|
||||||
|
|
|
@ -35,9 +35,9 @@ class ExchangeRateTest(unittest.TestCase):
|
||||||
util.resetTime(self)
|
util.resetTime(self)
|
||||||
|
|
||||||
def test_invalid_rates(self):
|
def test_invalid_rates(self):
|
||||||
with self.assertRaises(AssertionError):
|
with self.assertRaises(ValueError):
|
||||||
ExchangeRateManager.ExchangeRate('USDBTC', 0, util.DEFAULT_ISO_TIME)
|
ExchangeRateManager.ExchangeRate('USDBTC', 0, util.DEFAULT_ISO_TIME)
|
||||||
with self.assertRaises(AssertionError):
|
with self.assertRaises(ValueError):
|
||||||
ExchangeRateManager.ExchangeRate('USDBTC', -1, util.DEFAULT_ISO_TIME)
|
ExchangeRateManager.ExchangeRate('USDBTC', -1, util.DEFAULT_ISO_TIME)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -39,12 +39,12 @@ class SettingsTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_invalid_setting_raises_exception(self):
|
def test_invalid_setting_raises_exception(self):
|
||||||
settings = self.get_mock_config_instance()
|
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):
|
def test_invalid_data_type_raises_exception(self):
|
||||||
settings = self.get_mock_config_instance()
|
settings = self.get_mock_config_instance()
|
||||||
self.assertIsNone(settings.set('test', 123))
|
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):
|
def test_setting_precedence(self):
|
||||||
settings = self.get_mock_config_instance()
|
settings = self.get_mock_config_instance()
|
||||||
|
|
|
@ -36,3 +36,6 @@ def resetTime(test_case, timestamp=DEFAULT_TIMESTAMP):
|
||||||
patcher = mock.patch('lbrynet.core.utils.utcnow')
|
patcher = mock.patch('lbrynet.core.utils.utcnow')
|
||||||
patcher.start().return_value = timestamp
|
patcher.start().return_value = timestamp
|
||||||
test_case.addCleanup(patcher.stop)
|
test_case.addCleanup(patcher.stop)
|
||||||
|
|
||||||
|
def is_android():
|
||||||
|
return 'ANDROID_ARGUMENT' in os.environ # detect Android using the Kivy way
|
||||||
|
|
Loading…
Reference in a new issue