Spaces:
Sleeping
Sleeping
rmm
commited on
Commit
·
befc693
1
Parent(s):
7af40e7
fix: test patches updated to reflect code refactoring
Browse files- tests/test_obs_map.py +11 -17
tests/test_obs_map.py
CHANGED
|
@@ -9,10 +9,11 @@ from dataset.download import try_download_dataset
|
|
| 9 |
# is the return value, which should have similar form but change according to if an exception was raised or not
|
| 10 |
# since this function uses st and m_logger to keep track of the download status, we need to mock them too
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
@patch('
|
| 15 |
-
|
|
|
|
| 16 |
# Mock the return value of load_dataset
|
| 17 |
mock_load_dataset.return_value = {'train': {'latitude': [1], 'longitude': [2], 'predicted_class': ['whale']}}
|
| 18 |
|
|
@@ -25,13 +26,11 @@ def test_try_download_dataset_success(mock_logger, mock_st, mock_load_dataset):
|
|
| 25 |
mock_load_dataset.assert_called_once_with(dataset_id, data_files=data_files)
|
| 26 |
assert result == {'train': {'latitude': [1], 'longitude': [2], 'predicted_class': ['whale']}}
|
| 27 |
mock_logger.info.assert_called_with("Downloaded dataset: (after 0.00s). ")
|
| 28 |
-
mock_st.write.assert_called_with("Downloaded dataset: (after 0.00s). ")
|
| 29 |
|
| 30 |
|
| 31 |
-
@patch('
|
| 32 |
-
@patch('
|
| 33 |
-
|
| 34 |
-
def test_try_download_dataset_failure_known(mock_logger, mock_st, mock_load_dataset):
|
| 35 |
# testing the case where we've found (can reproduce by removing network connection)
|
| 36 |
dataset_id = "test_dataset"
|
| 37 |
data_files = "test_file"
|
|
@@ -41,15 +40,12 @@ def test_try_download_dataset_failure_known(mock_logger, mock_st, mock_load_data
|
|
| 41 |
mock_logger.info.assert_any_call(f"Starting to download dataset {dataset_id} from Hugging Face")
|
| 42 |
mock_load_dataset.assert_called_once_with(dataset_id, data_files=data_files)
|
| 43 |
mock_logger.error.assert_called_with("Error downloading dataset: Download failed. (after 0.00s).")
|
| 44 |
-
mock_st.error.assert_called_with("Error downloading dataset: Download failed. (after 0.00s).")
|
| 45 |
assert result == {}
|
| 46 |
mock_logger.info.assert_called_with("Downloaded dataset: (after 0.00s). ")
|
| 47 |
-
mock_st.write.assert_called_with("Downloaded dataset: (after 0.00s). ")
|
| 48 |
|
| 49 |
-
@patch('
|
| 50 |
-
@patch('
|
| 51 |
-
|
| 52 |
-
def test_try_download_dataset_failure_unknown(mock_logger, mock_st, mock_load_dataset):
|
| 53 |
# the cases we haven't found, but should still be handled (maybe network error, etc)
|
| 54 |
dataset_id = "test_dataset"
|
| 55 |
data_files = "test_file"
|
|
@@ -59,7 +55,5 @@ def test_try_download_dataset_failure_unknown(mock_logger, mock_st, mock_load_da
|
|
| 59 |
mock_logger.info.assert_any_call(f"Starting to download dataset {dataset_id} from Hugging Face")
|
| 60 |
mock_load_dataset.assert_called_once_with(dataset_id, data_files=data_files)
|
| 61 |
mock_logger.error.assert_called_with("!!Unknown Error!! downloading dataset: Download engine corrupt. (after 0.00s).")
|
| 62 |
-
mock_st.error.assert_called_with("!!Unknown Error!! downloading dataset: Download engine corrupt. (after 0.00s).")
|
| 63 |
assert result == {}
|
| 64 |
mock_logger.info.assert_called_with("Downloaded dataset: (after 0.00s). ")
|
| 65 |
-
mock_st.write.assert_called_with("Downloaded dataset: (after 0.00s). ")
|
|
|
|
| 9 |
# is the return value, which should have similar form but change according to if an exception was raised or not
|
| 10 |
# since this function uses st and m_logger to keep track of the download status, we need to mock them too
|
| 11 |
|
| 12 |
+
#@patch('maps.obs_map.load_dataset')
|
| 13 |
+
#@patch('maps.obs_map.m_logger')
|
| 14 |
+
@patch('dataset.download.load_dataset')
|
| 15 |
+
@patch('dataset.download.m_logger')
|
| 16 |
+
def test_try_download_dataset_success(mock_logger, mock_load_dataset):
|
| 17 |
# Mock the return value of load_dataset
|
| 18 |
mock_load_dataset.return_value = {'train': {'latitude': [1], 'longitude': [2], 'predicted_class': ['whale']}}
|
| 19 |
|
|
|
|
| 26 |
mock_load_dataset.assert_called_once_with(dataset_id, data_files=data_files)
|
| 27 |
assert result == {'train': {'latitude': [1], 'longitude': [2], 'predicted_class': ['whale']}}
|
| 28 |
mock_logger.info.assert_called_with("Downloaded dataset: (after 0.00s). ")
|
|
|
|
| 29 |
|
| 30 |
|
| 31 |
+
@patch('dataset.download.load_dataset', side_effect=ValueError("Download failed"))
|
| 32 |
+
@patch('dataset.download.m_logger')
|
| 33 |
+
def test_try_download_dataset_failure_known(mock_logger, mock_load_dataset):
|
|
|
|
| 34 |
# testing the case where we've found (can reproduce by removing network connection)
|
| 35 |
dataset_id = "test_dataset"
|
| 36 |
data_files = "test_file"
|
|
|
|
| 40 |
mock_logger.info.assert_any_call(f"Starting to download dataset {dataset_id} from Hugging Face")
|
| 41 |
mock_load_dataset.assert_called_once_with(dataset_id, data_files=data_files)
|
| 42 |
mock_logger.error.assert_called_with("Error downloading dataset: Download failed. (after 0.00s).")
|
|
|
|
| 43 |
assert result == {}
|
| 44 |
mock_logger.info.assert_called_with("Downloaded dataset: (after 0.00s). ")
|
|
|
|
| 45 |
|
| 46 |
+
@patch('dataset.download.load_dataset', side_effect=Exception("Download engine corrupt"))
|
| 47 |
+
@patch('dataset.download.m_logger')
|
| 48 |
+
def test_try_download_dataset_failure_unknown(mock_logger, mock_load_dataset):
|
|
|
|
| 49 |
# the cases we haven't found, but should still be handled (maybe network error, etc)
|
| 50 |
dataset_id = "test_dataset"
|
| 51 |
data_files = "test_file"
|
|
|
|
| 55 |
mock_logger.info.assert_any_call(f"Starting to download dataset {dataset_id} from Hugging Face")
|
| 56 |
mock_load_dataset.assert_called_once_with(dataset_id, data_files=data_files)
|
| 57 |
mock_logger.error.assert_called_with("!!Unknown Error!! downloading dataset: Download engine corrupt. (after 0.00s).")
|
|
|
|
| 58 |
assert result == {}
|
| 59 |
mock_logger.info.assert_called_with("Downloaded dataset: (after 0.00s). ")
|
|
|