def test_group(self): p = Params() self.assertEqual(len(p), 0) p2 = Params() p.group('P2', p2) self.assertEqual(len(p), 1) self.assertEqual(p.get('P2'), p2)
def test_propagates_params_changes(self): p = Params() self.assertEqual(len(p), 0) p2 = Params() p.group('P2', p2) self.assertEqual(p.changeEvent._fireCount, 1) p2.int('foo') self.assertEqual(p.changeEvent._fireCount, 2)
def test_set_values(self): pars = Params() pars.int('count').set(1) pars.float('price').set(9.99) subpars = Params() subpars.bool('flag').set(True) pars.group('subgroup', subpars) set_values(pars, {'count': 5, 'price': 0.5, 'subgroup': {'flag': False}}) self.assertEqual(pars.get('count').val(), 5) self.assertEqual(pars.get('price').val(), 0.5) self.assertEqual(pars.get('subgroup').get('flag').val(), False)
def test_schema_list_with_values(self): pars = Params() pars.string('name').set('Moby Dick') pars.int('count').set(100) pars.float('price').set(9.99) pars.bool('soldout').set(False) details = Params() details.int('page_count').set(345) details.string('author').set('Herman Melville') pars.group('details', details) self.assertEqual(schema_list(pars), [ {'path': '/name', 'type':'s', 'value':'Moby Dick'}, {'path': '/count', 'type':'i', 'value':100}, {'path': '/price', 'type':'f', 'value':9.99}, {'path': '/soldout', 'type':'b', 'value':False}, {'path': '/details/page_count', 'type':'i','value':345}, {'path': '/details/author', 'type':'s','value':'Herman Melville'} ])
def test_schema_list(self): pars = Params() pars.string('name') pars.int('count') pars.float('price') pars.bool('soldout') details = Params() details.int('page_count') details.string('author') pars.group('details', details) self.assertEqual(schema_list(pars), [ {'path': '/name', 'type':'s'}, {'path': '/count', 'type':'i'}, {'path': '/price', 'type':'f'}, {'path': '/soldout', 'type':'b'}, {'path': '/details/page_count', 'type':'i'}, {'path': '/details/author', 'type':'s'} ])