From e522e7e7f7156169e7e052b42e35594459051771 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Tue, 17 Oct 2017 03:11:20 +0100 Subject: [PATCH] Changed AssertionError to ValueError. Skip tests that cannot pass on Android. --- lbrynet/daemon/ExchangeRateManager.py | 4 ++-- lbrynet/tests/functional/test_misc.py | 11 ++++++++++- lbrynet/tests/unit/core/test_log_support.py | 11 ++++++++--- lbrynet/tests/unit/lbrynet_daemon/test_Daemon.py | 11 ++++++++--- .../unit/lbrynet_daemon/test_ExchangeRateManager.py | 4 ++-- lbrynet/tests/util.py | 3 +++ 6 files changed, 33 insertions(+), 11 deletions(-) diff --git a/lbrynet/daemon/ExchangeRateManager.py b/lbrynet/daemon/ExchangeRateManager.py index 52fb1ab73..63298ed88 100644 --- a/lbrynet/daemon/ExchangeRateManager.py +++ b/lbrynet/daemon/ExchangeRateManager.py @@ -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 diff --git a/lbrynet/tests/functional/test_misc.py b/lbrynet/tests/functional/test_misc.py index 1fa2b2c26..d84d693cb 100644 --- a/lbrynet/tests/functional/test_misc.py +++ b/lbrynet/tests/functional/test_misc.py @@ -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() diff --git a/lbrynet/tests/unit/core/test_log_support.py b/lbrynet/tests/unit/core/test_log_support.py index cf7bdfc27..5f68c6272 100644 --- a/lbrynet/tests/unit/core/test_log_support.py +++ b/lbrynet/tests/unit/core/test_log_support.py @@ -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 diff --git a/lbrynet/tests/unit/lbrynet_daemon/test_Daemon.py b/lbrynet/tests/unit/lbrynet_daemon/test_Daemon.py index 0fffb7b4a..3a91c54b0 100644 --- a/lbrynet/tests/unit/lbrynet_daemon/test_Daemon.py +++ b/lbrynet/tests/unit/lbrynet_daemon/test_Daemon.py @@ -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'])) diff --git a/lbrynet/tests/unit/lbrynet_daemon/test_ExchangeRateManager.py b/lbrynet/tests/unit/lbrynet_daemon/test_ExchangeRateManager.py index c8695144c..9c82b449b 100644 --- a/lbrynet/tests/unit/lbrynet_daemon/test_ExchangeRateManager.py +++ b/lbrynet/tests/unit/lbrynet_daemon/test_ExchangeRateManager.py @@ -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) diff --git a/lbrynet/tests/util.py b/lbrynet/tests/util.py index ba3fc05c9..43cb007ea 100644 --- a/lbrynet/tests/util.py +++ b/lbrynet/tests/util.py @@ -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