def test_main_03_dims(self): import yaml psy.register_plotter('test_plotter', module='test_plotter', plotter_name='TestPlotter') fname2 = tempfile.NamedTemporaryFile( suffix='.pdf', prefix='test_psyplot_').name self._created_files.add(fname2) # create a formatoptions file fmt_file = tempfile.NamedTemporaryFile( suffix='.yml', prefix='test_psyplot_').name self._created_files.add(fmt_file) with open(fmt_file, 'w') as f: yaml.dump({'fmt1': 'fmt1', 'fmt2': 'fmt2'}, f) if not six.PY2: with self.assertRaisesRegex(ValueError, 'plotting method'): main.main([bt.get_file('test-t2m-u-v.nc'), '-o', fname2, '-d', 'time,1,2', 'y,3,4', '-n', 'u', 'v']) main.main([bt.get_file('test-t2m-u-v.nc'), '-o', fname2, '-d', 'time,1,2', 'y,3,4', '-n', 'u', 'v', '-pm', 'test_plotter', '-fmt', fmt_file]) mp = psy.gcp(True) self.assertEqual(len(mp), 2*2*2, msg=mp) all_dims = set(product((1, 2), (3, 4), ('u', 'v'))) for arr in mp: idims = arr.psy.idims all_dims -= {(idims['time'], idims['lat'], arr.name)} self.assertFalse(all_dims) for i, plotter in enumerate(mp.plotters): self.assertEqual(plotter['fmt1'], 'fmt1', msg='Wrong value for fmt1 of plotter %i!' % i) self.assertEqual(plotter['fmt2'], 'fmt2', msg='Wrong value for fmt2 of plotter %i!' % i)
def _create_and_save_test_project(self): psy.register_plotter('test_plotter', module='test_plotter', plotter_name='TestPlotter') sp = psy.plot.test_plotter(bt.get_file('test-t2m-u-v.nc'), name=['t2m', 'u'], time=[0, 1]) self.assertEqual(len(sp), 4, sp) fname = tempfile.NamedTemporaryFile( suffix='.pkl', prefix='test_psyplot_').name self._created_files.add(fname) sp.save_project(fname, use_rel_paths=False) return sp, fname
def test_list_plot_methods(self): """Test to display all versions""" proc = spr.Popen([sys.executable, '-m', 'psyplot', '-lpm'], stdout=spr.PIPE, stderr=spr.PIPE) proc.wait() self.assertFalse(proc.poll(), msg=proc.stderr.read()) import psyplot.project as psy for pm, d in psyplot.rcParams['project.plotters'].items(): try: psy.register_plotter(pm, **d) except: pass ref = psy.plot._plot_methods d = yaml.load(proc.stdout.read(), yaml.Loader) self.assertEqual(d, ref)