pylint and unit test fixes

This commit is contained in:
Lex Berezhny 2018-07-04 23:16:52 -04:00 committed by Jack Robison
parent d5beaa0937
commit 69446491b8
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
32 changed files with 84 additions and 112 deletions

View file

@ -1,7 +1,5 @@
import logging
from zope.interface import implements
from lbrynet.interfaces import IRateLimiter
from twisted.internet import task

View file

@ -5,13 +5,11 @@ from decimal import Decimal
from twisted.internet import defer
from twisted.python.failure import Failure
from twisted.internet.error import ConnectionAborted
from zope.interface import implements
from lbrynet.core.Error import ConnectionClosedBeforeResponseError
from lbrynet.core.Error import InvalidResponseError, RequestCanceledError, NoResponseError
from lbrynet.core.Error import PriceDisagreementError, DownloadCanceledError, InsufficientFundsError
from lbrynet.core.client.ClientRequest import ClientRequest, ClientBlobRequest
from lbrynet.interfaces import IRequestCreator
from lbrynet.core.Offer import Offer

View file

@ -10,8 +10,6 @@ from lbrynet.core import utils
from lbrynet.core.Error import ConnectionClosedBeforeResponseError, NoResponseError
from lbrynet.core.Error import DownloadCanceledError, MisbehavingPeerError
from lbrynet.core.Error import RequestCanceledError
from lbrynet.interfaces import IRequestSender, IRateLimited
from zope.interface import implements
log = logging.getLogger(__name__)

View file

@ -1,8 +1,6 @@
import random
import logging
from twisted.internet import defer, reactor
from zope.interface import implements
from lbrynet import interfaces
from lbrynet import conf
from lbrynet.core.client.ClientProtocol import ClientProtocolFactory
from lbrynet.core.Error import InsufficientFundsError

View file

@ -1,7 +1,5 @@
import logging
from twisted.internet import defer
from zope.interface import implements
from lbrynet import interfaces
log = logging.getLogger(__name__)

View file

@ -1,6 +1,4 @@
import logging
from zope.interface import implements
from lbrynet import interfaces
from lbrynet.core.BlobInfo import BlobInfo
from lbrynet.core.client.BlobRequester import BlobRequester
from lbrynet.core.client.ConnectionManager import ConnectionManager

View file

@ -1,7 +1,5 @@
import logging
from lbrynet.interfaces import IProgressManager
from twisted.internet import defer
from zope.interface import implements
log = logging.getLogger(__name__)

View file

@ -3,11 +3,9 @@ import logging
from twisted.internet import defer
from twisted.protocols.basic import FileSender
from twisted.python.failure import Failure
from zope.interface import implements
from lbrynet import analytics
from lbrynet.core.Offer import Offer
from lbrynet.interfaces import IQueryHandlerFactory, IQueryHandler, IBlobSender
log = logging.getLogger(__name__)

View file

@ -1,8 +1,7 @@
import logging
from twisted.internet import interfaces, error
from twisted.internet import error
from twisted.internet.protocol import Protocol, ServerFactory
from twisted.python import failure
from zope.interface import implements
from lbrynet.core.server.ServerRequestHandler import ServerRequestHandler

View file

@ -1,8 +1,6 @@
import json
import logging
from twisted.internet import interfaces, defer
from zope.interface import implements
from lbrynet.interfaces import IRequestHandler
from twisted.internet import defer
log = logging.getLogger(__name__)

View file

@ -1,9 +1,11 @@
from __future__ import print_function
import platform
import json
import subprocess
import os
from six.moves.urllib.request import urlopen
from six.moves.urllib import request
from six.moves.urllib.error import URLError
from lbryschema import __version__ as lbryschema_version
from lbrynet import build_type, __version__ as lbrynet_version
@ -43,7 +45,7 @@ def get_platform(get_ip=True):
# TODO: remove this from get_platform and add a get_external_ip function using treq
if get_ip:
try:
response = json.loads(urlopen("https://api.lbry.io/ip").read())
response = json.loads(request.urlopen("https://api.lbry.io/ip").read())
if not response['success']:
raise URLError("failed to get external ip")
p['ip'] = response['data']['ip']

View file

@ -5,8 +5,7 @@ import os
import logging
from cryptography.hazmat.primitives.ciphers.algorithms import AES
from twisted.internet import interfaces, defer
from zope.interface import implements
from twisted.internet import defer
from lbrynet.cryptstream.CryptBlob import CryptStreamBlobMaker

View file

@ -1,8 +1,6 @@
import binascii
from zope.interface import implements
from twisted.internet import defer
from lbrynet.cryptstream.CryptBlob import StreamBlobDecryptor
from lbrynet.interfaces import IBlobHandler
class CryptBlobHandler(object):

View file

@ -1,7 +1,5 @@
import binascii
import logging
from zope.interface import implements
from lbrynet.interfaces import IStreamDownloader
from lbrynet.core.client.BlobRequester import BlobRequester
from lbrynet.core.client.ConnectionManager import ConnectionManager
from lbrynet.core.client.DownloadManager import DownloadManager

View file

@ -6,7 +6,6 @@ import urllib
import json
import textwrap
import signal
import six
from binascii import hexlify, unhexlify, b2a_hex
from copy import deepcopy
from decimal import Decimal, InvalidOperation
@ -17,7 +16,6 @@ from twisted.python.failure import Failure
from torba.constants import COIN
import lbryschema
from lbryschema.claim import ClaimDict
from lbryschema.uri import parse_lbry_uri
from lbryschema.error import URIParseError, DecodeError

View file

@ -6,8 +6,7 @@ import signal
from decimal import Decimal
from functools import wraps
from zope.interface import implements
from twisted.web import server, resource
from twisted.web import server
from twisted.internet import defer
from twisted.python.failure import Failure
from twisted.internet.error import ConnectionDone, ConnectionLost

View file

@ -1,4 +1,4 @@
from collections import UserDict
from six.moves import UserDict
from . import constants

View file

@ -1,3 +1,4 @@
from __future__ import print_function
from .error import DecodeError

View file

@ -1,9 +1,7 @@
import binascii
import logging
from zope.interface import implements
from twisted.internet import defer
from lbrynet.interfaces import IPeerFinder
from lbrynet import conf

View file

@ -6,13 +6,11 @@
# may be created by processing this file with epydoc: http://epydoc.sf.net
import random
from zope.interface import implements
from twisted.internet import defer
from . import constants
from . import kbucket
from .error import TimeoutError
from .distance import Distance
from .interface import IRoutingTable
import logging
log = logging.getLogger(__name__)

View file

@ -4,7 +4,6 @@ Download LBRY Files from LBRYnet and save them to disk.
import logging
import binascii
from zope.interface import implements
from twisted.internet import defer
from lbrynet import conf
from lbrynet.core.client.StreamProgressManager import FullStreamProgressManager
@ -13,7 +12,6 @@ from lbrynet.core.utils import short_hash
from lbrynet.lbry_file.client.EncryptedFileDownloader import EncryptedFileSaver
from lbrynet.lbry_file.client.EncryptedFileDownloader import EncryptedFileDownloader
from lbrynet.file_manager.EncryptedFileStatusReport import EncryptedFileStatusReport
from lbrynet.interfaces import IStreamDownloaderFactory
from lbrynet.core.StreamDescriptor import save_sd_info
log = logging.getLogger(__name__)

View file

@ -7,7 +7,6 @@ import logging
from twisted.internet import defer, task, reactor
from twisted.python.failure import Failure
from lbrynet.reflector.reupload import reflect_file
# from lbrynet.core.PaymentRateManager import NegotiatedPaymentRateManager
from lbrynet.file_manager.EncryptedFileDownloader import ManagedEncryptedFileDownloader
from lbrynet.file_manager.EncryptedFileDownloader import ManagedEncryptedFileDownloaderFactory
from lbrynet.core.StreamDescriptor import EncryptedFileStreamType, get_sd_info

View file

@ -1,11 +1,8 @@
import binascii
from zope.interface import implements
from lbrynet.core.StreamDescriptor import save_sd_info
from lbrynet.cryptstream.client.CryptStreamDownloader import CryptStreamDownloader
from lbrynet.core.client.StreamProgressManager import FullStreamProgressManager
from lbrynet.interfaces import IStreamDownloaderFactory
from lbrynet.lbry_file.client.EncryptedFileMetadataHandler import EncryptedFileMetadataHandler
import os
from twisted.internet import defer, threads

View file

@ -1,14 +1,11 @@
import logging
from zope.interface import implements
from twisted.internet import defer
from lbrynet.interfaces import IMetadataHandler
log = logging.getLogger(__name__)
class EncryptedFileMetadataHandler(object):
#implements(IMetadataHandler)
def __init__(self, stream_hash, storage, download_manager):
self.stream_hash = stream_hash

View file

@ -1,7 +1,7 @@
# pylint: skip-file
import os
import shutil
import tempfile
import lbryum.wallet
from decimal import Decimal
from collections import defaultdict
@ -10,9 +10,9 @@ from twisted.internet import threads, defer
from lbrynet.database.storage import SQLiteStorage
from lbrynet.tests.mocks import FakeNetwork
from lbrynet.core.Error import InsufficientFundsError
from lbrynet.core.Wallet import LBRYumWallet, ReservedPoints
from lbryum.commands import Commands
from lbryum.simple_config import SimpleConfig
#from lbrynet.core.Wallet import LBRYumWallet, ReservedPoints
#from lbryum.commands import Commands
#from lbryum.simple_config import SimpleConfig
from lbryschema.claim import ClaimDict
test_metadata = {
@ -36,50 +36,53 @@ test_claim_dict = {
}}
class MocLbryumWallet(LBRYumWallet):
def __init__(self, db_dir, max_usable_balance=3):
LBRYumWallet.__init__(self, SQLiteStorage(db_dir), SimpleConfig(
{"lbryum_path": db_dir, "wallet_path": os.path.join(db_dir, "testwallet")}
))
self.db_dir = db_dir
self.wallet_balance = Decimal(10.0)
self.total_reserved_points = Decimal(0.0)
self.queued_payments = defaultdict(Decimal)
self.network = FakeNetwork()
self._mock_max_usable_balance = max_usable_balance
assert self.config.get_wallet_path() == os.path.join(self.db_dir, "testwallet")
#class MocLbryumWallet(LBRYumWallet):
# def __init__(self, db_dir, max_usable_balance=3):
# LBRYumWallet.__init__(self, SQLiteStorage(db_dir), SimpleConfig(
# {"lbryum_path": db_dir, "wallet_path": os.path.join(db_dir, "testwallet")}
# ))
# self.db_dir = db_dir
# self.wallet_balance = Decimal(10.0)
# self.total_reserved_points = Decimal(0.0)
# self.queued_payments = defaultdict(Decimal)
# self.network = FakeNetwork()
# self._mock_max_usable_balance = max_usable_balance
# assert self.config.get_wallet_path() == os.path.join(self.db_dir, "testwallet")
#
# @defer.inlineCallbacks
# def setup(self, password=None, seed=None):
# yield self.storage.setup()
# seed = seed or "travel nowhere air position hill peace suffer parent beautiful rise " \
# "blood power home crumble teach"
# storage = lbryum.wallet.WalletStorage(self.config.get_wallet_path())
# self.wallet = lbryum.wallet.NewWallet(storage)
# self.wallet.add_seed(seed, password)
# self.wallet.create_master_keys(password)
# self.wallet.create_main_account()
#
# @defer.inlineCallbacks
# def stop(self):
# yield self.storage.stop()
# yield threads.deferToThread(shutil.rmtree, self.db_dir)
#
# def get_least_used_address(self, account=None, for_change=False, max_count=100):
# return defer.succeed(None)
#
# def get_name_claims(self):
# return threads.deferToThread(lambda: [])
#
# def _save_name_metadata(self, name, claim_outpoint, sd_hash):
# return defer.succeed(True)
#
# def get_max_usable_balance_for_claim(self, name):
# # The amount is returned on the basis of test_point_reservation_and_claim unittest
# # Also affects test_successful_send_name_claim
# return defer.succeed(self._mock_max_usable_balance)
@defer.inlineCallbacks
def setup(self, password=None, seed=None):
yield self.storage.setup()
seed = seed or "travel nowhere air position hill peace suffer parent beautiful rise " \
"blood power home crumble teach"
storage = lbryum.wallet.WalletStorage(self.config.get_wallet_path())
self.wallet = lbryum.wallet.NewWallet(storage)
self.wallet.add_seed(seed, password)
self.wallet.create_master_keys(password)
self.wallet.create_main_account()
@defer.inlineCallbacks
def stop(self):
yield self.storage.stop()
yield threads.deferToThread(shutil.rmtree, self.db_dir)
def get_least_used_address(self, account=None, for_change=False, max_count=100):
return defer.succeed(None)
def get_name_claims(self):
return threads.deferToThread(lambda: [])
def _save_name_metadata(self, name, claim_outpoint, sd_hash):
return defer.succeed(True)
def get_max_usable_balance_for_claim(self, name):
# The amount is returned on the basis of test_point_reservation_and_claim unittest
# Also affects test_successful_send_name_claim
return defer.succeed(self._mock_max_usable_balance)
class WalletTest(unittest.TestCase):
skip = "Needs to be ported to the new wallet."
@defer.inlineCallbacks
def setUp(self):
user_dir = tempfile.mkdtemp()
@ -246,6 +249,8 @@ class WalletTest(unittest.TestCase):
class WalletEncryptionTests(unittest.TestCase):
skip = "Needs to be ported to the new wallet."
def setUp(self):
user_dir = tempfile.mkdtemp()
self.wallet = MocLbryumWallet(user_dir)

View file

@ -9,9 +9,7 @@ from twisted.trial import unittest
from faker import Faker
from lbryschema.decode import smart_decode
from lbryum.wallet import NewWallet
from lbrynet import conf
from lbrynet.core import Wallet
from lbrynet.database.storage import SQLiteStorage
from lbrynet.daemon.ComponentManager import ComponentManager
from lbrynet.daemon.Components import DATABASE_COMPONENT, DHT_COMPONENT, WALLET_COMPONENT, STREAM_IDENTIFIER_COMPONENT
@ -20,6 +18,9 @@ from lbrynet.daemon.Components import PEER_PROTOCOL_SERVER_COMPONENT, EXCHANGE_R
from lbrynet.daemon.Components import RATE_LIMITER_COMPONENT, HEADERS_COMPONENT, FILE_MANAGER_COMPONENT
from lbrynet.daemon.Daemon import Daemon as LBRYDaemon
from lbrynet.file_manager.EncryptedFileDownloader import ManagedEncryptedFileDownloader
from lbrynet.wallet.manager import LbryWalletManager
from torba.wallet import Wallet
from lbrynet.core.PaymentRateManager import OnlyFreePaymentsManager
from lbrynet.tests import util
from lbrynet.tests.mocks import mock_conf_settings, FakeNetwork, FakeFileManager

View file

@ -3,6 +3,8 @@ import mock
from twisted.trial import unittest
from twisted.internet import defer, task
from lbrynet.wallet.manager import LbryWalletManager
from lbrynet.core import PaymentRateManager, Wallet
from lbrynet.core.Error import DownloadDataTimeout, DownloadSDTimeout
from lbrynet.daemon import Downloader
@ -66,7 +68,7 @@ class GetStreamTests(unittest.TestCase):
def init_getstream_with_mocs(self):
mock_conf_settings(self)
sd_identifier = mock.Mock(spec=StreamDescriptorIdentifier)
wallet = mock.Mock(spec=Wallet.LBRYumWallet)
wallet = mock.Mock(spec=LbryWalletmanager)
prm = mock.Mock(spec=PaymentRateManager.NegotiatedPaymentRateManager)
exchange_rate_manager = mock.Mock(spec=ExchangeRateManager)
storage = mock.Mock(spec=SQLiteStorage)

View file

@ -1,4 +1,3 @@
from binascii import hexlify
from lbryschema.claim import ClaimDict
from lbryschema.signer import SECP256k1, get_signer

View file

@ -1,20 +1,17 @@
import os
from twisted.internet import defer
from torba.basetransaction import NULL_HASH
from torba.constants import COIN
from torba.coinselection import CoinSelector
from torba.manager import WalletManager as BaseWalletManager
from lbryschema.uri import parse_lbry_uri
from lbryschema.error import URIParseError
from .ledger import MainNetLedger
from .ledger import MainNetLedger # pylint: disable=unused-import
from .account import generate_certificate
from .transaction import Transaction
class BackwardsCompatibleNetwork:
class BackwardsCompatibleNetwork(object):
def __init__(self, manager):
self.manager = manager
@ -129,19 +126,19 @@ class LbryWalletManager(BaseWalletManager):
defer.returnValue(tx)
class ReservedPoints:
class ReservedPoints(object):
def __init__(self, identifier, amount):
self.identifier = identifier
self.amount = amount
class ClientRequest:
class ClientRequest(object):
def __init__(self, request_dict, response_identifier=None):
self.request_dict = request_dict
self.response_identifier = response_identifier
class LBRYcrdAddressRequester:
class LBRYcrdAddressRequester(object):
def __init__(self, wallet):
self.wallet = wallet
@ -167,11 +164,14 @@ class LBRYcrdAddressRequester:
self.wallet.update_peer_address(peer, address)
def _request_failed(self, error, peer):
raise Exception("A peer failed to send a valid public key response. Error: %s, peer: %s",
error.getErrorMessage(), str(peer))
raise Exception(
"A peer failed to send a valid public key response. Error: {}, peer: {}".format(
error.getErrorMessage(), str(peer)
)
)
class LBRYcrdAddressQueryHandlerFactory:
class LBRYcrdAddressQueryHandlerFactory(object):
def __init__(self, wallet):
self.wallet = wallet
@ -187,7 +187,7 @@ class LBRYcrdAddressQueryHandlerFactory:
return "LBRYcrd Address - an address for receiving payments via LBRYcrd"
class LBRYcrdAddressQueryHandler:
class LBRYcrdAddressQueryHandler(object):
def __init__(self, wallet):
self.wallet = wallet

View file

@ -1,14 +1,14 @@
import struct
from binascii import hexlify
from typing import List
from typing import List # pylint: disable=unused-import
from twisted.internet import defer
from twisted.internet import defer # pylint: disable=unused-import
from torba.baseaccount import BaseAccount
from torba.baseaccount import BaseAccount # pylint: disable=unused-import
from torba.basetransaction import BaseTransaction, BaseInput, BaseOutput
from torba.hash import hash160
from lbryschema.claim import ClaimDict
from lbryschema.claim import ClaimDict # pylint: disable=unused-import
from .script import InputScript, OutputScript

View file

@ -27,3 +27,4 @@ wsgiref==0.1.2
zope.interface==4.3.3
treq==17.8.0
typing
git+https://github.com/lbryio/torba.git#egg=torba

View file

@ -1,2 +1,3 @@
mock>=2.0,<3.0
Faker==0.8
git+https://github.com/lbryio/orchstr8.git#egg=orchstr8