Back to index

python3.2  3.2.2
Public Member Functions
test.test_nntplib.MiscTests Class Reference

List of all members.

Public Member Functions

def test_decode_header
def test_parse_overview_fmt
def test_parse_overview
def test_parse_datetime
def test_unparse_datetime
def test_unparse_datetime_legacy

Detailed Description

Definition at line 1077 of file test_nntplib.py.


Member Function Documentation

Definition at line 1079 of file test_nntplib.py.

01079 
01080     def test_decode_header(self):
01081         def gives(a, b):
01082             self.assertEqual(nntplib.decode_header(a), b)
01083         gives("" , "")
01084         gives("a plain header", "a plain header")
01085         gives(" with extra  spaces ", " with extra  spaces ")
01086         gives("=?ISO-8859-15?Q?D=E9buter_en_Python?=", "Débuter en Python")
01087         gives("=?utf-8?q?Re=3A_=5Bsqlite=5D_probl=C3=A8me_avec_ORDER_BY_sur_des_cha?="
01088               " =?utf-8?q?=C3=AEnes_de_caract=C3=A8res_accentu=C3=A9es?=",
01089               "Re: [sqlite] problème avec ORDER BY sur des chaînes de caractères accentuées")
01090         gives("Re: =?UTF-8?B?cHJvYmzDqG1lIGRlIG1hdHJpY2U=?=",
01091               "Re: problème de matrice")
01092         # A natively utf-8 header (found in the real world!)
01093         gives("Re: Message d'erreur incompréhensible (par moi)",
01094               "Re: Message d'erreur incompréhensible (par moi)")

Here is the call graph for this function:

Definition at line 1181 of file test_nntplib.py.

01181 
01182     def test_parse_datetime(self):
01183         def gives(a, b, *c):
01184             self.assertEqual(nntplib._parse_datetime(a, b),
01185                              datetime.datetime(*c))
01186         # Output of DATE command
01187         gives("19990623135624", None, 1999, 6, 23, 13, 56, 24)
01188         # Variations
01189         gives("19990623", "135624", 1999, 6, 23, 13, 56, 24)
01190         gives("990623", "135624", 1999, 6, 23, 13, 56, 24)
01191         gives("090623", "135624", 2009, 6, 23, 13, 56, 24)

Here is the call graph for this function:

Definition at line 1135 of file test_nntplib.py.

01135 
01136     def test_parse_overview(self):
01137         fmt = nntplib._DEFAULT_OVERVIEW_FMT + ["xref"]
01138         # First example from RFC 3977
01139         lines = [
01140             '3000234\tI am just a test article\t"Demo User" '
01141             '<nobody@example.com>\t6 Oct 1998 04:38:40 -0500\t'
01142             '<45223423@example.com>\t<45454@example.net>\t1234\t'
01143             '17\tXref: news.example.com misc.test:3000363',
01144         ]
01145         overview = nntplib._parse_overview(lines, fmt)
01146         (art_num, fields), = overview
01147         self.assertEqual(art_num, 3000234)
01148         self.assertEqual(fields, {
01149             'subject': 'I am just a test article',
01150             'from': '"Demo User" <nobody@example.com>',
01151             'date': '6 Oct 1998 04:38:40 -0500',
01152             'message-id': '<45223423@example.com>',
01153             'references': '<45454@example.net>',
01154             ':bytes': '1234',
01155             ':lines': '17',
01156             'xref': 'news.example.com misc.test:3000363',
01157         })
01158         # Second example; here the "Xref" field is totally absent (including
01159         # the header name) and comes out as None
01160         lines = [
01161             '3000234\tI am just a test article\t"Demo User" '
01162             '<nobody@example.com>\t6 Oct 1998 04:38:40 -0500\t'
01163             '<45223423@example.com>\t<45454@example.net>\t1234\t'
01164             '17\t\t',
01165         ]
01166         overview = nntplib._parse_overview(lines, fmt)
01167         (art_num, fields), = overview
01168         self.assertEqual(fields['xref'], None)
01169         # Third example; the "Xref" is an empty string, while "references"
01170         # is a single space.
01171         lines = [
01172             '3000234\tI am just a test article\t"Demo User" '
01173             '<nobody@example.com>\t6 Oct 1998 04:38:40 -0500\t'
01174             '<45223423@example.com>\t \t1234\t'
01175             '17\tXref: \t',
01176         ]
01177         overview = nntplib._parse_overview(lines, fmt)
01178         (art_num, fields), = overview
01179         self.assertEqual(fields['references'], ' ')
01180         self.assertEqual(fields['xref'], '')

Here is the call graph for this function:

Definition at line 1095 of file test_nntplib.py.

01095 
01096     def test_parse_overview_fmt(self):
01097         # The minimal (default) response
01098         lines = ["Subject:", "From:", "Date:", "Message-ID:",
01099                  "References:", ":bytes", ":lines"]
01100         self.assertEqual(nntplib._parse_overview_fmt(lines),
01101             ["subject", "from", "date", "message-id", "references",
01102              ":bytes", ":lines"])
01103         # The minimal response using alternative names
01104         lines = ["Subject:", "From:", "Date:", "Message-ID:",
01105                  "References:", "Bytes:", "Lines:"]
01106         self.assertEqual(nntplib._parse_overview_fmt(lines),
01107             ["subject", "from", "date", "message-id", "references",
01108              ":bytes", ":lines"])
01109         # Variations in casing
01110         lines = ["subject:", "FROM:", "DaTe:", "message-ID:",
01111                  "References:", "BYTES:", "Lines:"]
01112         self.assertEqual(nntplib._parse_overview_fmt(lines),
01113             ["subject", "from", "date", "message-id", "references",
01114              ":bytes", ":lines"])
01115         # First example from RFC 3977
01116         lines = ["Subject:", "From:", "Date:", "Message-ID:",
01117                  "References:", ":bytes", ":lines", "Xref:full",
01118                  "Distribution:full"]
01119         self.assertEqual(nntplib._parse_overview_fmt(lines),
01120             ["subject", "from", "date", "message-id", "references",
01121              ":bytes", ":lines", "xref", "distribution"])
01122         # Second example from RFC 3977
01123         lines = ["Subject:", "From:", "Date:", "Message-ID:",
01124                  "References:", "Bytes:", "Lines:", "Xref:FULL",
01125                  "Distribution:FULL"]
01126         self.assertEqual(nntplib._parse_overview_fmt(lines),
01127             ["subject", "from", "date", "message-id", "references",
01128              ":bytes", ":lines", "xref", "distribution"])
01129         # A classic response from INN
01130         lines = ["Subject:", "From:", "Date:", "Message-ID:",
01131                  "References:", "Bytes:", "Lines:", "Xref:full"]
01132         self.assertEqual(nntplib._parse_overview_fmt(lines),
01133             ["subject", "from", "date", "message-id", "references",
01134              ":bytes", ":lines", "xref"])

Here is the call graph for this function:

Definition at line 1192 of file test_nntplib.py.

01192 
01193     def test_unparse_datetime(self):
01194         # Test non-legacy mode
01195         # 1) with a datetime
01196         def gives(y, M, d, h, m, s, date_str, time_str):
01197             dt = datetime.datetime(y, M, d, h, m, s)
01198             self.assertEqual(nntplib._unparse_datetime(dt),
01199                              (date_str, time_str))
01200             self.assertEqual(nntplib._unparse_datetime(dt, False),
01201                              (date_str, time_str))
01202         gives(1999, 6, 23, 13, 56, 24, "19990623", "135624")
01203         gives(2000, 6, 23, 13, 56, 24, "20000623", "135624")
01204         gives(2010, 6, 5, 1, 2, 3, "20100605", "010203")
01205         # 2) with a date
01206         def gives(y, M, d, date_str, time_str):
01207             dt = datetime.date(y, M, d)
01208             self.assertEqual(nntplib._unparse_datetime(dt),
01209                              (date_str, time_str))
01210             self.assertEqual(nntplib._unparse_datetime(dt, False),
01211                              (date_str, time_str))
01212         gives(1999, 6, 23, "19990623", "000000")
01213         gives(2000, 6, 23, "20000623", "000000")
01214         gives(2010, 6, 5, "20100605", "000000")

Here is the call graph for this function:

Definition at line 1215 of file test_nntplib.py.

01215 
01216     def test_unparse_datetime_legacy(self):
01217         # Test legacy mode (RFC 977)
01218         # 1) with a datetime
01219         def gives(y, M, d, h, m, s, date_str, time_str):
01220             dt = datetime.datetime(y, M, d, h, m, s)
01221             self.assertEqual(nntplib._unparse_datetime(dt, True),
01222                              (date_str, time_str))
01223         gives(1999, 6, 23, 13, 56, 24, "990623", "135624")
01224         gives(2000, 6, 23, 13, 56, 24, "000623", "135624")
01225         gives(2010, 6, 5, 1, 2, 3, "100605", "010203")
01226         # 2) with a date
01227         def gives(y, M, d, date_str, time_str):
01228             dt = datetime.date(y, M, d)
01229             self.assertEqual(nntplib._unparse_datetime(dt, True),
01230                              (date_str, time_str))
01231         gives(1999, 6, 23, "990623", "000000")
01232         gives(2000, 6, 23, "000623", "000000")
01233         gives(2010, 6, 5, "100605", "000000")
01234 

Here is the call graph for this function:


The documentation for this class was generated from the following file: