Skip to content

Commit 39e85c0

Browse files
author
Scott Kitterman
committed
Add initial doctests for dmarc_lookup.py
1 parent 42b180d commit 39e85c0

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
UNRELEASED 2024-01-12
22
- Switch from pkg_resources resource_filename to importlib_resources (thanks
33
to Andreas Schneider for the change)
4+
- Add initial doctests for dmarc_lookup.py
45

56
2023-09-11 Version 0.15.3
67
- Fix parsing of psddmarc.org CSV file for PSD domains

authheaders/dmarc_lookup.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@
3636

3737
def answer_to_dict(answer):
3838
# type: (Text) -> Dict[unicode, unicode]
39-
'''Turn the DNS DMARC answer into a dict of tag:value pairs.'''
39+
'''Turn the DNS DMARC answer into a dict of tag:value pairs.
40+
Examples:
41+
>>> answer_to_dict("v=DMARC1\; p=reject\; rua=mailto:dmarc.reports@valimail.com,mailto:dmarc_agg@vali.email\; ruf=mailto:dmarc.reports@valimail.com,mailto:dmarc_c0cb7153_afrf@vali.email")
42+
{'v': 'DMARC1', 'p': 'reject\\\\', 'rua': 'mailto:dmarc.reports@valimail.com,mailto:dmarc_agg@vali.email\\\\', 'ruf': 'mailto:dmarc.reports@valimail.com,mailto:dmarc_c0cb7153_afrf@vali.email'}
43+
>>> answer_to_dict("v=DMARC1\; p=none\; sp=reject")
44+
{'v': 'DMARC1', 'p': 'none\\\\', 'sp': 'reject'}
45+
'''
46+
4047
a = answer.strip('"').strip(' ')
4148
rawTags = [t.split('=') for t in a.split(';') if t]
4249
retval = {t[0].strip().lower(): t[1].strip().lower() for t in rawTags}
@@ -181,3 +188,11 @@ def get_org_domain(domain):
181188
ref = importlib_resources.files('authheaders') / 'public_suffix_list.txt'
182189
with importlib_resources.as_file(ref) as location:
183190
return get_org_domain_from_suffix_list(location, domain)
191+
192+
def _test():
193+
import doctest, dmarc_lookup
194+
return doctest.testmod(dmarc_lookup)
195+
196+
197+
if __name__ == '__main__':
198+
_test()

0 commit comments

Comments
 (0)