This commit is contained in:
wittmannzl103469 committed 2026-11-05 15:08:42 +01:00
1 parent de41a02749
commit 9af09cebd3
764 files changed
+54218 -78859

No files matched your search

@@ -1,14 +1,12 @@
import pathlib
import platform
import sys
import unittest
from pygame import encode_file_path, encode_string
IS_PYPY = "PyPy" == platform.python_implementation()
from pygame import encode_string, encode_file_path
class RWopsEncodeStringTest(unittest.TestCase):
global getrefcount
def test_obj_None(self):
encoded_string = encode_string(None)
@@ -21,13 +19,13 @@ class RWopsEncodeStringTest(unittest.TestCase):
self.assertIsInstance(encoded_string, bytes)
def test_obj_bytes(self):
b = b"encyclop\xe6dia"
b = b"encyclop\xE6dia"
encoded_string = encode_string(b, "ascii", "strict")
self.assertIs(encoded_string, b)
def test_encode_unicode(self):
u = "\u00dee Olde Komp\u00fcter Shoppe"
u = "\u00DEe Olde Komp\u00FCter Shoppe"
b = u.encode("utf-8")
self.assertEqual(encode_string(u, "utf-8"), b)
@@ -35,7 +33,7 @@ class RWopsEncodeStringTest(unittest.TestCase):
self.assertRaises(SyntaxError, encode_string)
def test_errors(self):
u = "abc\u0109defg\u011dh\u0125ij\u0135klmnoprs\u015dtu\u016dvz"
u = "abc\u0109defg\u011Dh\u0125ij\u0135klmnoprs\u015Dtu\u016Dvz"
b = u.encode("ascii", "ignore")
self.assertEqual(encode_string(u, "ascii", "ignore"), b)
@@ -46,7 +44,7 @@ class RWopsEncodeStringTest(unittest.TestCase):
self.assertIsNone(encoded_string)
def test_check_defaults(self):
u = "a\u01f7b"
u = "a\u01F7b"
b = u.encode("unicode_escape", "backslashreplace")
encoded_string = encode_string(u)
@@ -70,19 +68,26 @@ class RWopsEncodeStringTest(unittest.TestCase):
self.assertIs(encoded_string, b)
self.assertEqual(encoded_decode_string, b)
@unittest.skipIf(IS_PYPY, "getrefcount not available on pypy")
def test_refcount(self):
bpath = b" This is a string that is not cached."[1:]
upath = bpath.decode("ascii")
before = sys.getrefcount(bpath)
bpath = encode_string(bpath)
self.assertEqual(sys.getrefcount(bpath), 2)
bpath = encode_string(upath)
self.assertIn(sys.getrefcount(bpath), (before, before - 1))
try:
from sys import getrefcount as _g
getrefcount = _g # This nonsense is for Python 3.x
except ImportError:
pass
else:
def test_refcount(self):
bpath = b" This is a string that is not cached."[1:]
upath = bpath.decode("ascii")
before = getrefcount(bpath)
bpath = encode_string(bpath)
self.assertEqual(getrefcount(bpath), before)
bpath = encode_string(upath)
self.assertEqual(getrefcount(bpath), before)
def test_smp(self):
utf_8 = b"a\xf0\x93\x82\xa7b"
u = "a\U000130a7b"
utf_8 = b"a\xF0\x93\x82\xA7b"
u = "a\U000130A7b"
b = encode_string(u, "utf-8", "strict", AssertionError)
self.assertEqual(b, utf_8)