mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-19 08:59:27 +01:00
Add registry.Json.
This commit is contained in:
parent
3063340ce3
commit
d8bd1f6f92
@ -32,6 +32,7 @@ import re
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import json
|
||||
import codecs
|
||||
import string
|
||||
import textwrap
|
||||
@ -678,4 +679,11 @@ class TemplatedString(String):
|
||||
else:
|
||||
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:
|
||||
|
@ -130,6 +130,14 @@ class ValuesTestCase(SupyTestCase):
|
||||
v.set('"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):
|
||||
v = registry.NormalizedString("""foo
|
||||
bar baz
|
||||
|
Loading…
Reference in New Issue
Block a user