Changed AssertionError to ValueError. Skip tests that cannot pass on Android.

This commit is contained in:
Akinwale Ariwodola 2017-10-17 03:11:20 +01:00
parent 0291482abb
commit e522e7e7f7
6 changed files with 33 additions and 11 deletions

View file

@ -18,9 +18,9 @@ COINBASE_FEE = 0.0 #add fee
class ExchangeRate(object):
def __init__(self, market, spot, ts):
if not int(time.time()) - ts < 600:
raise AssertionError()
raise ValueError('The timestamp is too dated.')
if not spot > 0:
raise AssertionError()
raise ValueError('Spot must be greater than 0.')
self.currency_pair = (market[0:3], market[3:6])
self.spot = spot
self.ts = ts

View file

@ -33,7 +33,7 @@ from lbrynet.core.server.BlobRequestHandler import BlobRequestHandlerFactory
from lbrynet.core.server.ServerProtocol import ServerProtocolFactory
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
FakeWallet = mocks.Wallet
@ -487,6 +487,9 @@ class TestTransfer(TestCase):
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):
sd_hash_queue = Queue()
kill_event = Event()
@ -574,6 +577,9 @@ class TestTransfer(TestCase):
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):
kill_event = Event()
dead_event_1 = Event()
@ -656,6 +662,9 @@ class TestTransfer(TestCase):
d.addBoth(stop)
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):
sd_hash_queue = Queue()
kill_event = Event()

View file

@ -2,13 +2,15 @@ import StringIO
import logging
import mock
import unittest
from twisted.internet import defer
from twisted.trial import unittest
from twisted import trial
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):
raise Exception('terrible things happened')
@ -26,12 +28,15 @@ class TestLogger(unittest.TestCase):
handler.setFormatter(logging.Formatter("%(filename)s:%(lineno)d - %(message)s"))
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 output_lines():
return self.stream.getvalue().split('\n')
# 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
# traceback will depend on the system the test is being run on

View file

@ -1,8 +1,9 @@
import mock
import json
import unittest
from twisted.internet import defer
from twisted.trial import unittest
from twisted import trial
from lbryschema.decode import smart_decode
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 ExchangeRateManager as DummyExchangeRateManager
from lbrynet.tests.mocks import BTCLBCFeed, USDBTCFeed
from lbrynet.tests.util import is_android
def get_test_daemon(data_rate=None, generous=True, with_fee=False):
if data_rate is None:
@ -59,7 +62,7 @@ def get_test_daemon(data_rate=None, generous=True, with_fee=False):
return daemon
class TestCostEst(unittest.TestCase):
class TestCostEst(trial.unittest.TestCase):
def setUp(self):
mock_conf_settings(self)
util.resetTime(self)
@ -93,7 +96,7 @@ class TestCostEst(unittest.TestCase):
self.assertEquals(daemon.get_est_cost("test", size).result, correct_result)
class TestJsonRpc(unittest.TestCase):
class TestJsonRpc(trial.unittest.TestCase):
def setUp(self):
def noop():
return None
@ -109,6 +112,8 @@ class TestJsonRpc(unittest.TestCase):
d = defer.maybeDeferred(self.test_daemon.jsonrpc_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):
d = defer.maybeDeferred(self.test_daemon.jsonrpc_help, command='status')
d.addCallback(lambda result: self.assertSubstring('daemon status', result['help']))

View file

@ -35,9 +35,9 @@ class ExchangeRateTest(unittest.TestCase):
util.resetTime(self)
def test_invalid_rates(self):
with self.assertRaises(AssertionError):
with self.assertRaises(ValueError):
ExchangeRateManager.ExchangeRate('USDBTC', 0, util.DEFAULT_ISO_TIME)
with self.assertRaises(AssertionError):
with self.assertRaises(ValueError):
ExchangeRateManager.ExchangeRate('USDBTC', -1, util.DEFAULT_ISO_TIME)

View file

@ -36,3 +36,6 @@ def resetTime(test_case, timestamp=DEFAULT_TIMESTAMP):
patcher = mock.patch('lbrynet.core.utils.utcnow')
patcher.start().return_value = timestamp
test_case.addCleanup(patcher.stop)
def is_android():
return 'ANDROID_ARGUMENT' in os.environ # detect Android using the Kivy way