/usr/lib/python2.7/dist-packages/formencode/tests/test_variabledecode.py is in python-formencode 1.3.0-0ubuntu5.
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 65 66 67 68 69 | import unittest
from formencode.variabledecode import variable_decode, variable_encode
class TestVariableDecode(unittest.TestCase):
def test_list_decode(self):
src = {'a-0': 'a', 'a-1': 'b', 'a-2': 'c'}
expect = {'a': ['a', 'b', 'c']}
self.assertEqual(expect, variable_decode(src))
def test_list_decode_non_int(self):
src = {'a-0': 'a', 'a-a': 'b', 'a-2': 'c'}
expect = {'a': ['a', 'c'], 'a-a': 'b'}
self.assertEqual(expect, variable_decode(src))
def test_list_decode_double_dash(self):
src = {'a-0': 'a', 'a-1-2': 'b', 'a-3': 'c'}
expect = {'a': ['a', 'c'], 'a-1-2': 'b'}
self.assertEqual(expect, variable_decode(src))
def test_list_decode_non_int_nested(self):
src = {'a-0.name': 'a', 'a-a.name': 'b', 'a-2.name': 'c'}
expect = {'a': [{'name': 'a'}, {'name': 'c'}], 'a-a': {'name': 'b'}}
self.assertEqual(expect, variable_decode(src))
def test_dict_decode(self):
src = {'a.a': 'a', 'a.b': 'b', 'a.c': 'c'}
expect = {'a': {'a': 'a', 'b': 'b', 'c': 'c'}}
self.assertEqual(expect, variable_decode(src))
def test_list_dict(self):
src = {'a-0.name': 'a', 'a-1.name': 'b', 'a-2.name': 'c'}
expect = {'a': [{'name': 'a'}, {'name': 'b'}, {'name': 'c'}]}
self.assertEqual(expect, variable_decode(src))
def test_dict_list_dict(self):
src = {'a.b-0.name': 'a', 'a.b-1.name': 'b', 'a.b-2.name': 'c'}
expect = {'a': {'b': [{'name': 'a'}, {'name': 'b'}, {'name': 'c'}]}}
self.assertEqual(expect, variable_decode(src))
class TestVariableEncode(unittest.TestCase):
def test_list_encode(self):
src = {'a': ['a', 'b', 'c']}
expect = {'a--repetitions': '3', 'a-0': 'a', 'a-1': 'b', 'a-2': 'c'}
self.assertEqual(expect, variable_encode(src))
def test_list_encode_non_int(self):
src = {'a': ['a', 'c'], 'a-a': 'b'}
expect = {'a--repetitions': '2', 'a-0': 'a', 'a-a': 'b', 'a-1': 'c'}
self.assertEqual(expect, variable_encode(src))
def test_dict_encode(self):
src = {'a': {'a': 'a', 'b': 'b', 'c': 'c'}}
expect = {'a.a': 'a', 'a.b': 'b', 'a.c': 'c'}
self.assertEqual(expect, variable_encode(src))
|