Merge pull request #764 from mswilkison/master

PEP 8 fixes + miscellaneous cleanup on tests and visual improvement for docs
pull/774/head
Tux 2019-02-16 00:26:01 +00:00 committed by GitHub
commit e537a95167
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 56 additions and 70 deletions

View File

@ -64,7 +64,7 @@
xlink:href="#path0_fill"
transform="translate(3901,-2624.64)"
id="use17"
style="fill:#1e65f3"
style="fill:#343131"
x="0"
y="0"
width="100%"
@ -76,7 +76,7 @@
xlink:href="#path1_fill"
transform="translate(4016.34,-2590.23)"
id="use21"
style="fill:#1e65f3"
style="fill:#343131"
x="0"
y="0"
width="100%"
@ -88,7 +88,7 @@
xlink:href="#path2_fill"
transform="translate(4107.25,-2627)"
id="use25"
style="fill:#121112"
style="fill:#343131"
x="0"
y="0"
width="100%"
@ -100,7 +100,7 @@
xlink:href="#path3_fill"
transform="translate(4224.29,-2590.25)"
id="use29"
style="fill:#121112"
style="fill:#343131"
x="0"
y="0"
width="100%"
@ -112,7 +112,7 @@
xlink:href="#path4_fill"
transform="translate(4322.33,-2592.59)"
id="use33"
style="fill:#121112"
style="fill:#343131"
x="0"
y="0"
width="100%"
@ -124,7 +124,7 @@
xlink:href="#path5_fill"
transform="translate(4423.35,-2624.68)"
id="use37"
style="fill:#121112"
style="fill:#343131"
x="0"
y="0"
width="100%"
@ -136,7 +136,7 @@
xlink:href="#path6_fill"
transform="translate(4512.54,-2592.61)"
id="use41"
style="fill:#121112"
style="fill:#343131"
x="0"
y="0"
width="100%"
@ -148,7 +148,7 @@
xlink:href="#path7_fill"
transform="translate(4610.36,-2592.59)"
id="use45"
style="fill:#121112"
style="fill:#343131"
x="0"
y="0"
width="100%"
@ -164,7 +164,7 @@
xlink:href="#path8_fill"
transform="translate(3964,-3136)"
id="use50"
style="fill:#1e65f3"
style="fill:#ffffff"
x="0"
y="0"
width="100%"

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

View File

@ -97,7 +97,11 @@ html_theme = 'sphinx_rtd_theme'
# further. For a list of options available for each theme, see the
# documentation.
#
# html_theme_options = {}
html_theme_options = {
'logo_only': True,
}
html_logo = '.static/img/nucypher_logo.svg'
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,

View File

@ -2,9 +2,6 @@ NuCypher
========
*A proxy re-encryption network to empower privacy in decentralized systems*
.. image:: .static/img/nucypher_logo.svg
:width: 60%
----

View File

@ -239,4 +239,4 @@ def test_pre_deposit(testerchain, token, escrow_contract):
event_args = events[5]['args']
assert miners[4] == event_args['miner']
assert 500 == event_args['value']
assert 250 == event_args['periods']
assert 250 == event_args['periods']

View File

@ -74,4 +74,3 @@ def test_rapid_deployment():
allocation_data.append(random_allocation)
deployer.deploy_beneficiary_contracts(allocations=allocation_data)

View File

@ -117,5 +117,3 @@ def test_miner_collects_staking_reward(testerchain, miner, three_agents):
final_balance = token_agent.get_balance(miner.checksum_public_address)
assert final_balance > initial_balance

View File

@ -93,4 +93,3 @@ def test_transfer(agent):
new_balance = agent.get_balance(someone)
assert new_balance == old_balance + MIN_ALLOWED_LOCKED

View File

@ -16,8 +16,6 @@ along with nucypher. If not, see <https://www.gnu.org/licenses/>.
"""
import os
import pytest
from nucypher.blockchain.eth.agents import MinerAgent
from nucypher.blockchain.eth.deployers import NucypherTokenDeployer, MinerEscrowDeployer

View File

@ -14,11 +14,11 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with nucypher. If not, see <https://www.gnu.org/licenses/>.
"""
def test_testerchain_creation(testerchain):
# Ensure we are testing on the correct network...
assert 'tester' in testerchain.interface.provider_uri
# ... and that there are already some blocks mined
assert testerchain.interface.w3.eth.blockNumber >= 0

View File

@ -26,7 +26,6 @@ from umbral.kfrags import KFrag
from nucypher.characters.lawful import Bob
from nucypher.config.characters import AliceConfiguration
from nucypher.crypto.api import keccak_digest
from nucypher.crypto.powers import SigningPower, DecryptingPower
from nucypher.policy.models import Revocation
from nucypher.utilities.sandbox.constants import INSECURE_DEVELOPMENT_PASSWORD
@ -48,7 +47,7 @@ def test_mocked_decentralized_grant(blockchain_alice, blockchain_bob, three_agen
policy_end_datetime = maya.now() + datetime.timedelta(days=5)
label = b"this_is_the_path_to_which_access_is_being_granted"
# Create the Policy, Grating access to Bob
# Create the Policy, Granting access to Bob
policy = blockchain_alice.grant(blockchain_bob, label, m=2, n=n, expiration=policy_end_datetime)
# The number of accepted arrangements at least the number of Ursulas we're using (n)
@ -61,9 +60,7 @@ def test_mocked_decentralized_grant(blockchain_alice, blockchain_bob, three_agen
for kfrag in policy.kfrags:
arrangement = policy._enacted_arrangements[kfrag]
# Get the Arrangement from Ursula's datastore, looking up by hrac.
# This will be changed in 180, when we use the Arrangement ID.
proper_hrac = keccak_digest(bytes(blockchain_alice.stamp) + bytes(blockchain_bob.stamp) + label)
# Get the Arrangement from Ursula's datastore, looking up by the Arrangement ID.
retrieved_policy = arrangement.ursula.datastore.get_policy_arrangement(arrangement.id.hex().encode())
retrieved_kfrag = KFrag.from_bytes(retrieved_policy.kfrag)
@ -91,9 +88,7 @@ def test_federated_grant(federated_alice, federated_bob):
for kfrag in policy.kfrags:
arrangement = policy._enacted_arrangements[kfrag]
# Get the Arrangement from Ursula's datastore, looking up by hrac.
# This will be changed in 180, when we use the Arrangement ID.
proper_hrac = keccak_digest(bytes(federated_alice.stamp) + bytes(federated_bob.stamp) + label)
# Get the Arrangement from Ursula's datastore, looking up by the Arrangement ID.
retrieved_policy = arrangement.ursula.datastore.get_policy_arrangement(arrangement.id.hex().encode())
retrieved_kfrag = KFrag.from_bytes(retrieved_policy.kfrag)
@ -220,4 +215,3 @@ def test_alices_powers_are_persistent(federated_ursulas, tmpdir):
# Both policies must share the same public key (i.e., the policy public key)
assert policy_pubkey == roberto_policy.public_key

View File

@ -18,7 +18,6 @@ along with nucypher. If not, see <https://www.gnu.org/licenses/>.
import pytest
import pytest_twisted
from tempfile import TemporaryDirectory
from twisted.internet import threads
from umbral import pre
@ -48,7 +47,8 @@ def test_bob_cannot_follow_the_treasure_map_in_isolation(enacted_federated_polic
assert len(known) == 0
def test_bob_already_knows_all_nodes_in_treasure_map(enacted_federated_policy, federated_ursulas, federated_bob, federated_alice):
def test_bob_already_knows_all_nodes_in_treasure_map(enacted_federated_policy, federated_ursulas, federated_bob,
federated_alice):
# Bob knows of no Ursulas.
assert len(federated_bob.known_nodes) == 0
@ -125,7 +125,7 @@ def test_bob_can_follow_treasure_map_even_if_he_only_knows_of_one_node(enacted_f
def test_bob_can_issue_a_work_order_to_a_specific_ursula(enacted_federated_policy, federated_bob,
federated_alice, federated_ursulas, capsule_side_channel):
"""
Now that Bob has his list of Ursulas, he can issue a WorkOrder to one. Upon receiving the WorkOrder, Ursula
Now that Bob has his list of Ursulas, he can issue a WorkOrder to one. Upon receiving the WorkOrder, Ursula
saves it and responds by re-encrypting and giving Bob a cFrag.
This is a multipart test; it shows proper relations between the Characters Ursula and Bob and also proper
@ -136,14 +136,12 @@ def test_bob_can_issue_a_work_order_to_a_specific_ursula(enacted_federated_polic
hrac, treasure_map = enacted_federated_policy.hrac(), enacted_federated_policy.treasure_map
map_id = treasure_map.public_id()
federated_bob.treasure_maps[map_id] = treasure_map
d = federated_bob.start_learning_loop()
federated_bob.start_learning_loop()
federated_bob.follow_treasure_map(map_id=map_id, block=True, timeout=1)
assert len(federated_bob.known_nodes) == len(federated_ursulas)
the_hrac = enacted_federated_policy.hrac()
# Bob has no saved work orders yet, ever.
assert len(federated_bob._saved_work_orders) == 0
@ -185,13 +183,13 @@ def test_bob_can_issue_a_work_order_to_a_specific_ursula(enacted_federated_polic
assert len(federated_bob._saved_work_orders.by_ursula[ursula_id]) == 1
# OK, so cool - Bob has his cFrag! Let's make sure everything went properly. First, we'll show that it is in fact
# the correct cFrag (ie, that Ursula performed reencryption properly).
# the correct cFrag (ie, that Ursula performed re-encryption properly).
for u in federated_ursulas:
if u.rest_information()[0].port == work_order.ursula.rest_information()[0].port:
ursula = u
break
else:
raise RuntimeError("We've lost track of the Ursula that has the WorkOrder. Can't really proceed.")
raise RuntimeError("We've lost track of the Ursula that has the WorkOrder. Can't really proceed.")
kfrag_bytes = ursula.datastore.get_policy_arrangement(
work_order.arrangement_id.hex().encode()).kfrag
@ -199,7 +197,8 @@ def test_bob_can_issue_a_work_order_to_a_specific_ursula(enacted_federated_polic
the_correct_cfrag = pre.reencrypt(the_kfrag, capsule)
# The first CFRAG_LENGTH_WITHOUT_PROOF bytes (ie, the cfrag proper, not the proof material), are the same:
assert bytes(the_cfrag)[:CapsuleFrag.expected_bytes_length()] == bytes(the_correct_cfrag)[:CapsuleFrag.expected_bytes_length()] # It's the correct cfrag!
assert bytes(the_cfrag)[:CapsuleFrag.expected_bytes_length()] == bytes(
the_correct_cfrag)[:CapsuleFrag.expected_bytes_length()] # It's the correct cfrag!
assert the_correct_cfrag.verify_correctness(capsule)
@ -217,11 +216,11 @@ def test_bob_remembers_that_he_has_cfrags_for_a_particular_capsule(enacted_feder
assert len(capsule_side_channel[0].capsule._attached_cfrags) == 1
# He can also get a dict of {Ursula:WorkOrder} by looking them up from the capsule.
workorders_by_capsule = federated_bob._saved_work_orders.by_capsule(capsule_side_channel[0].capsule)
work_orders_by_capsule = federated_bob._saved_work_orders.by_capsule(capsule_side_channel[0].capsule)
# Bob has just one WorkOrder from that one Ursula.
assert len(workorders_by_capsule) == 1
saved_work_order = list(workorders_by_capsule.values())[0]
assert len(work_orders_by_capsule) == 1
saved_work_order = list(work_orders_by_capsule.values())[0]
# The rest of this test will show that if Bob generates another WorkOrder, it's for a *different* Ursula.
generated_work_orders = federated_bob.generate_work_orders(enacted_federated_policy.treasure_map.public_id(),
@ -230,7 +229,7 @@ def test_bob_remembers_that_he_has_cfrags_for_a_particular_capsule(enacted_feder
id_of_this_new_ursula, new_work_order = list(generated_work_orders.items())[0]
# This new Ursula isn't the same one to whom we've already issued a WorkOrder.
id_of_ursula_from_whom_we_already_have_a_cfrag = list(workorders_by_capsule.keys())[0]
id_of_ursula_from_whom_we_already_have_a_cfrag = list(work_orders_by_capsule.keys())[0]
assert id_of_ursula_from_whom_we_already_have_a_cfrag != id_of_this_new_ursula
# ...and, although this WorkOrder has the same capsules as the saved one...

View File

@ -113,7 +113,7 @@ def test_bob_joins_policy_and_retrieves(federated_alice,
def test_treasure_map_serialization(enacted_federated_policy, federated_bob):
treasure_map = enacted_federated_policy.treasure_map
assert treasure_map.m != None
assert treasure_map.m is not None
assert treasure_map.m != NO_DECRYPTION_PERFORMED
assert treasure_map.m == MOCK_POLICY_DEFAULT_M, 'm value is not correct'

View File

@ -14,7 +14,7 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with nucypher. If not, see <https://www.gnu.org/licenses/>.
"""
import pytest
from nucypher.characters.lawful import Ursula

View File

@ -40,11 +40,11 @@ def test_actor_without_signing_power_cannot_sign():
federated_only=True)
# The non-signer's stamp doesn't work for signing...
with pytest.raises(NoSigningPower) as e_info:
with pytest.raises(NoSigningPower):
non_signer.stamp("something")
# ...or as a way to cast the (non-existent) public key to bytes.
with pytest.raises(NoSigningPower) as e_info:
with pytest.raises(NoSigningPower):
bytes(non_signer.stamp)
@ -111,7 +111,7 @@ def test_character_blockchain_power(testerchain):
sig = power.sign_message(data_to_sign)
is_verified = power.verify_message(eth_address, sig_pubkey.to_bytes(), data_to_sign, sig)
assert is_verified == True
assert is_verified is True
# Test a bad message:
with pytest.raises(PowerUpError):

View File

@ -112,7 +112,7 @@ def test_vladimir_uses_his_own_signing_key(blockchain_alice, blockchain_ursulas)
"""
his_target = list(blockchain_ursulas)[4]
fraduluent_keys = CryptoPower(power_ups=Ursula._default_crypto_powerups) # TODO: Why is this unused?
fraudulent_keys = CryptoPower(power_ups=Ursula._default_crypto_powerups) # TODO: Why is this unused?
vladimir = Vladimir.from_target_ursula(target_ursula=his_target)

View File

@ -211,7 +211,8 @@ def test_ursula_init_does_not_overrides_existing_files(custom_filepath, click_ru
def test_ursula_destroy_configuration(custom_filepath, click_runner):
preexisting_live_configuration = os.path.isdir(DEFAULT_CONFIG_ROOT)
preexisting_live_configuration_file = os.path.isfile(os.path.join(DEFAULT_CONFIG_ROOT, UrsulaConfiguration.CONFIG_FILENAME))
preexisting_live_configuration_file = os.path.isfile(os.path.join(DEFAULT_CONFIG_ROOT,
UrsulaConfiguration.CONFIG_FILENAME))
# Ensure the configuration file still exists
custom_config_filepath = os.path.join(custom_filepath, UrsulaConfiguration.CONFIG_FILENAME)

View File

@ -17,8 +17,6 @@ along with nucypher. If not, see <https://www.gnu.org/licenses/>.
from functools import partial
import maya
import pytest
import pytest_twisted as pt
from twisted.internet.threads import deferToThread
@ -66,7 +64,8 @@ def test_get_cert_from_running_seed_node(ursula_federated_test_config):
any_other_ursula.log.info(
"Known nodes when starting learning loop were: {}".format(any_other_ursula.known_nodes))
any_other_ursula.start_learning_loop()
result = any_other_ursula.block_until_specific_nodes_are_known(set([firstula.checksum_public_address]), timeout=2)
result = any_other_ursula.block_until_specific_nodes_are_known(set([firstula.checksum_public_address]),
timeout=2)
assert result
yield deferToThread(start_lonely_learning_loop)

View File

@ -59,7 +59,8 @@ class BaseTestNodeStorageBackends:
# Save more nodes
all_known_nodes = set()
for port in range(MOCK_URSULA_STARTING_PORT, MOCK_URSULA_STARTING_PORT+100):
node = Ursula(rest_host='127.0.0.1', db_filepath=MOCK_URSULA_DB_FILEPATH, rest_port=port, federated_only=True)
node = Ursula(rest_host='127.0.0.1', db_filepath=MOCK_URSULA_DB_FILEPATH, rest_port=port,
federated_only=True)
node_storage.store_node_metadata(node=node)
all_known_nodes.add(node)
@ -97,7 +98,7 @@ class BaseTestNodeStorageBackends:
#
# Storage Backed Tests
# Storage Backend Tests
#
def test_delete_node_in_storage(self, light_ursula):

View File

@ -19,8 +19,7 @@ import pytest
from twisted.logger import globalLogPublisher
from nucypher.cli.config import NucypherClickConfig
#
from nucypher.utilities.logging import SimpleObserver, GlobalConsoleLogger, logToSentry
from nucypher.utilities.logging import GlobalConsoleLogger, logToSentry
# Logger Configuration
#

View File

@ -242,7 +242,7 @@ def idle_blockchain_policy(blockchain_alice, blockchain_bob):
@pytest.fixture(scope="module")
def enacted_blockchain_policy(idle_blockchain_policy, blockchain_ursulas):
# Alice has a policy in mind and knows of enough qualifies Ursulas; she crafts an offer for them.
# Alice has a policy in mind and knows of enough qualified Ursulas; she crafts an offer for them.
deposit = NON_PAYMENT(b"0000000")
contract_end_datetime = maya.now() + datetime.timedelta(days=5)
network_middleware = MockRestMiddleware()

View File

@ -38,8 +38,6 @@ def test_key_sqlite_keystore(test_keystore, federated_bob):
def test_policy_arrangement_sqlite_keystore(test_keystore):
alice_keypair_sig = keypairs.SigningKeypair(generate_keys_if_needed=True)
alice_keypair_dec = keypairs.DecryptingKeypair(generate_keys_if_needed=True)
bob_keypair_sig = keypairs.SigningKeypair(generate_keys_if_needed=True)
arrangement_id = b'test'

View File

@ -106,7 +106,7 @@ def test_vladimir_uses_his_own_signing_key(blockchain_alice, blockchain_ursulas)
"""
his_target = list(blockchain_ursulas)[4]
fraduluent_keys = CryptoPower(power_ups=Ursula._default_crypto_powerups)
fraudulent_keys = CryptoPower(power_ups=Ursula._default_crypto_powerups)
vladimir = Vladimir.from_target_ursula(target_ursula=his_target)
@ -147,6 +147,7 @@ def test_emit_warning_upon_new_version(ursula_federated_test_config, caplog):
learner.learn_from_teacher_node()
assert len(warnings) == 1
#TODO: Why no assert? Is this in progress?
warnings[0]['log_format'] == learner.unknown_version_message.format(new_node, new_node.TEACHER_VERSION,
learner.LEARNER_VERSION)
@ -159,6 +160,7 @@ def test_emit_warning_upon_new_version(ursula_federated_test_config, caplog):
learner.learn_from_teacher_node()
assert len(warnings) == 2
# TODO: Why no assert? Is this in progress?
warnings[1]['log_format'] == learner.unknown_version_message.format(new_node, new_node.TEACHER_VERSION,
learner.LEARNER_VERSION)

View File

@ -76,7 +76,8 @@ def test_old_state_is_preserved(federated_ursulas, ursula_federated_test_config)
proper_first_state = sorted([some_ursula_in_the_fleet, lonely_learner], key=lambda n: n.checksum_public_address)
assert lonely_learner.known_nodes.states[checksum_after_learning_one].nodes == proper_first_state
proper_second_state = sorted([some_ursula_in_the_fleet, another_ursula_in_the_fleet, lonely_learner], key=lambda n: n.checksum_public_address)
proper_second_state = sorted([some_ursula_in_the_fleet, another_ursula_in_the_fleet, lonely_learner],
key=lambda n: n.checksum_public_address)
assert lonely_learner.known_nodes.states[checksum_after_learning_two].nodes == proper_second_state

View File

@ -16,8 +16,6 @@ along with nucypher. If not, see <https://www.gnu.org/licenses/>.
"""
import os
import pytest
from binascii import unhexlify
from hendrix.experience import crosstown_traffic
@ -43,8 +41,8 @@ def test_all_blockchain_ursulas_know_about_all_other_ursulas(blockchain_ursulas,
if address == propagating_ursula.checksum_public_address:
continue
else:
assert address in propagating_ursula.known_nodes.addresses(), "{} did not know about {}".format(propagating_ursula,
nickname_from_seed(address))
assert address in propagating_ursula.known_nodes.addresses(), "{} did not know about {}".\
format(propagating_ursula, nickname_from_seed(address))
@pytest.mark.slow()
@ -53,8 +51,6 @@ def test_blockchain_alice_finds_ursula_via_rest(blockchain_alice, blockchain_urs
# Imagine alice knows of nobody.
blockchain_alice.known_nodes = {}
some_ursula_interface = blockchain_ursulas.pop().rest_interface
new_nodes = blockchain_alice.learn_from_teacher_node()
assert len(new_nodes) == len(blockchain_ursulas)
@ -86,7 +82,8 @@ def test_alice_sets_treasure_map(enacted_federated_policy, federated_ursulas):
assert treasure_map_as_set_on_network == enacted_federated_policy.treasure_map
def test_treasure_map_stored_by_ursula_is_the_correct_one_for_bob(federated_alice, federated_bob, federated_ursulas, enacted_federated_policy):
def test_treasure_map_stored_by_ursula_is_the_correct_one_for_bob(federated_alice, federated_bob, federated_ursulas,
enacted_federated_policy):
"""
The TreasureMap given by Alice to Ursula is the correct one for Bob; he can decrypt and read it.
"""