Beispiel #1
0
 def test_nocache(self):
     with tempfile.TemporaryDirectory() as testcachedir:
         with argopy.set_options(cachedir=testcachedir):
             loader = ArgoIndexFetcher(src=self.src, cache=False).float(self.requests['float'][0])
             loader.to_xarray()
             with pytest.raises(FileSystemHasNoCache):
                 loader.fetcher.cachepath
Beispiel #2
0
    def __testthis(self):
        for access_point in self.args:

            # Acces point not implemented yet for erddap
            # if access_point == 'profile':
            #     for arg in self.args['profile']:
            #         fetcher = ArgoIndexFetcher(src=self.src).profile(*arg).fetcher
            #         try:
            #             ds = fetcher.to_xarray()
            #             assert isinstance(ds, xr.Dataset)
            #         except ErddapServerError:
            #             # Test is passed even if something goes wrong with the erddap server
            #             pass
            #         except Exception:
            #             print("ERROR ERDDAP request:\n", fetcher.cname())
            #             pass

            if access_point == "float":
                for arg in self.args["float"]:
                    fetcher = ArgoIndexFetcher(src=self.src).float(arg).fetcher
                    ds = fetcher.to_xarray()
                    assert isinstance(ds, xr.Dataset)

            if access_point == "region":
                for arg in self.args["region"]:
                    fetcher = ArgoIndexFetcher(src=self.src).region(arg).fetcher
                    ds = fetcher.to_xarray()
                    assert isinstance(ds, xr.Dataset)
Beispiel #3
0
 def test_nocache(self):
     with argopy.set_options(cachedir="dummy", local_ftp=self.local_ftp):
         loader = ArgoIndexFetcher(src=self.src,
                                   cache=False).profile(2901623, 2)
         loader.to_xarray()
         with pytest.raises(FileSystemHasNoCache):
             loader.fetcher.cachepath
Beispiel #4
0
 def test_nocache(self):
     with argopy.set_options(cachedir=self.testcachedir):
         loader = ArgoIndexFetcher(src='erddap', cache=False).float(6902746)
         loader.to_xarray()
         with pytest.raises(FileSystemHasNoCache):
             loader.fetcher.cachepath
     shutil.rmtree(self.testcachedir)  # Make sure the cache is empty
Beispiel #5
0
 def test_clearcache(self):
     with tempfile.TemporaryDirectory() as testcachedir:
         with argopy.set_options(cachedir=testcachedir):
             loader = ArgoIndexFetcher(src=self.src, cache=True).float(self.requests['float'][0])
             loader.to_xarray()
             loader.clear_cache()
             with pytest.raises(CacheFileNotFound):
                 loader.fetcher.cachepath
Beispiel #6
0
 def test_caching(self):
     with tempfile.TemporaryDirectory() as testcachedir:
         with argopy.set_options(cachedir=testcachedir):
             loader = ArgoIndexFetcher(src=self.src, cache=True).float(self.requests['float'][0])
             # 1st call to load and save to cache:
             loader.to_xarray()
             # 2nd call to load from cached file:
             ds = loader.to_xarray()
             assert isinstance(ds, xr.Dataset)
             assert isinstance(loader.fetcher.cachepath, str)
Beispiel #7
0
 def test_caching_float(self):
     testcachedir = os.path.expanduser(os.path.join("~", ".argopytest_tmp"))
     with argopy.set_options(cachedir=testcachedir,
                             local_ftp=self.local_ftp):
         try:
             loader = ArgoIndexFetcher(src=self.src,
                                       cache=True).float(6901929)
             # 1st call to load from erddap and save to cachedir:
             ds = loader.to_xarray()
             # 2nd call to load from cached file:
             ds = loader.to_xarray()
             assert isinstance(ds, xr.Dataset)
             assert isinstance(loader.fetcher.cachepath, str)
             shutil.rmtree(testcachedir)
         except Exception:
             shutil.rmtree(testcachedir)
             raise
Beispiel #8
0
 def test_caching_index(self):
     with argopy.set_options(cachedir=self.testcachedir):
         try:
             loader = ArgoIndexFetcher(src='erddap',
                                       cache=True).float(6902746)
             # 1st call to load from erddap and save to cachedir:
             ds = loader.to_xarray()
             # 2nd call to load from cached file:
             ds = loader.to_xarray()
             assert isinstance(ds, xr.Dataset)
             assert isinstance(loader.fetcher.cachepath, str)
             shutil.rmtree(self.testcachedir)
         except ErddapServerError:  # Test is passed when something goes wrong because of the erddap server, not our fault !
             shutil.rmtree(self.testcachedir)
             pass
         except Exception:
             shutil.rmtree(self.testcachedir)
             raise
    def __testthis(self):
        for access_point in self.args:

            if access_point == "profile":
                for arg in self.args["profile"]:
                    with argopy.set_options(local_ftp=self.local_ftp):
                        fetcher = ArgoIndexFetcher(src=self.src).profile(*arg).fetcher
                        ds = fetcher.to_xarray()
                        assert isinstance(ds, xr.Dataset)

            if access_point == "float":
                for arg in self.args["float"]:
                    with argopy.set_options(local_ftp=self.local_ftp):
                        fetcher = ArgoIndexFetcher(src=self.src).float(arg).fetcher
                        ds = fetcher.to_xarray()
                        assert isinstance(ds, xr.Dataset)

            if access_point == "region":
                for arg in self.args["region"]:
                    with argopy.set_options(local_ftp=self.local_ftp):
                        fetcher = ArgoIndexFetcher(src=self.src).region(arg).fetcher
                        ds = fetcher.to_xarray()
                        assert isinstance(ds, xr.Dataset)
Beispiel #10
0
 def __test_region(self, bk, **ftc_opts):
     """ Test float index fetching for a given backend """
     for arg in self.args["region"]:
         options = {**self.fetcher_opts, **ftc_opts}
         f = ArgoIndexFetcher(src=bk, **options).region(arg)
         assert isinstance(f.to_xarray(), xr.Dataset)
Beispiel #11
0
 def __test_profile(self, bk, **ftc_opts):
     """ Test profile index fetching for a given backend """
     for arg in self.args["profile"]:
         options = {**self.fetcher_opts, **ftc_opts}
         f = ArgoIndexFetcher(src=bk, **options).profile(*arg)
         assert isinstance(f.to_xarray(), xr.Dataset)