[pypy-commit] pypy py3.5: add some simple fs en/decode tests

cfbolz pypy.commits at gmail.com
Wed Nov 9 10:33:26 EST 2016


Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch: py3.5
Changeset: r88266:c9b8dd4d8872
Date: 2016-11-09 14:17 +0100
http://bitbucket.org/pypy/pypy/changeset/c9b8dd4d8872/

Log:	add some simple fs en/decode tests

diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -1068,9 +1068,6 @@
         from pypy.objspace.std.listobject import make_empty_list_with_size
         return make_empty_list_with_size(self, sizehint)
 
-    def wrap_fsdecoded(self, x):
-        return self.fsdecode(self.newbytes(x))
-
     @jit.unroll_safe
     def exception_match(self, w_exc_type, w_check_class):
         """Checks if the given exception type matches 'w_check_class'."""
@@ -1680,6 +1677,9 @@
             w_obj = self.fsdecode(w_obj)
         return self.unicode0_w(w_obj)
 
+    def wrap_fsdecoded(self, x):
+        return self.fsdecode(self.newbytes(x))
+
     def bool_w(self, w_obj):
         # Unwraps a bool, also accepting an int for compatibility.
         # For cases where you need to accept bools and ints and nothing
diff --git a/pypy/interpreter/test/test_fsencode.py b/pypy/interpreter/test/test_fsencode.py
--- a/pypy/interpreter/test/test_fsencode.py
+++ b/pypy/interpreter/test/test_fsencode.py
@@ -1,6 +1,7 @@
 import sys
+from pypy.interpreter.error import OperationError
 
-class BaseImportTest:
+class BaseFSEncodeTest:
 
     def setup_class(cls):
         space = cls.space
@@ -60,3 +61,24 @@
 
     if special_char:
         return special_char.decode(fsenc)
+
+class TestFSEncode(BaseFSEncodeTest):
+    def test_fsencode_fsdecode(self):
+        space = self.space
+        strs = [u"/home/bar/baz", u"c:\\"]
+        if self.special_char:
+            strs.append(self.special_char)
+        for st in strs:
+            # check roundtrip
+            w_st = space.newunicode(st)
+            w_enc = space.fsencode(w_st)
+            w_st2 = space.fsdecode(w_enc)
+            assert space.eq_w(w_st, w_st2)
+            assert space.fsdecode_w(w_enc) == st
+
+            assert space.fsencode_w(w_enc) == space.bytes_w(w_enc)
+            assert space.eq_w(space.wrap_fsdecoded(space.bytes_w(w_enc)), w_st2)
+
+    def test_error(self):
+        raises(OperationError, self.space.fsencode, self.space.newbytes(self.testfn_unencodable))
+


More information about the pypy-commit mailing list