Skip to content

Commit

Permalink
add tests for download_datasets function
Browse files Browse the repository at this point in the history
  • Loading branch information
Moritz-Alexander-Kern committed Jun 14, 2024
1 parent 7de8853 commit a1833c6
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions elephant/test/test_datasets.py
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()

0 comments on commit a1833c6

Please sign in to comment.