Skip to content

Commit

Permalink
Merge pull request #49 from AndreMiras/feature/ticket9_run_doctests
Browse files Browse the repository at this point in the history
Run doctests with tox
  • Loading branch information
carver authored Jan 9, 2020
2 parents 9bcc910 + 8d99dea commit 692cf9d
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 28 deletions.
39 changes: 19 additions & 20 deletions eth_account/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,21 +106,21 @@ def decrypt(keyfile_json, password):
.. code-block:: python
>>> encrypted = {
'address': '5ce9454909639d2d17a3f753ce7d93fa0b9ab12e',
'crypto': {'cipher': 'aes-128-ctr',
'cipherparams': {'iv': '78f214584844e0b241b433d7c3bb8d5f'},
'ciphertext': 'd6dbb56e4f54ba6db2e8dc14df17cb7352fdce03681dd3f90ce4b6c1d5af2c4f',
'kdf': 'pbkdf2',
'kdfparams': {'c': 1000000,
'dklen': 32,
'prf': 'hmac-sha256',
'salt': '45cf943b4de2c05c2c440ef96af914a2'},
'mac': 'f5e1af09df5ded25c96fcf075ada313fb6f79735a914adc8cb02e8ddee7813c3'},
'id': 'b812f3f9-78cc-462a-9e89-74418aa27cb0',
'version': 3}
... 'address': '5ce9454909639d2d17a3f753ce7d93fa0b9ab12e',
... 'crypto': {'cipher': 'aes-128-ctr',
... 'cipherparams': {'iv': '78f214584844e0b241b433d7c3bb8d5f'},
... 'ciphertext': 'd6dbb56e4f54ba6db2e8dc14df17cb7352fdce03681dd3f90ce4b6c1d5af2c4f',
... 'kdf': 'pbkdf2',
... 'kdfparams': {'c': 1000000,
... 'dklen': 32,
... 'prf': 'hmac-sha256',
... 'salt': '45cf943b4de2c05c2c440ef96af914a2'},
... 'mac': 'f5e1af09df5ded25c96fcf075ada313fb6f79735a914adc8cb02e8ddee7813c3'},
... 'id': 'b812f3f9-78cc-462a-9e89-74418aa27cb0',
... 'version': 3}
>>> import getpass
>>> Account.decrypt(encrypted, getpass.getpass())
>>> Account.decrypt(encrypted, getpass.getpass()) # doctest: +SKIP
HexBytes('0xb25c7db31feed9122727bf0939dc769a96564b2de4c4726d035b36ecf1e5b364')
"""
Expand Down Expand Up @@ -156,11 +156,10 @@ def encrypt(cls, private_key, password, kdf=None, iterations=None):
.. code-block:: python
>>> import getpass
>>> encrypted = Account.encrypt(
0xb25c7db31feed9122727bf0939dc769a96564b2de4c4726d035b36ecf1e5b364,
getpass.getpass()
)
>>> encrypted = Account.encrypt( # doctest: +SKIP
... 0xb25c7db31feed9122727bf0939dc769a96564b2de4c4726d035b36ecf1e5b364,
... getpass.getpass()
... )
{
'address': '5ce9454909639d2d17a3f753ce7d93fa0b9ab12e',
'crypto': {
Expand All @@ -183,8 +182,8 @@ def encrypt(cls, private_key, password, kdf=None, iterations=None):
'version': 3
}
>>> with open('my-keyfile', 'w') as f:
f.write(json.dumps(encrypted))
>>> with open('my-keyfile', 'w') as f: # doctest: +SKIP
... f.write(json.dumps(encrypted))
"""
if isinstance(private_key, keys.PrivateKey):
key_bytes = private_key.to_bytes()
Expand Down
4 changes: 2 additions & 2 deletions eth_account/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,13 @@ def encode_defunct(
SignableMessage(version=b'E', header=b'thereum Signed Message:\n6', body=b'I\xe2\x99\xa5SF')
# these four also produce the same hash:
>>> encode_defunct(w3.toBytes(text=message_text))
>>> encode_defunct(w3.toBytes(text=message_text)) # doctest: +SKIP
SignableMessage(version=b'E', header=b'thereum Signed Message:\n6', body=b'I\xe2\x99\xa5SF')
>>> encode_defunct(bytes(message_text, encoding='utf-8'))
SignableMessage(version=b'E', header=b'thereum Signed Message:\n6', body=b'I\xe2\x99\xa5SF')
>>> Web3.toHex(text=message_text)
>>> Web3.toHex(text=message_text) # doctest: +SKIP
'0x49e299a55346'
>>> encode_defunct(hexstr='0x49e299a55346')
SignableMessage(version=b'E', header=b'thereum Signed Message:\n6', body=b'I\xe2\x99\xa5SF')
Expand Down
2 changes: 1 addition & 1 deletion eth_account/signers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def address(self):
.. code-block:: python
>>> my_account.address
>>> my_account.address # doctest: +SKIP
"0xF0109fC8DF283027b6285cc889F5aA624EaC1F55"
"""
Expand Down
6 changes: 3 additions & 3 deletions eth_account/signers/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ class LocalAccount(BaseAccount):
.. code-block:: python
>>> my_local_account.address
>>> my_local_account.address # doctest: +SKIP
"0xF0109fC8DF283027b6285cc889F5aA624EaC1F55"
>>> my_local_account.key
>>> my_local_account.key # doctest: +SKIP
b"\x01\x23..."
You can also get the private key by casting the account to :class:`bytes`:
.. code-block:: python
>>> bytes(my_local_account)
>>> bytes(my_local_account) # doctest: +SKIP
b"\\x01\\x23..."
"""
def __init__(self, key, account):
Expand Down
2 changes: 1 addition & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[pytest]
addopts= -v --showlocals --durations 10
addopts= -v --showlocals --doctest-modules --durations 10
python_paths= .
xfail_strict=true

Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ignore=
[testenv]
usedevelop=True
commands=
core: pytest {posargs:tests/core}
core: pytest {posargs:tests/core eth_account}
doctest: make -C {toxinidir}/docs doctest
basepython =
doctest: python
Expand Down

0 comments on commit 692cf9d

Please sign in to comment.