[Code Cleanup] Format source files with black
This commit is contained in:
parent
382449d6bb
commit
39772f1983
@ -39,6 +39,12 @@ Static linting:
|
||||
|
||||
poetry run pylint earthsnake tests
|
||||
|
||||
Code style check:
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
poetry run black --diff --skip-string-normalization earthsnake tests
|
||||
|
||||
Tests:
|
||||
|
||||
.. code-block:: sh
|
||||
|
@ -29,9 +29,7 @@ def base32_string_to_bytes(string: str) -> bytes:
|
||||
"""
|
||||
|
||||
if not string.startswith("b"):
|
||||
raise ValueError(
|
||||
f"can't decode base32 string - it should start with a 'b'. {str}"
|
||||
)
|
||||
raise ValueError(f"can't decode base32 string - it should start with a 'b'. {str}")
|
||||
|
||||
string = string[1:]
|
||||
|
||||
@ -44,9 +42,7 @@ def base32_string_to_bytes(string: str) -> bytes:
|
||||
|
||||
# make sure no padding characters are on the end
|
||||
if string.endswith("="):
|
||||
raise ValueError(
|
||||
"can't decode base32 string - it contains padding characters ('=')"
|
||||
)
|
||||
raise ValueError("can't decode base32 string - it contains padding characters ('=')")
|
||||
|
||||
pad_length = 8 - len(string) % 8
|
||||
string += '=' * pad_length
|
||||
|
@ -1,6 +1,7 @@
|
||||
"""Exception types for Earthsnake
|
||||
"""
|
||||
|
||||
|
||||
class EarthsnakeError(Exception):
|
||||
"""Basic Earthsnake error
|
||||
|
||||
@ -9,5 +10,4 @@ class EarthsnakeError(Exception):
|
||||
|
||||
|
||||
class ValidationError(EarthsnakeError):
|
||||
"""Raised when something doesn’t pass as a valid Earthsnake object
|
||||
"""
|
||||
"""Raised when something doesn’t pass as a valid Earthsnake object"""
|
||||
|
@ -17,6 +17,10 @@ black = "^22.3.0"
|
||||
mypy = "^0.942"
|
||||
pytest-cov = "^3.0.0"
|
||||
|
||||
[tool.black]
|
||||
skip-string-normalization = true
|
||||
line-length = 100
|
||||
|
||||
[tool.pytest.ini_options]
|
||||
markers = [
|
||||
"id_key_seed: seed to create an identity secret from",
|
||||
|
@ -65,9 +65,7 @@ def test_init_no_keys() -> None:
|
||||
def test_str(identity: Identity) -> None:
|
||||
"""Test if the __str__ method returns the author address"""
|
||||
|
||||
assert (
|
||||
str(identity) == '@test.bcz76z52y5dlpohtkmpuj3jsdcvfmebzpcgfmtmhu4u7hlexzreya'
|
||||
)
|
||||
assert str(identity) == '@test.bcz76z52y5dlpohtkmpuj3jsdcvfmebzpcgfmtmhu4u7hlexzreya'
|
||||
|
||||
|
||||
@pytest.mark.id_key_seed(TEST_SEED)
|
||||
@ -85,9 +83,7 @@ def test_from_address() -> None:
|
||||
|
||||
skey = SigningKey(TEST_SEED)
|
||||
vkey = skey.get_verifying_key()
|
||||
identity = Identity.from_address(
|
||||
'@test.bcz76z52y5dlpohtkmpuj3jsdcvfmebzpcgfmtmhu4u7hlexzreya'
|
||||
)
|
||||
identity = Identity.from_address('@test.bcz76z52y5dlpohtkmpuj3jsdcvfmebzpcgfmtmhu4u7hlexzreya')
|
||||
|
||||
assert identity.name == 'test'
|
||||
assert identity.sign_key is None
|
||||
@ -112,9 +108,7 @@ def test_generate(mocker: MockerFixture) -> None:
|
||||
mocker.patch('earthsnake.identity.create_keypair', return_value=(skey, vkey))
|
||||
identity = Identity.generate('test')
|
||||
|
||||
assert (
|
||||
str(identity) == '@test.bcz76z52y5dlpohtkmpuj3jsdcvfmebzpcgfmtmhu4u7hlexzreya'
|
||||
)
|
||||
assert str(identity) == '@test.bcz76z52y5dlpohtkmpuj3jsdcvfmebzpcgfmtmhu4u7hlexzreya'
|
||||
assert identity.sign_key
|
||||
assert identity.verify_key
|
||||
assert identity.name == 'test'
|
||||
@ -131,9 +125,7 @@ def test_mnemonic(identity: Identity) -> None:
|
||||
def test_mnemonic_no_signing_key() -> None:
|
||||
"""Test if the mnemonic property returns None if there is no signing key"""
|
||||
|
||||
identity = Identity.from_address(
|
||||
'@test.bcz76z52y5dlpohtkmpuj3jsdcvfmebzpcgfmtmhu4u7hlexzreya'
|
||||
)
|
||||
identity = Identity.from_address('@test.bcz76z52y5dlpohtkmpuj3jsdcvfmebzpcgfmtmhu4u7hlexzreya')
|
||||
|
||||
assert identity.mnemonic is None
|
||||
|
||||
@ -147,18 +139,13 @@ def test_from_mnemonic() -> None:
|
||||
assert identity.name == name
|
||||
assert identity.sign_key
|
||||
assert identity.sign_key.to_seed() == TEST_SEED
|
||||
assert (
|
||||
str(identity)
|
||||
== f'@{name}.bcz76z52y5dlpohtkmpuj3jsdcvfmebzpcgfmtmhu4u7hlexzreya'
|
||||
)
|
||||
assert str(identity) == f'@{name}.bcz76z52y5dlpohtkmpuj3jsdcvfmebzpcgfmtmhu4u7hlexzreya'
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'address',
|
||||
[
|
||||
pytest.param(
|
||||
'noat.bcz76z52y5dlpohtkmpuj3jsdcvfmebzpcgfmtmhu4u7hlexzreya', id='no_at'
|
||||
),
|
||||
pytest.param('noat.bcz76z52y5dlpohtkmpuj3jsdcvfmebzpcgfmtmhu4u7hlexzreya', id='no_at'),
|
||||
pytest.param(
|
||||
'@toolong.bcz76z52y5dlpohtkmpuj3jsdcvfmebzpcgfmtmhu4u7hlexzreya',
|
||||
id='too_long',
|
||||
@ -180,6 +167,4 @@ def test_valid_address_invalid(address: str) -> None:
|
||||
def test_valid_address() -> None:
|
||||
"""Test if valid_address passes on valid addresses"""
|
||||
|
||||
assert Identity.valid_address(
|
||||
'@test.bcz76z52y5dlpohtkmpuj3jsdcvfmebzpcgfmtmhu4u7hlexzreya'
|
||||
)
|
||||
assert Identity.valid_address('@test.bcz76z52y5dlpohtkmpuj3jsdcvfmebzpcgfmtmhu4u7hlexzreya')
|
||||
|
Loading…
Reference in New Issue
Block a user