Skip to content
Snippets Groups Projects
Commit 76e78a4d authored by ulif's avatar ulif
Browse files

Add test for broken seek().

Add test case that provides a file descriptor with broken seek(). We
must expect "broken" seek() methods for instance with sys.stdin.
parent c4e8288e
No related branches found
No related tags found
No related merge requests found
import os
import pytest
import sys
from io import StringIO
from diceware.wordlist import (
WORDLISTS_DIR, RE_WORDLIST_NAME, RE_NUMBERED_WORDLIST_ENTRY,
RE_VALID_WORDLIST_FILENAME, get_wordlist_path, get_wordlist_names,
......@@ -144,6 +146,15 @@ class TestWordList(object):
assert w_list.fd is not None
assert w_list.path is None
def test_create_accepts_fd_with_broken_seek(self, argv_handler):
# we accept files that have no working seek() (like sys.stdin)
fd = StringIO("word1\nword2\n")
def broken_seek(num):
raise IOError("Illegal seek")
fd.seek = broken_seek
w_list = WordList(fd)
assert w_list.fd is not fd
def test_open_file_descriptor_simple(self, tmpdir):
# we handle simple lists from open file descriptors correctly
in_file = tmpdir.mkdir("work").join("mywordlist")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment