Removes third-party mock dependency (#1661)

* Removes mock from setup.py dependencies
* Refactors name resetTime to reset_time
* Replaces import mock with built-in unittest.mock
* Refactors imports to separate built-in, external, and project modules
This commit is contained in:
Oleg Silkin 2018-11-25 10:12:30 -06:00 committed by Lex Berezhny
parent b3fde9d78d
commit f9ff3e5d14
11 changed files with 25 additions and 20 deletions

View file

@ -46,7 +46,6 @@ setup(
], ],
extras_require={ extras_require={
'test': ( 'test': (
'mock>=2.0,<3.0',
'faker==0.8.17', 'faker==0.8.17',
'pytest', 'pytest',
'pytest-asyncio', 'pytest-asyncio',

View file

@ -1,6 +1,6 @@
import base64 import base64
import io import io
import mock from unittest import mock
from cryptography.hazmat.backends import default_backend from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.asymmetric import rsa from cryptography.hazmat.primitives.asymmetric import rsa

View file

@ -3,7 +3,7 @@ import time
import os import os
import tempfile import tempfile
import shutil import shutil
import mock from unittest import mock
from binascii import hexlify from binascii import hexlify
@ -26,7 +26,7 @@ def random_lbry_hash():
return hexlify(os.urandom(48)).decode() return hexlify(os.urandom(48)).decode()
def resetTime(test_case, timestamp=DEFAULT_TIMESTAMP): def reset_time(test_case, timestamp=DEFAULT_TIMESTAMP):
iso_time = time.mktime(timestamp.timetuple()) iso_time = time.mktime(timestamp.timetuple())
patcher = mock.patch('time.time') patcher = mock.patch('time.time')
patcher.start().return_value = iso_time patcher.start().return_value = iso_time

View file

@ -1,6 +1,6 @@
from io import BytesIO from io import BytesIO
from unittest import mock
import mock
from twisted.internet import defer from twisted.internet import defer
from twisted.test import proto_helpers from twisted.test import proto_helpers
from twisted.trial import unittest from twisted.trial import unittest

View file

@ -1,4 +1,4 @@
from mock import MagicMock from unittest.mock import MagicMock
from twisted.trial import unittest from twisted.trial import unittest
from twisted.internet import defer from twisted.internet import defer

View file

@ -1,7 +1,9 @@
import itertools import itertools
from twisted.trial import unittest
import random import random
import mock from unittest import mock
from twisted.trial import unittest
from lbrynet.p2p.PaymentRateManager import NegotiatedPaymentRateManager, BasePaymentRateManager from lbrynet.p2p.PaymentRateManager import NegotiatedPaymentRateManager, BasePaymentRateManager
from lbrynet.p2p.Strategy import BasicAvailabilityWeightedStrategy from lbrynet.p2p.Strategy import BasicAvailabilityWeightedStrategy
from lbrynet.p2p.Offer import Offer from lbrynet.p2p.Offer import Offer

View file

@ -1,9 +1,10 @@
import mock from unittest import mock
from twisted.internet import reactor from twisted.internet import reactor
from twisted.trial import unittest from twisted.trial import unittest
from lbrynet import conf from lbrynet import conf
from lbrynet.extras.daemon.auth import server from lbrynet.extras.daemon.auth import server
from tests.mocks import mock_conf_settings from tests.mocks import mock_conf_settings

View file

@ -1,4 +1,4 @@
import mock from unittest import mock
import json import json
import random import random
from os import path from os import path
@ -13,7 +13,8 @@ from lbrynet.extras.daemon.storage import SQLiteStorage
from lbrynet.extras.daemon.ComponentManager import ComponentManager from lbrynet.extras.daemon.ComponentManager import ComponentManager
from lbrynet.extras.daemon.Components import DATABASE_COMPONENT, DHT_COMPONENT, WALLET_COMPONENT from lbrynet.extras.daemon.Components import DATABASE_COMPONENT, DHT_COMPONENT, WALLET_COMPONENT
from lbrynet.extras.daemon.Components import f2d from lbrynet.extras.daemon.Components import f2d
from lbrynet.extras.daemon.Components import HASH_ANNOUNCER_COMPONENT, REFLECTOR_COMPONENT, UPNP_COMPONENT, BLOB_COMPONENT from lbrynet.extras.daemon.Components import HASH_ANNOUNCER_COMPONENT, REFLECTOR_COMPONENT
from lbrynet.extras.daemon.Components import UPNP_COMPONENT, BLOB_COMPONENT
from lbrynet.extras.daemon.Components import PEER_PROTOCOL_SERVER_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT from lbrynet.extras.daemon.Components import PEER_PROTOCOL_SERVER_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT
from lbrynet.extras.daemon.Components import RATE_LIMITER_COMPONENT, HEADERS_COMPONENT, FILE_MANAGER_COMPONENT from lbrynet.extras.daemon.Components import RATE_LIMITER_COMPONENT, HEADERS_COMPONENT, FILE_MANAGER_COMPONENT
from lbrynet.extras.daemon.Daemon import Daemon as LBRYDaemon from lbrynet.extras.daemon.Daemon import Daemon as LBRYDaemon
@ -83,7 +84,7 @@ class TestCostEst(unittest.TestCase):
def setUp(self): def setUp(self):
mock_conf_settings(self) mock_conf_settings(self)
test_utils.resetTime(self) test_utils.reset_time(self)
@defer.inlineCallbacks @defer.inlineCallbacks
def test_fee_and_generous_data(self): def test_fee_and_generous_data(self):
@ -128,7 +129,7 @@ class TestJsonRpc(unittest.TestCase):
return None return None
mock_conf_settings(self) mock_conf_settings(self)
test_utils.resetTime(self) test_utils.reset_time(self)
self.test_daemon = get_test_daemon() self.test_daemon = get_test_daemon()
self.test_daemon.wallet_manager.is_first_run = False self.test_daemon.wallet_manager.is_first_run = False
self.test_daemon.wallet_manager.get_best_blockhash = noop self.test_daemon.wallet_manager.get_best_blockhash = noop
@ -150,7 +151,7 @@ class TestFileListSorting(unittest.TestCase):
def setUp(self): def setUp(self):
mock_conf_settings(self) mock_conf_settings(self)
test_utils.resetTime(self) test_utils.reset_time(self)
self.faker = Faker('en_US') self.faker = Faker('en_US')
self.faker.seed(129) # contains 3 same points paid (5.9) self.faker.seed(129) # contains 3 same points paid (5.9)
self.test_daemon = get_test_daemon() self.test_daemon = get_test_daemon()

View file

@ -1,5 +1,5 @@
import types import types
import mock from unittest import mock
from twisted.trial import unittest from twisted.trial import unittest
from twisted.internet import defer, task from twisted.internet import defer, task

View file

@ -32,7 +32,7 @@ class FeeFormatTest(unittest.TestCase):
class ExchangeRateTest(unittest.TestCase): class ExchangeRateTest(unittest.TestCase):
def setUp(self): def setUp(self):
test_utils.resetTime(self) test_utils.reset_time(self)
def test_invalid_rates(self): def test_invalid_rates(self):
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
@ -43,7 +43,7 @@ class ExchangeRateTest(unittest.TestCase):
class FeeTest(unittest.TestCase): class FeeTest(unittest.TestCase):
def setUp(self): def setUp(self):
test_utils.resetTime(self) test_utils.reset_time(self)
def test_fee_converts_to_lbc(self): def test_fee_converts_to_lbc(self):
fee = Fee({ fee = Fee({

View file

@ -1,9 +1,11 @@
from io import StringIO from io import StringIO
import logging import logging
import mock from unittest import mock
from unittest import skipIf from unittest import skipIf
from twisted.internet import defer from twisted.internet import defer
from twisted.trial import unittest from twisted.trial import unittest
from lbrynet import custom_logger from lbrynet import custom_logger
from tests.test_utils import is_android from tests.test_utils import is_android
@ -34,7 +36,7 @@ class TestLogger(unittest.TestCase):
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_customLogger.py:18 - My message: terrible things happened' expected_first_line = 'test_customLogger.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