def test_basic(self): """Test the basic functionality """ d = { 'test.1': 'test1', 'test.2': 'test2', 'test1.1': 'test11', 'test1.2': 'test12' } sub = SubDict(d, 'test.', pattern_base=r'test\.') self.assertIn('1', sub) self.assertIn('2', sub) self.assertEqual(sub['1'], 'test1') self.assertEqual(sub['2'], 'test2') self.assertNotIn('test11', sub.values(), msg='Item test1.1 catched in %s' % (sub, )) self.assertNotIn('test12', sub.values(), msg='Item test1.2 catched in %s' % (sub, ))
def test_replace(self): """Test the replace property """ d = { 'test.1': 'test1', 'test.2': 'test2', 'test1.1': 'test11', 'test1.2': 'test12' } sub = SubDict(d, 'test.', pattern_base=r'test\.') sub['test'] = 5 # test something that is not traced back to d self.assertNotIn('test.1', sub) self.assertIn('1', sub) sub.replace = False sub.trace = True sub['test.2'] = 4 self.assertIn('test.1', sub) self.assertNotIn('1', sub) self.assertEqual(sub['test.2'], 4) self.assertEqual(d['test.2'], 4) sub.replace = True self.assertNotIn('test.1', sub) self.assertIn('1', sub)
def test_trace(self): """Test the backtracing to the origin dictionary""" d = { 'test.1': 'test1', 'test.2': 'test2', 'test1.1': 'test11', 'test1.2': 'test12' } sub = SubDict(d, 'test.', pattern_base=r'test\.', trace=True) self.assertIn('1', sub) sub['1'] = 'change in d' sub['test.3'] = 'test3' # new item self.assertEqual(d['test.1'], 'change in d') self.assertEqual(sub['1'], 'change in d') self.assertIn('3', sub) self.assertIn('test.3', d) sub.trace = False sub['1'] = 'do not change in d' sub['4'] = 'test4' self.assertEqual(d['test.1'], 'change in d') self.assertEqual(sub['1'], 'do not change in d') self.assertIn('4', sub) self.assertNotIn('4', d)
# ------------------------------------------------------------------------- # ---------------------------- Miscallaneous ------------------------------ # ------------------------------------------------------------------------- # color lists for user-defined colormaps (see for example # psy_simple.colors._cmapnames) 'colors.cmaps': [{}, validate_cmaps, 'User defined color lists that shall be accessible through the ' ':meth:`psyplot.plotter.colors.get_cmap` function'], 'ticks.which': [ 'major', ValidateInStrings('ticks.which', ['major', 'minor'], True), 'default tick that is used when using a x- or y-tick formatoption' ], }) # add combinedplotter strings for vectorplot _subd = SubDict(rcParams.defaultParams, ['plotter.vector.', 'plotter.plot2d.']) for _key in [ 'plot', 'cbar', 'cmap', 'bounds', 'cticksize', 'cbarspacing', 'ctickweight', 'ctickprops', 'clabel', 'cticks', 'cticklabels', 'clabelsize', 'clabelprops', 'clabelweight' ]: rcParams.defaultParams['plotter.combinedsimple.v%s' % _key] = _subd[_key] rcParams.defaultParams['plotter.combinedsimple.plot'] = rcParams.defaultParams[ 'plotter.plot2d.plot'] del _key, _subd rcParams.update_from_defaultParams()