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