Exemple #1
0
 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)
Exemple #2
0
    def test_main_02_alternative_ds(self):

        sp, fname1 = self._create_and_save_test_project()
        fname2 = tempfile.NamedTemporaryFile(
            suffix='.pdf', prefix='test_psyplot_').name
        self._created_files.add(fname2)
        sp.save_project(fname1, use_rel_paths=False)
        psy.close('all')
        main.main([bt.get_file('circumpolar_test.nc'), '-p', fname1,
                   '-o', fname2])
        self.assertTrue(osp.exists(fname2), msg='Missing ' + fname2)
        mp = psy.gcp(True)
        self.assertEqual(len(mp), 4)
        self.assertEqual(
             set(t[0] for t in mp._get_dsnames(mp.array_info(
                 dump=False, use_rel_paths=False))),
             {bt.get_file('circumpolar_test.nc')})
Exemple #3
0
 def test_main_01_from_project(self):
     """Test the :func:`psyplot.__main__.main` function"""
     if not six.PY2:
         with self.assertRaisesRegex(ValueError, 'filename'):
             main.main(['-o', 'test.pdf'])
     sp, fname1 = self._create_and_save_test_project()
     fname2 = tempfile.NamedTemporaryFile(
                 suffix='.pdf', prefix='test_psyplot_').name
     self._created_files.add(fname2)
     sp.save_project(fname1, use_rel_paths=False)
     psy.close('all')
     if six.PY2:
         main.main(['-p', fname1, '-o', fname2])
     else:
         with self.assertWarnsRegex(UserWarning, 'ignored'):
             main.main(['-p', fname1, '-o', fname2, '-n', 't2m'])
     self.assertTrue(osp.exists(fname2), msg='Missing ' + fname2)
     self.assertEqual(len(psy.gcp(True)), 4)