-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should we, and is it possible, to mock the FTP for unit tests ? #249
Conversation
- The FtpPathError is not raised anymore for non-official ftp source, a log info message is printed. - ftpstore can now handle a specific port in the ftp source
- Replaced fsspec split_protocol by urlparse in order to access the possible port value of an ftp server
- Requires pytest-localftpserver - In conftests set up a mocked ftp server with the content of the tutorial GDAC data - In GDAC data fetcher tests, uses the new mocked ftp server and no longer tests the Ifremer FTP
- also improve data store
- fix bug where argo_split_path will fail in windows for a localhost ftp server
Seems to work like a charm for the FTP server ! I further gave a try to aioresponses to mock HTTP requests to the erddap, argovis, etc ... def test_Argofetcher():
# URI to be catched by mocked server:
uri = 'https://erddap.ifremer.fr/erddap/tabledap/ArgoFloats.nc?data_mode,latitude,longitude,position_qc,time,time_qc,direction,platform_number,cycle_number,config_mission_number,vertical_sampling_scheme,pres,temp,psal,pres_qc,temp_qc,psal_qc,pres_adjusted,temp_adjusted,psal_adjusted,pres_adjusted_qc,temp_adjusted_qc,psal_adjusted_qc,pres_adjusted_error,temp_adjusted_error,psal_adjusted_error&platform_number=~%221901393%22&distinct()&orderBy(%22time,pres%22)'
with aioresponses() as m:
# Set up the expected data to return when this uri will be requested with aiohttp:
with open('test_data/ArgoFloats_aa81_6de2_3b5c.nc', mode='rb') as file:
data = file.read()
m.get(uri, body=data)
# Move on to regular unit testing:
ds = ArgoDataFetcher(src='erddap').float(1901393).to_xarray()
assert isinstance(ds, xr.Dataset) Where the This seems to work as well ! The ArgoDataFetcher send the http request using a fsspec httpstore but it is catched by aioresponses and the local netcdf file content. But this method requires to have all the "expected" data stored somewhere, and I don't know where to put these. |
So I implemented a mocked FTP server using https://github.com/oz123/pytest-localftpserver. The mocked FTP is populated with all content from the tutorial gdac dataset (fetcher from the argopy-data repo) The mocked FTP will not catch all requests to any FTP server. One has to point toward the mocked ftp server to use it. The only modification required in tests, are on those using the ftpstore to call the GDAC. |
I will merge for the FTP fix to close #248 |
Should closes #248
Start playing with https://github.com/oz123/pytest-localftpserver