Exception handling for development installation required.

pull/2013/head
Kieran Prasch 2020-05-19 21:56:08 -07:00
parent ba81356224
commit ac07ff7415
No known key found for this signature in database
GPG Key ID: 199AB839D4125A62
5 changed files with 30 additions and 16 deletions

View File

@ -24,6 +24,7 @@ from web3.exceptions import InfuraKeyNotFound
from web3.providers.eth_tester.main import EthereumTesterProvider
from nucypher.blockchain.eth.clients import NuCypherGethDevProcess
from nucypher.exceptions import DevelopmentInstallationRequired
class ProviderError(Exception):
@ -90,10 +91,10 @@ def _get_auto_provider(provider_uri):
def _get_pyevm_test_backend() -> PyEVMBackend:
try:
# TODO: Consider packaged support of --dev mode with testerchain
from tests.constants import PYEVM_GAS_LIMIT, NUMBER_OF_ETH_TEST_ACCOUNTS
except ImportError:
raise ImportError("Nucypher is not installed in development mode. "
"Please checkout the code locally and reinstall to use the test client.")
raise DevelopmentInstallationRequired(importable_name='tests.constants')
# Initialize
genesis_params = PyEVMBackend._generate_genesis_params(overrides={'gas_limit': PYEVM_GAS_LIMIT})

View File

@ -14,6 +14,7 @@ from nucypher.characters.control.interfaces import CharacterPublicInterface
from nucypher.characters.control.specifications.exceptions import SpecificationError
from nucypher.cli.processes import JSONRPCLineReceiver
from nucypher.config.constants import MAX_UPLOAD_CONTENT_LENGTH
from nucypher.exceptions import DevelopmentInstallationRequired
class CharacterControllerBase(ABC):
@ -139,8 +140,8 @@ class JSONRPCController(CharacterControlServer):
try:
from tests.utils.controllers import JSONRPCTestClient
except ImportError:
raise ImportError("Nucypher is not installed in development mode, "
"Please checkout the code locally and reinstall to use the test client.")
raise DevelopmentInstallationRequired(importable_name='tests.utils.controllers.JSONRPCTestClient')
test_client = JSONRPCTestClient(rpc_controller=self)
return test_client

View File

@ -16,6 +16,8 @@ along with nucypher. If not, see <https://www.gnu.org/licenses/>.
"""
from nucypher.exceptions import DevelopmentInstallationRequired
from copy import copy
from eth_tester.exceptions import ValidationError
@ -31,7 +33,6 @@ class Vladimir(Ursula):
"""
from tests.utils.middleware import EvilMiddleWare
network_middleware = EvilMiddleWare()
fraud_address = '0xbad022A87Df21E4c787C7B1effD5077014b8CC45'
fraud_key = 'a75d701cc4199f7646909d15f22e2e0ef6094b3e2aa47a188f35f47e8932a7b9'
db_filepath = ':memory:'
@ -47,6 +48,13 @@ class Vladimir(Ursula):
TODO: This is probably a more instructive method if it takes a bytes representation instead of the entire Ursula.
"""
try:
from tests.utils.middleware import EvilMiddleWare
except ImportError:
raise DevelopmentInstallationRequired(importable_name='tests.utils.middleware.EvilMiddleWare')
else:
cls.network_middleware = EvilMiddleWare()
crypto_power = CryptoPower(power_ups=target_ursula._default_crypto_powerups)
if claim_signing_key:
@ -55,6 +63,7 @@ class Vladimir(Ursula):
if attach_transacting_key:
cls.attach_transacting_key(blockchain=target_ursula.blockchain)
vladimir = cls(is_me=True,
crypto_power=crypto_power,
db_filepath=cls.db_filepath,

View File

@ -20,6 +20,7 @@ from collections import namedtuple
import click
import functools
import os
from twisted.python.log import Logger
from nucypher.blockchain.eth.constants import NUCYPHER_CONTRACT_NAMES
from nucypher.cli.types import (
@ -30,6 +31,7 @@ from nucypher.cli.types import (
)
# Alphabetical
option_checksum_address = click.option('--checksum-address', help="Run with a specified account", type=EIP55_CHECKSUM_ADDRESS)
option_config_file = click.option('--config-file', help="Path to configuration file", type=EXISTING_READABLE_FILE)
option_config_root = click.option('--config-root', help="Custom configuration directory", type=click.Path())
@ -182,22 +184,18 @@ def wrap_option(handler, **options):
return _decorator
def process_middleware(mock_networking):
def process_middleware(mock_networking) -> tuple:
"""Must not raise"""
try:
import tests
except ImportError:
# TODO: IDK what to say here...needs further discussion around deprecation in lieu of mocks.
tests_available = False
else:
tests_available = True
if mock_networking and tests_available:
from tests.utils.middleware import MockRestMiddleware
except ImportError:
logger = Logger("CLI-Middleware-Optional-Handler")
logger.info('--mock-networking flag is unavailable without dev install.')
if mock_networking:
middleware = MockRestMiddleware()
else:
from nucypher.network.middleware import RestMiddleware
middleware = RestMiddleware()
return 'middleware', middleware

View File

@ -25,7 +25,12 @@ along with nucypher. If not, see <https://www.gnu.org/licenses/>.
from click.testing import CliRunner
from nucypher.cli.main import nucypher_cli
from tests.utils.constants import select_test_port
from nucypher.exceptions import DevelopmentInstallationRequired
try:
from tests.utils.networking import select_test_port
except ImportError:
raise DevelopmentInstallationRequired(importable_name='tests.utils.ursula.select_test_port')
click_runner = CliRunner()