mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-26 20:14:20 +01:00
Add registry.Json.
This commit is contained in:
parent
3063340ce3
commit
d8bd1f6f92
@ -32,6 +32,7 @@ import re
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
import json
|
||||||
import codecs
|
import codecs
|
||||||
import string
|
import string
|
||||||
import textwrap
|
import textwrap
|
||||||
@ -678,4 +679,11 @@ class TemplatedString(String):
|
|||||||
else:
|
else:
|
||||||
self.error()
|
self.error()
|
||||||
|
|
||||||
|
class Json(String):
|
||||||
|
# Json-serializable data
|
||||||
|
def setValue(self, v):
|
||||||
|
super(Json, self).setValue(json.dumps(v))
|
||||||
|
def __call__(self):
|
||||||
|
return json.loads(super(Json, self).__call__())
|
||||||
|
|
||||||
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
||||||
|
@ -130,6 +130,14 @@ class ValuesTestCase(SupyTestCase):
|
|||||||
v.set('"xyzzy')
|
v.set('"xyzzy')
|
||||||
self.assertEqual(v(), '"xyzzy')
|
self.assertEqual(v(), '"xyzzy')
|
||||||
|
|
||||||
|
def testJson(self):
|
||||||
|
data = {'foo': ['bar', 'baz', 5], 'qux': None}
|
||||||
|
v = registry.Json('foo', 'help')
|
||||||
|
self.assertEqual(v(), 'foo')
|
||||||
|
v.setValue(data)
|
||||||
|
self.assertEqual(v(), data)
|
||||||
|
self.assertIsNot(v(), data)
|
||||||
|
|
||||||
def testNormalizedString(self):
|
def testNormalizedString(self):
|
||||||
v = registry.NormalizedString("""foo
|
v = registry.NormalizedString("""foo
|
||||||
bar baz
|
bar baz
|
||||||
|
Loading…
Reference in New Issue
Block a user