示例#1
0
    def test_error(self):
        """Test whether the correct Error is raised"""
        def validate(i):
            try:
                return int(i)
            except:
                raise ValueError("Expected failure")

        rc = RcParams(
            defaultParams={
                'some.test': [1, validate, 'The documentation'],
                'some.other_test': [2, validate, 'Another documentation']
            })
        rc.update_from_defaultParams()
        with self.assertRaisesRegex(ValueError, "Expected failure"):
            rc['some.test'] = 'test'
        with self.assertRaises(KeyError):
            rc['wrong_key'] = 1
        rc._deprecated_map['something'] = ['some.test', lambda x: x]
        with self.assertWarnsRegex(UserWarning,
                                   rc.msg_depr % ('something', 'some.test')):
            rc['something'] = 3
        # check whether the value has been changed correctly
        self.assertEqual(rc['some.test'], 3)
        rc._deprecated_ignore_map['ignored'] = 'some.test'
        with self.assertWarnsRegex(
                UserWarning, rc.msg_depr_ignore % ('ignored', 'some.test')):
            rc['ignored'] = None
        # check whether the value has not been changed
        self.assertEqual(rc['some.test'], 3)
示例#2
0
 def test_findall(self):
     rc = RcParams(
         defaultParams={
             'some.test': [1, lambda i: int(i), 'The documentation'],
             'some.other_test':
             [2, lambda i: int(i), 'Another documentation']
         })
     rc.update_from_defaultParams()
     self.assertEqual(rc.find_all('other'), {'some.other_test': 2})
示例#3
0
 def test_catch(self):
     rc = RcParams(
         defaultParams={
             'some.test': [1, lambda i: int(i), 'The documentation'],
             'some.other_test':
             [2, lambda i: int(i), 'Another documentation']
         })
     rc.update_from_defaultParams()
     with rc.catch():
         rc['some.test'] = 2
         self.assertEqual(rc['some.test'], 2)
     self.assertEqual(rc['some.test'], 1)
示例#4
0
    def test_dump(self):
        """Test the dumping of the rcParams"""
        rc = RcParams(
            defaultParams={
                'some.test': [1, lambda i: int(i), 'The documentation'],
                'some.other_test':
                [2, lambda i: int(i), 'Another documentation']
            })
        rc.update_from_defaultParams()

        rc.HEADER = 'the header'
        s = rc.dump(default_flow_style=False)
        self.assertIn('the header', s)
        self.assertRegex(s, r'# The documentation\n\s*some.test')
        self.assertRegex(s, r'# Another documentation\n\s*some.other_test')
示例#5
0
        # -------------------------------------------------------------------------
        # ---------------------------- 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()
示例#6
0
from psyplot.config.rcsetup import RcParams, validate_bool, validate_dict
from psyplot_gui.common import DockMixin
from psyplot_gui.compat.qtcompat import QWidget, Qt


class W1(QWidget, DockMixin):
    title = 'w1'
    dock_position = Qt.LeftDockWidgetArea


class W2(QWidget, DockMixin):
    title = 'w2'
    dock_position = Qt.BottomDockWidgetArea
    hidden = True


rcParams = RcParams(
    defaultParams={
        'test_plugin': [True, validate_bool],
        'project.plotters': [
            {'gui_test_plotter': {
                'module': 'psyplot_gui_test.plotter',
                'plotter_name': 'TestPlotter', 'import_plotter': True}},
            validate_dict]})
rcParams.update_from_defaultParams()