Rev 99: Format 'bool' objects nicely. [give them value: True, value: False] in http://bazaar.launchpad.net/~meliae-dev/meliae/trunk
John Arbash Meinel
john at arbash-meinel.com
Sun Oct 18 19:35:31 BST 2009
At http://bazaar.launchpad.net/~meliae-dev/meliae/trunk
------------------------------------------------------------
revno: 99
revision-id: john at arbash-meinel.com-20091018183504-q5perhh3l1xfd1fd
parent: john at arbash-meinel.com-20091017030158-8pa7tzmyiwfk02bq
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: trunk
timestamp: Sun 2009-10-18 13:35:04 -0500
message:
Format 'bool' objects nicely. [give them value: True, value: False]
-------------- next part --------------
=== modified file 'meliae/_scanner_core.c'
--- a/meliae/_scanner_core.c 2009-10-13 21:26:54 +0000
+++ b/meliae/_scanner_core.c 2009-10-18 18:35:04 +0000
@@ -412,6 +412,14 @@
_write_to_ref_info(info, ", \"len\": " SSIZET_FMT, PyUnicode_GET_SIZE(c_obj));
_write_static_to_info(info, ", \"value\": ");
_dump_unicode(info, c_obj);
+ } else if (PyBool_Check(c_obj)) {
+ if (c_obj == Py_True) {
+ _write_static_to_info(info, ", \"value\": \"True\"");
+ } else if (c_obj == Py_False) {
+ _write_static_to_info(info, ", \"value\": \"False\"");
+ } else {
+ _write_to_ref_info(info, ", \"value\": %ld", PyInt_AS_LONG(c_obj));
+ }
} else if (PyInt_CheckExact(c_obj)) {
_write_to_ref_info(info, ", \"value\": %ld", PyInt_AS_LONG(c_obj));
} else if (PyTuple_Check(c_obj)) {
=== modified file 'meliae/tests/test__scanner.py'
--- a/meliae/tests/test__scanner.py 2009-10-13 21:26:54 +0000
+++ b/meliae/tests/test__scanner.py 2009-10-18 18:35:04 +0000
@@ -245,6 +245,10 @@
content.append(', "value": %s' % (_string_to_json(obj[:100]),))
elif isinstance(obj, unicode):
content.append(', "value": %s' % (_unicode_to_json(obj[:100]),))
+ elif obj is True:
+ content.append(', "value": "True"')
+ elif obj is False:
+ content.append(', "value": "False"')
elif isinstance(obj, int):
content.append(', "value": %d' % (obj,))
first = True
@@ -332,6 +336,18 @@
', "name": "meliae._scanner", "refs": [%d]}\n'
% (id(m), _scanner.size_of(m), id(m.__dict__)), m)
+ def test_bool(self):
+ a = True
+ b = False
+ self.assertDumpText(
+ '{"address": %d, "type": "bool", "size": %d'
+ ', "value": "True", "refs": []}\n'
+ % (id(a), _scanner.size_of(a)), a)
+ self.assertDumpText(
+ '{"address": %d, "type": "bool", "size": %d'
+ ', "value": "False", "refs": []}\n'
+ % (id(b), _scanner.size_of(b)), b)
+
class TestDumpInfo(tests.TestCase):
"""dump_object_info should give the same result at py_dump_object_info"""
@@ -439,6 +455,10 @@
pass
self.assertDumpInfo(MyOldClass)
+ def test_bool(self):
+ self.assertDumpInfo(True)
+ self.assertDumpInfo(False)
+
class TestGetReferents(tests.TestCase):
More information about the bazaar-commits
mailing list