Beispiel #1
0
    def setup(self):
        """Runs before every method to create a clean testing setup."""
        # store current pysat directory
        self.saved_data_path = pysat.data_dir

        pysat.data_dir = ''
        re_load(pysat._files)
Beispiel #2
0
def set_data_dir(path=None, store=True):
    """
    Set the top level directory pysat uses to look for data and reload.

    Parameters
    ----------
    path : string
        valid path to directory pysat uses to look for data
    store : bool
        if True, store data directory for future runs
    """

    import os
    import sys
    import pysat
    if sys.version_info[0] >= 3:
        from importlib import reload as re_load
    else:
        re_load = reload

    if os.path.isdir(path):
        if store:
            with open(
                    os.path.join(os.path.expanduser('~'), '.pysat',
                                 'data_path.txt'), 'w') as f:
                f.write(path)
        pysat.data_dir = path
        pysat._files = re_load(pysat._files)
        pysat._instrument = re_load(pysat._instrument)
    else:
        raise ValueError('Path %s does not lead to a valid directory.' % path)
Beispiel #3
0
    def setup(self):
        """Runs before every method to create a clean testing setup."""
        # store current pysat directory
        self.data_path = pysat.data_dir
        # create temporary directory
        dir_name = tempfile.gettempdir()
        pysat.utils.set_data_dir(dir_name, store=False)
        # create testing directory
        create_dir(temporary_file_list=self.temporary_file_list)

        # create a test instrument, make sure it is getting files from
        # filesystem
        re_load(pysat.instruments.pysat_testing)
        pysat.instruments.pysat_testing.list_files = list_versioned_files
        # create a bunch of files by year and doy
        self.testInst = \
            pysat.Instrument(inst_module=pysat.instruments.pysat_testing,
                             clean_level='clean',
                             temporary_file_list=self.temporary_file_list)

        self.root_fname = ''.join(('pysat_testing_junk_{year:04d}_{month:02d}',
                                   '_{day:03d}{hour:02d}{minute:02d}',
                                   '{second:02d}_stuff_{version:02d}_',
                                   '{revision:03d}.pysat_testing_file'))
        start = pysat.datetime(2007, 12, 31)
        stop = pysat.datetime(2008, 1, 10)
        create_versioned_files(self.testInst, start, stop, freq='100min',
                               use_doy=False, root_fname=self.root_fname)

        self.testInst = \
            pysat.Instrument(inst_module=pysat.instruments.pysat_testing,
                             clean_level='clean',
                             update_files=True,
                             temporary_file_list=self.temporary_file_list)
Beispiel #4
0
 def setup(self):
     re_load(pysat.instruments.pysat_testing)
     """Runs before every method to create a clean testing setup."""
     self.testInst = pysat.Instrument('pysat',
                                      'testing_xarray',
                                      sat_id='10',
                                      clean_level='clean',
                                      update_files=True)
Beispiel #5
0
 def setup(self):
     re_load(pysat.instruments.pysat_testing)
     """Runs before every method to create a clean testing setup."""
     self.testInst = pysat.Instrument('pysat',
                                      'testing',
                                      clean_level='clean',
                                      pad={'minutes': 5},
                                      update_files=True)
Beispiel #6
0
    def test_instrument_has_no_files(self):
        import pysat.instruments.pysat_testing

        pysat.instruments.pysat_testing.list_files = list_files
        inst = pysat.Instrument(platform='pysat', name='testing',
                                update_files=True)
        re_load(pysat.instruments.pysat_testing)
        assert(inst.files.files.empty)
Beispiel #7
0
 def setup(self):
     re_load(pysat.instruments.pysat_testing)
     """Runs before every method to create a clean testing setup."""
     self.testInst = pysat.Instrument('pysat',
                                      'testing',
                                      sat_id='10',
                                      clean_level='clean',
                                      malformed_index=True,
                                      update_files=True,
                                      strict_time_flag=True)
Beispiel #8
0
 def setup(self):
     re_load(pysat.instruments.pysat_testing)
     """Runs before every method to create a clean testing setup."""
     self.testInst = pysat.Instrument('pysat',
                                      'testing_xarray',
                                      clean_level='clean',
                                      update_files=True,
                                      sim_multi_file_right=True,
                                      pad={'minutes': 5},
                                      multi_file_day=True)
Beispiel #9
0
    def test_set_data_dir_no_store(self):
        """update data_dir without storing"""
        pysat.utils.set_data_dir('.', store=False)
        check1 = (pysat.data_dir == '.')

        # Check if next load of pysat remembers old settings
        pysat._files = re_load(pysat._files)
        pysat._instrument = re_load(pysat._instrument)
        re_load(pysat)
        check2 = (pysat.data_dir == self.data_path)

        assert check1 & check2
Beispiel #10
0
    def test_set_data_dir(self):
        """update data_dir"""
        pysat.utils.set_data_dir('.')
        check1 = (pysat.data_dir == '.')

        # Check if next load of pysat remembers the change
        pysat._files = re_load(pysat._files)
        pysat._instrument = re_load(pysat._instrument)
        re_load(pysat)
        check2 = (pysat.data_dir == '.')

        assert check1 & check2
Beispiel #11
0
 def teardown(self):
     """Runs after every method to clean up previous testing."""
     remove_files(self.testInst)
     del self.testInst
     re_load(pysat.instruments.pysat_testing)
     re_load(pysat.instruments)
     # make sure everything about instrument state is restored
     # restore original file list, no files
     pysat.Instrument(inst_module=pysat.instruments.pysat_testing,
                      clean_level='clean',
                      update_files=True,
                      temporary_file_list=self.temporary_file_list)
     pysat.utils.set_data_dir(self.data_path, store=False)
Beispiel #12
0
    def setup(self):
        re_load(pysat.instruments.pysat_testing)
        """Runs before every method to create a clean testing setup."""
        self.testInst = pysat.Instrument('pysat',
                                         'testing_xarray',
                                         clean_level='clean',
                                         pad={'minutes': 5},
                                         update_files=True)
        self.testInst.bounds = ('2008-01-01.nofile', '2010-12-31.nofile')

        self.rawInst = pysat.Instrument('pysat',
                                        'testing_xarray',
                                        clean_level='clean',
                                        update_files=True)
        self.rawInst.bounds = self.testInst.bounds
Beispiel #13
0
    def test_instrument_has_files(self):
        import pysat.instruments.pysat_testing

        root_fname = ''.join(('pysat_testing_junk_{year:04d}_gold_{day:03d}_'
                              'stuff_{month:02d}_{hour:02d}_{minute:02d}_'
                              '{second:02d}.pysat_testing_file'))
        # create a bunch of files by year and doy
        start = pysat.datetime(2007, 12, 31)
        stop = pysat.datetime(2008, 1, 10)
        create_files(self.testInst, start, stop, freq='100min',
                     use_doy=False, root_fname=root_fname)
        # create the same range of dates
        dates = pysat.utils.time.create_date_range(start, stop, freq='100min')
        pysat.instruments.pysat_testing.list_files = list_files
        inst = pysat.Instrument(platform='pysat', name='testing',
                                update_files=True)
        re_load(pysat.instruments.pysat_testing)
        assert (np.all(inst.files.files.index == dates))
Beispiel #14
0
    def test_initial_pysat_load(self):
        import shutil
        saved = False
        try:
            root = os.path.join(os.getenv('HOME'), '.pysat')
            new_root = os.path.join(os.getenv('HOME'), '.saved_pysat')
            shutil.move(root, new_root)
            saved = True
        except:
            pass

        re_load(pysat)

        try:
            if saved:
                # remove directory, trying to be careful
                os.remove(os.path.join(root, 'data_path.txt'))
                os.rmdir(root)
                shutil.move(new_root, root)
        except:
            pass

        assert True
Beispiel #15
0
 def teardown(self):
     """Runs after every method to clean up previous testing."""
     pysat.data_dir = self.saved_data_path
     re_load(pysat._files)