Skip to content

Commit

Permalink
Merge pull request #48 from LayerXcom/fix_pep8
Browse files Browse the repository at this point in the history
Fix pep8
  • Loading branch information
yudetamago authored Apr 8, 2019
2 parents d2e84a5 + c91cde0 commit b8b333c
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
max-line-length = 120
1 change: 0 additions & 1 deletion cbc_casper_simulator/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ def __init__(self, message_hashes: List[int]):
message_hash) for message_hash in message_hashes]
reason = " ".join(errors)
super().__init__(reason)

11 changes: 8 additions & 3 deletions cbc_casper_simulator/message_validator.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
from __future__ import annotations
from result import Ok, Err, Result
from cbc_casper_simulator.error import *
# FIXME: Resolve circular reference
# from cbc_casper_simulator.state import State
from cbc_casper_simulator.message import Message
from cbc_casper_simulator.error import Error, MessageNotJustifiedError
from cbc_casper_simulator.justification import Justification


class MessageValidator:
@classmethod
def validate(cls, state: 'State', message: 'Message') -> Result[Error, bool]:
def validate(cls, state: 'State', message: Message) -> Result[Error, bool]:
justified = cls.justification_is_justified(
state, message.justification)
if justified.is_err():
Expand All @@ -17,7 +21,8 @@ def validate(cls, state: 'State', message: 'Message') -> Result[Error, bool]:
@classmethod
def justification_is_justified(cls, state: 'State', justification: Justification) -> Result[Error, bool]:
not_justified = [h for h in justification.latest_messages.values(
) if not state.store.justified(h)]
) if not state.store.justified(h)]

if len(not_justified) > 0:
return Err(MessageNotJustifiedError(not_justified))
else:
Expand Down
4 changes: 2 additions & 2 deletions cbc_casper_simulator/safety_oracle/clique_oracle.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from result import Ok, Err, Result
from cbc_casper_simulator.error import *
from result import Ok, Result
from cbc_casper_simulator.error import Error


class CliqueOracle:
Expand Down
4 changes: 2 additions & 2 deletions cbc_casper_simulator/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from cbc_casper_simulator.message_validator import MessageValidator
from cbc_casper_simulator.safety_oracle.clique_oracle import CliqueOracle
from cbc_casper_simulator.util.ticker import Ticker
from cbc_casper_simulator.error import *
from cbc_casper_simulator.error import Error
from typing import Optional
from result import Ok, Err, Result
from result import Ok, Result


class State:
Expand Down
1 change: 0 additions & 1 deletion cbc_casper_simulator/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from typing import Dict, List, Optional
from cbc_casper_simulator.message import Message
from cbc_casper_simulator.block import Block
from cbc_casper_simulator.justification import Justification
from typing import TYPE_CHECKING
from typing import Union
if TYPE_CHECKING:
Expand Down
4 changes: 2 additions & 2 deletions cbc_casper_simulator/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from cbc_casper_simulator.message import Message
from cbc_casper_simulator.estimator.lmd_ghost_estimator import LMDGhostEstimator as Estimator
from cbc_casper_simulator.util.ticker import Ticker
from cbc_casper_simulator.error import *
from cbc_casper_simulator.error import Error
import random as r
from result import Ok, Err, Result
from result import Result


class Validator:
Expand Down
5 changes: 3 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from cbc_casper_simulator.examples.broadcast import simulate as broadcast
from cbc_casper_simulator.examples.lmd_ghost import simulate as lmd_ghost
# NOTE: Do not create png files for now
# from cbc_casper_simulator.examples.broadcast import simulate as broadcast
# from cbc_casper_simulator.examples.lmd_ghost import simulate as lmd_ghost
from cbc_casper_simulator.examples.simple import run as simple_run
import argparse

Expand Down
2 changes: 2 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/sh

flake8

pip install -r requirements.txt -r requirements-test.txt

pytest
2 changes: 1 addition & 1 deletion tests/util/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ def test_tick():
ticker = Ticker()
assert ticker.current() == 0
ticker.tick()
assert ticker.current() == 1
assert ticker.current() == 1

0 comments on commit b8b333c

Please sign in to comment.