Skip to content

Commit

Permalink
refactor: Cached list of languages; test init with bad lang choice
Browse files Browse the repository at this point in the history
  • Loading branch information
fubuloubu committed Mar 3, 2020
1 parent 1191955 commit a75fb65
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 3 additions & 2 deletions eth_account/hdaccount/mnemonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ def get_wordlist(language):
class Mnemonic:
def __init__(self, raw_language="english"):
language = raw_language.lower().replace(' ', '_')
if language not in Mnemonic.list_languages():
languages = Mnemonic.list_languages()
if language not in languages:
raise ValidationError(
f'Invalid language choice "{language}", must be one of {Mnemonic.list_langauges()}'
f'Invalid language choice "{language}", must be one of {languages}'
)
self.language = language
self.wordlist = get_wordlist(language)
Expand Down
2 changes: 2 additions & 0 deletions tests/core/test_mnemonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ def test_detection(language, word):
def test_undetected_language():
with pytest.raises(ValidationError):
Mnemonic.detect_language("xxxxxxx")
with pytest.raises(ValidationError):
Mnemonic("xxxxxxx")


def test_expand_word():
Expand Down

0 comments on commit a75fb65

Please sign in to comment.