Skip to content

Commit

Permalink
Fixed relevant style_check errors (remaining are unrelated to pull)
Browse files Browse the repository at this point in the history
  • Loading branch information
pjkundert authored and matejcik committed Apr 28, 2022
1 parent e95d285 commit e81a50c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/mnemonic/mnemonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,11 @@ def detect_language(cls, code: str) -> str:
possible = set(p for p in possible if word in p.wordlist)
if not possible:
raise ConfigurationError(f"Language unrecognized for {word!r}")
if len( possible ) == 1:
if len(possible) == 1:
return possible.pop().language
raise ConfigurationError(f"Language ambiguous between {', '.join( p.language for p in possible)}")
raise ConfigurationError(
f"Language ambiguous between {', '.join( p.language for p in possible)}"
)

def generate(self, strength: int = 128) -> str:
"""
Expand Down
8 changes: 6 additions & 2 deletions tests/test_mnemonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,14 @@ def test_detection(self) -> None:
self.assertEqual("english", Mnemonic.detect_language("security"))

with self.assertRaises(Exception):
Mnemonic.detect_language("jaguar xxxxxxx") # Unrecognized in any known language
Mnemonic.detect_language(
"jaguar xxxxxxx"
) # Unrecognized in any known language

with self.assertRaises(Exception):
Mnemonic.detect_language("jaguar jaguar") # Ambiguous after examining all words
Mnemonic.detect_language(
"jaguar jaguar"
) # Ambiguous after examining all words

self.assertEqual("english", Mnemonic.detect_language("jaguar security"))
self.assertEqual("french", Mnemonic.detect_language("jaguar aboyer"))
Expand Down

0 comments on commit e81a50c

Please sign in to comment.