-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for download_datasets function
- Loading branch information
1 parent
7de8853
commit a1833c6
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import unittest | ||
import os | ||
from unittest.mock import patch | ||
from pathlib import Path | ||
import urllib | ||
|
||
from elephant.datasets import download_datasets | ||
|
||
|
||
class TestDownloadDatasets(unittest.TestCase): | ||
@patch.dict(os.environ, {'ELEPHANT_DATA_LOCATION': '/valid/path'}, clear=True) | ||
@patch('os.path.exists', return_value=True) | ||
def test_valid_path(self, mock_exists): | ||
repo_path = 'some/repo/path' | ||
expected = Path('/valid/path/some/repo/path') | ||
result = download_datasets(repo_path) | ||
self.assertEqual(result, expected) | ||
|
||
@patch.dict(os.environ, {'ELEPHANT_DATA_LOCATION': 'http://valid.url'}, clear=True) | ||
@patch('os.path.exists', return_value=False) | ||
def test_valid_url(self, mock_exists): | ||
repo_path = 'some/repo/path' | ||
self.assertRaises(urllib.error.URLError, download_datasets, repo_path) | ||
|
||
@patch.dict(os.environ, {'ELEPHANT_DATA_LOCATION': 'invalid_path_or_url'}, clear=True) | ||
@patch('os.path.exists', return_value=False) | ||
def test_invalid_value(self, mock_exists): | ||
repo_path = 'some/repo/path' | ||
with self.assertRaises(ValueError) as cm: | ||
download_datasets(repo_path) | ||
self.assertIn("invalid_path_or_url", str(cm.exception)) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |