def test_invalid_wordlist(self): s = StringIO(six.u('\n'.join([ 'alpha', 'invalid?syntax', ]))) with self.assertRaisesRegex( InitializationError, r"Invalid config: Invalid syntax " r"at list 'words' line 2: u?'invalid\?syntax'"): _load_wordlist('words', s)
def test_phrase_too_long(self): s = StringIO( six.u('\n'.join([ 'max_length = 9', 'alpha beta', 'gamma delta', # 10 characters ]))) with self.assertRaisesRegex( InitializationError, r"Invalid config: Phrase is too long " r"at list 'words' line 3: u?'gamma delta'"): _load_wordlist('words', s)
def test_word_too_long(self): s = StringIO( six.u('\n'.join([ 'max_length = 11', 'alpha', 'augmentation', # line exceeds 11 characters ]))) with self.assertRaisesRegex( InitializationError, r"Invalid config: Word is too long " r"at list 'words' line 3: u?'augmentation'"): _load_wordlist('words', s)
def test_load_wordlist_max_length(self): s = StringIO(six.u('\n'.join([ 'max_length = 11', 'alpha', ]))) wordlist = _load_wordlist('words', s) self.assertEqual(wordlist, { 'type': 'words', 'max_length': 11, 'words': ['alpha'] })
def test_load_phrases(self): s = StringIO( six.u('\n'.join( ['one', 'two', 'three', 'four five', 'six', 'seven eight']))) wordlist = _load_wordlist('phrases', s) self.assertEqual( wordlist, { 'type': 'phrases', 'phrases': [('one', ), ('two', ), ('three', ), ('four', 'five'), ('six', ), ('seven', 'eight')] })
def test_load_wordlist(self): s = StringIO( six.u('\n'.join([ 'alpha', '', # blank line 'beta', '# Some comment', 'gamma', ]))) wordlist = _load_wordlist('words', s) self.assertEqual(wordlist, { 'type': 'words', 'words': ['alpha', 'beta', 'gamma'] })