Skip to content

Commit

Permalink
✅ Test csv data download a bit better
Browse files Browse the repository at this point in the history
Actually download a file (sample with header only) and check that the header line matches. Remove the file when test is done.
  • Loading branch information
weiji14 committed Oct 31, 2018
1 parent fdb0464 commit 3989fd7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
9 changes: 6 additions & 3 deletions data_prep.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,14 @@
"outputs": [],
"source": [
"def download_to_path(path:str, url:str):\n",
" \"\"\"\n",
" r\"\"\"\n",
" Download from a url to a path\n",
" \n",
" >>> download_to_path(path=\"highres/2017_Antarctica_Basler.csv\", url=\"https://data.cresis.ku.edu/data/rds/2017_Antarctica_Basler/csv_good/2017_Antarctica_Basler.csv\").headers['Content-Length']\n",
" '64'\n",
" >>> download_to_path(path=\"highres/2017_Antarctica_Basler.csv\", url=\"https://data.cresis.ku.edu/data/rds/2017_Antarctica_Basler/csv_good/2017_Antarctica_Basler.csv\")\n",
" <Response [200]>\n",
" >>> open('highres/2017_Antarctica_Basler.csv').readlines()\n",
" ['LAT,LON,UTCTIMESOD,THICK,ELEVATION,FRAME,SURFACE,BOTTOM,QUALITY\\n']\n",
" >>> os.remove(path=\"highres/2017_Antarctica_Basler.csv\")\n",
" \"\"\"\n",
" #if not os.path.exists(path=path):\n",
" r = requests.get(url=url, stream=True)\n",
Expand Down
19 changes: 14 additions & 5 deletions test_ipynb.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,27 @@
"output_type": "stream",
"text": [
"Trying:\n",
" download_to_path(path=\"highres/2017_Antarctica_Basler.csv\", url=\"https://data.cresis.ku.edu/data/rds/2017_Antarctica_Basler/csv_good/2017_Antarctica_Basler.csv\").headers['Content-Length']\n",
" download_to_path(path=\"highres/2017_Antarctica_Basler.csv\", url=\"https://data.cresis.ku.edu/data/rds/2017_Antarctica_Basler/csv_good/2017_Antarctica_Basler.csv\")\n",
"Expecting:\n",
" '64'\n",
" <Response [200]>\n",
"ok\n",
"Trying:\n",
" open('highres/2017_Antarctica_Basler.csv').readlines()\n",
"Expecting:\n",
" ['LAT,LON,UTCTIMESOD,THICK,ELEVATION,FRAME,SURFACE,BOTTOM,QUALITY\\n']\n",
"ok\n",
"Trying:\n",
" os.remove(path=\"highres/2017_Antarctica_Basler.csv\")\n",
"Expecting nothing\n",
"ok\n",
"3 items had no tests:\n",
" data_prep\n",
" data_prep.get_window_bounds\n",
" data_prep.selective_tile\n",
"1 items passed all tests:\n",
" 1 tests in data_prep.download_to_path\n",
"1 tests in 4 items.\n",
"1 passed and 0 failed.\n",
" 3 tests in data_prep.download_to_path\n",
"3 tests in 4 items.\n",
"3 passed and 0 failed.\n",
"Test passed.\n"
]
}
Expand Down

0 comments on commit 3989fd7

Please sign in to comment.