Author: Brian Kearns <bdkea...@gmail.com> Branch: Changeset: r71419:eefd0674de1d Date: 2014-05-08 17:05 -0400 http://bitbucket.org/pypy/pypy/changeset/eefd0674de1d/
Log: test/fix quotes in bytearray repr diff --git a/pypy/objspace/std/bytearrayobject.py b/pypy/objspace/std/bytearrayobject.py --- a/pypy/objspace/std/bytearrayobject.py +++ b/pypy/objspace/std/bytearrayobject.py @@ -221,7 +221,15 @@ # Good default if there are no replacements. buf = StringBuilder(len("bytearray(b'')") + len(s)) - buf.append("bytearray(b'") + buf.append("bytearray(b") + quote = "'" + for c in s: + if c == '"': + quote = "'" + break + elif c == "'": + quote = '"' + buf.append(quote) for i in range(len(s)): c = s[i] @@ -243,7 +251,8 @@ else: buf.append(c) - buf.append("')") + buf.append(quote) + buf.append(")") return space.wrap(buf.build()) diff --git a/pypy/objspace/std/test/test_bytearrayobject.py b/pypy/objspace/std/test/test_bytearrayobject.py --- a/pypy/objspace/std/test/test_bytearrayobject.py +++ b/pypy/objspace/std/test/test_bytearrayobject.py @@ -1,5 +1,6 @@ from pypy import conftest + class AppTestBytesArray: def setup_class(cls): cls.w_runappdirect = cls.space.wrap(conftest.option.runappdirect) @@ -49,7 +50,10 @@ def test_repr(self): assert repr(bytearray()) == "bytearray(b'')" assert repr(bytearray('test')) == "bytearray(b'test')" - assert repr(bytearray("d'oh")) == r"bytearray(b'd\'oh')" + assert repr(bytearray("d'oh")) == r'bytearray(b"d\'oh")' + assert repr(bytearray('d"oh')) == 'bytearray(b\'d"oh\')' + assert repr(bytearray('d"\'oh')) == 'bytearray(b\'d"\\\'oh\')' + assert repr(bytearray('d\'"oh')) == 'bytearray(b\'d\\\'"oh\')' def test_str(self): assert str(bytearray()) == "" _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit