Skip to content

Commit 316b003

Browse files
author
Steve Canny
committed
test: add snippet infrastructure
1 parent 7fb29b1 commit 316b003

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tests/unitutil/file.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,33 @@ def docx_path(name):
2727
return absjoin(test_file_dir, '%s.docx' % name)
2828

2929

30+
def snippet_seq(name, offset=0, count=1024):
31+
"""
32+
Return a tuple containing the unicode text snippets read from the snippet
33+
file having *name*. Snippets are delimited by a blank line. If specified,
34+
*count* snippets starting at *offset* are returned.
35+
"""
36+
path = os.path.join(test_file_dir, 'snippets', '%s.txt' % name)
37+
with open(path, 'rb') as f:
38+
text = f.read().decode('utf-8')
39+
snippets = text.split('\n\n')
40+
start, end = offset, offset+count
41+
return tuple(snippets[start:end])
42+
43+
44+
def snippet_text(snippet_file_name):
45+
"""
46+
Return the unicode text read from the test snippet file having
47+
*snippet_file_name*.
48+
"""
49+
snippet_file_path = os.path.join(
50+
test_file_dir, 'snippets', '%s.txt' % snippet_file_name
51+
)
52+
with open(snippet_file_path, 'rb') as f:
53+
snippet_bytes = f.read()
54+
return snippet_bytes.decode('utf-8')
55+
56+
3057
def test_file(name):
3158
"""
3259
Return the absolute path to test file having *name*.

0 commit comments

Comments
 (0)