/usr/share/pyshared/tests/test_jsonify.py is in python-turbogears2 2.1.5-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | from tg import jsonify
from nose.tools import raises
class Foo(object):
def __init__(self, bar):
self.bar = bar
class Bar(object):
def __init__(self, bar):
self.bar = bar
def __json__(self):
return 'bar-%s' % self.bar
class Baz(object):
pass
def test_string():
d = "string"
encoded = jsonify.encode(d)
assert encoded == '"string"'
@raises(jsonify.JsonEncodeError)
def test_list():
d = ['a', 1, 'b', 2]
encoded = jsonify.encode(d)
assert encoded == '["a", 1, "b", 2]'
@raises(jsonify.JsonEncodeError)
def test_list_iter():
d = range(3)
encoded = jsonify.encode_iter(d)
assert ''.join(jsonify.encode_iter(d)) == jsonify.encode(d)
def test_dictionary():
d = {'a': 1, 'b': 2}
encoded = jsonify.encode(d)
assert encoded == '{"a": 1, "b": 2}'
@raises(jsonify.JsonEncodeError)
def test_nospecificjson():
b = Baz()
try:
encoded = jsonify.encode(b)
except TypeError, e:
pass
assert "is not JSON serializable" in e.message
def test_exlicitjson():
b = Bar("bq")
encoded = jsonify.encode(b)
assert encoded == '"bar-bq"'
@raises(jsonify.JsonEncodeError)
def test_exlicitjson_in_list():
b = Bar("bq")
d = [b]
encoded = jsonify.encode(d)
assert encoded == '["bar-bq"]'
def test_exlicitjson_in_dict():
b = Bar("bq")
d = {"b": b}
encoded = jsonify.encode(d)
assert encoded == '{"b": "bar-bq"}'
|