MCPcopy Index your code
hub / github.com/RustPython/RustPython / TestParser

Class TestParser

Lib/test/test_email/test__header_value_parser.py:45–2868  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43
44
45class TestParser(TestParserMixin, TestEmailBase):
46
47 # _wsp_splitter
48
49 rfc_printable_ascii = bytes(range(33, 127)).decode('ascii')
50 rfc_atext_chars = (string.ascii_letters + string.digits +
51 "!#$%&\'*+-/=?^_`{}|~")
52 rfc_dtext_chars = rfc_printable_ascii.translate(str.maketrans('','',r'\[]'))
53
54 def test__wsp_splitter_one_word(self):
55 self.assertEqual(parser._wsp_splitter('foo', 1), ['foo'])
56
57 def test__wsp_splitter_two_words(self):
58 self.assertEqual(parser._wsp_splitter('foo def', 1),
59 ['foo', ' ', 'def'])
60
61 def test__wsp_splitter_ws_runs(self):
62 self.assertEqual(parser._wsp_splitter('foo \t def jik', 1),
63 ['foo', ' \t ', 'def jik'])
64
65
66 # get_fws
67
68 def test_get_fws_only(self):
69 fws = self._test_get_x(parser.get_fws, ' \t ', ' \t ', ' ', [], '')
70 self.assertEqual(fws.token_type, 'fws')
71
72 def test_get_fws_space(self):
73 self._test_get_x(parser.get_fws, ' foo', ' ', ' ', [], 'foo')
74
75 def test_get_fws_ws_run(self):
76 self._test_get_x(parser.get_fws, ' \t foo ', ' \t ', ' ', [], 'foo ')
77
78 # get_encoded_word
79
80 def test_get_encoded_word_missing_start_raises(self):
81 with self.assertRaises(errors.HeaderParseError):
82 parser.get_encoded_word('abc')
83
84 def test_get_encoded_word_missing_end_raises(self):
85 with self.assertRaises(errors.HeaderParseError):
86 parser.get_encoded_word('=?abc')
87
88 def test_get_encoded_word_missing_middle_raises(self):
89 with self.assertRaises(errors.HeaderParseError):
90 parser.get_encoded_word('=?abc?=')
91
92 def test_get_encoded_word_invalid_cte(self):
93 with self.assertRaises(errors.HeaderParseError):
94 parser.get_encoded_word('=?utf-8?X?somevalue?=')
95
96 def test_get_encoded_word_valid_ew(self):
97 self._test_get_x(parser.get_encoded_word,
98 '=?us-ascii?q?this_is_a_test?= bird',
99 'this is a test',
100 'this is a test',
101 [],
102 ' bird')

Callers

nothing calls this directly

Calls 3

decodeMethod · 0.45
translateMethod · 0.45
maketransMethod · 0.45

Tested by

no test coverage detected