def test_string_with_null_bytes(self):
        b = as_bytes("a\x00b\x00c")
        encoded_string = encode_string(b, etype=SyntaxError)
        encoded_decode_string = encode_string(b.decode(), "ascii", "strict")

        self.assertIs(encoded_string, b)
        self.assertEqual(encoded_decode_string, b)
 def test_refcount(self):
     bpath = as_bytes(" 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_pathlib_obj(self):
        """Test loading string representation of pathlib object"""
        """
        We do this because pygame functions internally use pg_EncodeString
        to decode the filenames passed to them. So if we test that here, we
        can safely assume that all those functions do not have any issues
        with pathlib objects
        """
        encoded = encode_string(pathlib.PurePath("foo"), "utf-8")
        self.assertEqual(encoded, b"foo")

        encoded = encode_string(pathlib.Path("baz"))
        self.assertEqual(encoded, b"baz")
Exemple #4
0
def main():
    numpass, numfail = pg.init()
    print(f'pass:{numpass}, fail:{numfail}')

    inited = pg.get_init()
    print(f'Inited: {inited}')

    try:
        raise pg.error('Custom Error')
    except RuntimeError as re:
        print(f'Exception: {re}')

    pg.set_error('Set Error')
    err = pg.get_error()
    print(f'Error: {err}')

    major, minor, path = pg.get_sdl_version()
    print(f'SDL: {major}.{minor}.{path}')

    pg.register_quit(quit)

    unencoded = '你好'
    encoded = pg.encode_string(unencoded, encoding='utf-8')
    print(f'Encoded: {encoded}, Original: {unencoded}')

    encoded_path = pg.encode_file_path(os.path.join(__file__))
    print(f'Encoded Path: {encoded_path}')

    print(f'{pg.version.PygameVersion(1, 2, 3)}, {pg.vernum}')
 def test_errors(self):
     s = r"abc\u0109defg\u011Dh\u0125ij\u0135klmnoprs\u015Dtu\u016Dvz"
     u = as_unicode(s)
     b = u.encode('ascii', 'ignore')
     self.assertEqual(encode_string(u, 'ascii', 'ignore'), b)
 def test_string_with_null_bytes(self):
     b = as_bytes("a\x00b\x00c")
     self.assert_(encode_string(b, etype=SyntaxError) is b)
     u = b.decode()
     self.assert_(encode_string(u, 'ascii', 'strict') == b)
 def test_encoding_error(self):
     u = as_unicode(r"a\x80b")
     self.assert_(encode_string(u, 'ascii', 'strict') is None)
 def test_encode_unicode(self):
     u = as_unicode(r"\u00DEe Olde Komp\u00FCter Shoppe")
     b = u.encode('utf-8')
     self.assertEqual(encode_string(u, 'utf-8'), b)
Exemple #9
0
 def test_encode_unicode(self):
     u = "\u00DEe Olde Komp\u00FCter Shoppe"
     b = u.encode("utf-8")
     self.assertEqual(encode_string(u, "utf-8"), b)
 def test_string_with_null_bytes(self):
     b = as_bytes("a\x00b\x00c")
     self.assert_(encode_string(b, etype=SyntaxError) is b)
     u = b.decode()
     self.assert_(encode_string(u, 'ascii', 'strict') == b)
    def test_obj_bytes(self):
        b = as_bytes("encyclop\xE6dia")
        encoded_string = encode_string(b, "ascii", "strict")

        self.assertIs(encoded_string, b)
    def test_returns_bytes(self):
        u = as_unicode(r"Hello")
        encoded_string = encode_string(u)

        self.assertIsInstance(encoded_string, bytes_)
    def test_obj_None(self):
        encoded_string = encode_string(None)

        self.assertIsNone(encoded_string)
Exemple #14
0
 def test_smp(self):
     utf_8 = b"a\xF0\x93\x82\xA7b"
     u = "a\U000130A7b"
     b = encode_string(u, "utf-8", "strict", AssertionError)
     self.assertEqual(b, utf_8)
Exemple #15
0
    def test_check_defaults(self):
        u = "a\u01F7b"
        b = u.encode("unicode_escape", "backslashreplace")
        encoded_string = encode_string(u)

        self.assertEqual(encoded_string, b)
Exemple #16
0
 def test_errors(self):
     u = "abc\u0109defg\u011Dh\u0125ij\u0135klmnoprs\u015Dtu\u016Dvz"
     b = u.encode("ascii", "ignore")
     self.assertEqual(encode_string(u, "ascii", "ignore"), b)
 def test_encoding_error(self):
     u = as_unicode(r"a\x80b")
     self.assert_(encode_string(u, 'ascii', 'strict') is None)
 def test_smp(self):
     utf_8 = as_bytes("a\xF0\x93\x82\xA7b")
     u = as_unicode(r"a\U000130A7b")
     b = encode_string(u, 'utf-8', 'strict', AssertionError)
     self.assertEqual(b, utf_8)
 def test_check_defaults(self):
     u = as_unicode(r"a\u01F7b")
     b = u.encode("unicode_escape", "backslashreplace") 
     self.assert_(encode_string(u) == b)
 def test_returns_bytes(self):
     u = as_unicode(r"Hello")
     self.assert_(isinstance(encode_string(u), bytes_))
    def test_encoding_error(self):
        u = as_unicode(r"a\x80b")
        encoded_string = encode_string(u, "ascii", "strict")

        self.assertIsNone(encoded_string)
Exemple #22
0
    def test_returns_bytes(self):
        u = "Hello"
        encoded_string = encode_string(u)

        self.assertIsInstance(encoded_string, bytes)
 def test_obj_None(self):
     self.assert_(encode_string(None) is None)
 def test_obj_None(self):
     self.assert_(encode_string(None) is None)
 def test_obj_bytes(self):
     b = as_bytes("encyclop\xE6dia")
     self.assert_(encode_string(b, 'ascii', 'strict') is b)
 def test_returns_bytes(self):
     u = as_unicode(r"Hello")
     self.assert_(isinstance(encode_string(u), bytes_))
 def test_errors(self):
     s = r"abc\u0109defg\u011Dh\u0125ij\u0135klmnoprs\u015Dtu\u016Dvz"
     u = as_unicode(s)
     b = u.encode('ascii', 'ignore')
     self.assertEqual(encode_string(u, 'ascii', 'ignore'), b)
 def test_obj_bytes(self):
     b = as_bytes("encyclop\xE6dia")
     self.assert_(encode_string(b, 'ascii', 'strict') is b)
 def test_check_defaults(self):
     u = as_unicode(r"a\u01F7b")
     b = u.encode("unicode_escape", "backslashreplace")
     self.assert_(encode_string(u) == b)
 def test_encode_unicode(self):
     u = as_unicode(r"\u00DEe Olde Komp\u00FCter Shoppe")
     b = u.encode('utf-8')
     self.assertEqual(encode_string(u, 'utf-8'), b)
 def test_smp(self):
     utf_8 = as_bytes("a\xF0\x93\x82\xA7b")
     u = as_unicode(r"a\U000130A7b")
     b = encode_string(u, 'utf-8', 'strict', AssertionError)
     self.assertEqual(b, utf_8)
Exemple #32
0
    def test_obj_bytes(self):
        b = as_bytes("encyclop\xE6dia")
        encoded_string = encode_string(b, 'ascii', 'strict')

        self.assertIs(encoded_string, b)
 def test_refcount(self):
     bpath = as_bytes(" 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)