Skip to content

Commit 636c8a5

Browse files
committed
Tests: move sample files into separate subdir
1 parent 3866689 commit 636c8a5

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed
File renamed without changes.
File renamed without changes.

tests/utils.py

+26-8
Original file line numberDiff line numberDiff line change
@@ -35,33 +35,51 @@ def decode_att(att):
3535
return b64decode(att.encode('ascii'))
3636

3737

38+
#
39+
# Sample files for testing (in ./test_files subdir)
40+
#
41+
42+
TEST_FILES_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'test_files')
43+
3844
SAMPLE_IMAGE_FILENAME = "sample_image.png"
3945
SAMPLE_EMAIL_FILENAME = "sample_email.txt"
4046

4147

48+
def test_file_path(filename):
49+
"""Returns path to a test file"""
50+
return os.path.join(TEST_FILES_DIR, filename)
51+
52+
53+
def test_file_content(filename):
54+
"""Returns contents (bytes) of a test file"""
55+
path = test_file_path(filename)
56+
with open(path, "rb") as f:
57+
return f.read()
58+
59+
4260
def sample_image_path(filename=SAMPLE_IMAGE_FILENAME):
4361
"""Returns path to an actual image file in the tests directory"""
44-
test_dir = os.path.dirname(os.path.abspath(__file__))
45-
path = os.path.join(test_dir, filename)
46-
return path
62+
return test_file_path(filename)
4763

4864

4965
def sample_image_content(filename=SAMPLE_IMAGE_FILENAME):
5066
"""Returns contents of an actual image file from the tests directory"""
51-
filename = sample_image_path(filename)
52-
with open(filename, "rb") as f:
53-
return f.read()
67+
return test_file_content(filename)
5468

5569

5670
def sample_email_path(filename=SAMPLE_EMAIL_FILENAME):
5771
"""Returns path to an email file (e.g., for forwarding as an attachment)"""
58-
return sample_image_path(filename) # borrow path logic from above
72+
return test_file_path(filename)
5973

6074

6175
def sample_email_content(filename=SAMPLE_EMAIL_FILENAME):
6276
"""Returns bytes contents of an email file (e.g., for forwarding as an attachment)"""
63-
return sample_image_content(filename) # borrow read logic from above
77+
return test_file_content(filename)
78+
6479

80+
#
81+
# TestCase helpers
82+
#
6583

6684
# noinspection PyUnresolvedReferences
6785
class AnymailTestMixin:

0 commit comments

Comments
 (0)