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

Method test_basics

Lib/test/test_codecs.py:2159–2237  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2157class BasicUnicodeTest(unittest.TestCase, MixInCheckStateHandling):
2158 @unittest.expectedFailure # TODO: RUSTPYTHON; LookupError: unknown encoding: big5
2159 def test_basics(self):
2160 s = "abc123" # all codecs should be able to encode these
2161 for encoding in all_unicode_encodings:
2162 name = codecs.lookup(encoding).name
2163 if encoding.endswith("_codec"):
2164 name += "_codec"
2165 elif encoding == "latin_1":
2166 name = "latin_1"
2167 # Skip the mbcs alias on Windows
2168 if name != "mbcs":
2169 self.assertEqual(encoding.replace("_", "-"),
2170 name.replace("_", "-"))
2171
2172 (b, size) = codecs.getencoder(encoding)(s)
2173 self.assertEqual(size, len(s), "encoding=%r" % encoding)
2174 (chars, size) = codecs.getdecoder(encoding)(b)
2175 self.assertEqual(chars, s, "encoding=%r" % encoding)
2176
2177 if encoding not in broken_unicode_with_stateful:
2178 # check stream reader/writer
2179 q = Queue(b"")
2180 writer = codecs.getwriter(encoding)(q)
2181 encodedresult = b""
2182 for c in s:
2183 writer.write(c)
2184 chunk = q.read()
2185 self.assertTrue(type(chunk) is bytes, type(chunk))
2186 encodedresult += chunk
2187 q = Queue(b"")
2188 reader = codecs.getreader(encoding)(q)
2189 decodedresult = ""
2190 for c in encodedresult:
2191 q.write(bytes([c]))
2192 decodedresult += reader.read()
2193 self.assertEqual(decodedresult, s, "encoding=%r" % encoding)
2194
2195 if encoding not in broken_unicode_with_stateful:
2196 # check incremental decoder/encoder and iterencode()/iterdecode()
2197 try:
2198 encoder = codecs.getincrementalencoder(encoding)()
2199 except LookupError: # no IncrementalEncoder
2200 pass
2201 else:
2202 # check incremental decoder/encoder
2203 encodedresult = b""
2204 for c in s:
2205 encodedresult += encoder.encode(c)
2206 encodedresult += encoder.encode("", True)
2207 decoder = codecs.getincrementaldecoder(encoding)()
2208 decodedresult = ""
2209 for c in encodedresult:
2210 decodedresult += decoder.decode(bytes([c]))
2211 decodedresult += decoder.decode(b"", True)
2212 self.assertEqual(decodedresult, s,
2213 "encoding=%r" % encoding)
2214
2215 # check iterencode()/iterdecode()
2216 result = "".join(codecs.iterdecode(

Callers

nothing calls this directly

Calls 14

writeMethod · 0.95
readMethod · 0.95
lenFunction · 0.85
assertTrueMethod · 0.80
getreaderMethod · 0.80
iterencodeMethod · 0.80
QueueClass · 0.70
lookupMethod · 0.45
endswithMethod · 0.45
assertEqualMethod · 0.45
replaceMethod · 0.45
encodeMethod · 0.45

Tested by

no test coverage detected