コード例 #1
0
    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)
コード例 #2
0
 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)
コード例 #3
0
    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")
コード例 #4
0
ファイル: pg_learn.py プロジェクト: webji/adarith
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}')
コード例 #5
0
 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)
コード例 #6
0
 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)
コード例 #7
0
 def test_encoding_error(self):
     u = as_unicode(r"a\x80b")
     self.assert_(encode_string(u, 'ascii', 'strict') is None)
コード例 #8
0
 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)
コード例 #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)
コード例 #10
0
 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)
コード例 #11
0
    def test_obj_bytes(self):
        b = as_bytes("encyclop\xE6dia")
        encoded_string = encode_string(b, "ascii", "strict")

        self.assertIs(encoded_string, b)
コード例 #12
0
    def test_returns_bytes(self):
        u = as_unicode(r"Hello")
        encoded_string = encode_string(u)

        self.assertIsInstance(encoded_string, bytes_)
コード例 #13
0
    def test_obj_None(self):
        encoded_string = encode_string(None)

        self.assertIsNone(encoded_string)
コード例 #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)
コード例 #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)
コード例 #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)
コード例 #17
0
 def test_encoding_error(self):
     u = as_unicode(r"a\x80b")
     self.assert_(encode_string(u, 'ascii', 'strict') is None)
コード例 #18
0
 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)
コード例 #19
0
 def test_check_defaults(self):
     u = as_unicode(r"a\u01F7b")
     b = u.encode("unicode_escape", "backslashreplace") 
     self.assert_(encode_string(u) == b)
コード例 #20
0
 def test_returns_bytes(self):
     u = as_unicode(r"Hello")
     self.assert_(isinstance(encode_string(u), bytes_))
コード例 #21
0
    def test_encoding_error(self):
        u = as_unicode(r"a\x80b")
        encoded_string = encode_string(u, "ascii", "strict")

        self.assertIsNone(encoded_string)
コード例 #22
0
    def test_returns_bytes(self):
        u = "Hello"
        encoded_string = encode_string(u)

        self.assertIsInstance(encoded_string, bytes)
コード例 #23
0
 def test_obj_None(self):
     self.assert_(encode_string(None) is None)
コード例 #24
0
 def test_obj_None(self):
     self.assert_(encode_string(None) is None)
コード例 #25
0
 def test_obj_bytes(self):
     b = as_bytes("encyclop\xE6dia")
     self.assert_(encode_string(b, 'ascii', 'strict') is b)
コード例 #26
0
 def test_returns_bytes(self):
     u = as_unicode(r"Hello")
     self.assert_(isinstance(encode_string(u), bytes_))
コード例 #27
0
 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)
コード例 #28
0
 def test_obj_bytes(self):
     b = as_bytes("encyclop\xE6dia")
     self.assert_(encode_string(b, 'ascii', 'strict') is b)
コード例 #29
0
 def test_check_defaults(self):
     u = as_unicode(r"a\u01F7b")
     b = u.encode("unicode_escape", "backslashreplace")
     self.assert_(encode_string(u) == b)
コード例 #30
0
 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)
コード例 #31
0
 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)
コード例 #32
0
ファイル: rwobject_test.py プロジェクト: leyuxuan1230/python
    def test_obj_bytes(self):
        b = as_bytes("encyclop\xE6dia")
        encoded_string = encode_string(b, 'ascii', 'strict')

        self.assertIs(encoded_string, b)
コード例 #33
-1
 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)