Skip to content

Commit

Permalink
add a test case for tempdir fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
fbdtemme authored and martinfleis committed Nov 19, 2023
1 parent 078a528 commit 6a49151
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion libpysal/examples/tests/test_available.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
#!/usr/bin/env python3

import errno
import os
import platform
import tempfile
import unittest
import pandas
from unittest.mock import MagicMock, patch

from platformdirs import user_data_dir

from .. import available, get_url, load_example

from ..base import get_data_home

os_name = platform.system()

original_path_exists = os.path.exists
original_makedirs = os.makedirs



class Testexamples(unittest.TestCase):
def test_available(self):
Expand Down Expand Up @@ -40,6 +48,30 @@ def test_data_home(self):
self.assertEqual(heads[-2], "Local")
self.assertEqual(heads[-3], "AppData")

@patch("os.makedirs")
@patch("os.path.exists")
def test_data_home_fallback(self, path_exists_mock, makedirs_mock):
data_home = user_data_dir("pysal", "pysal")

def makedirs_side_effect(path, exist_ok=False):
if path == data_home:
raise OSError(errno.EROFS)

def path_exists_side_effect(path):
if path == data_home:
return False
return original_path_exists(path)

makedirs_mock.side_effect = makedirs_side_effect
path_exists_mock.side_effect = path_exists_side_effect

pth = get_data_home()
head, tail = os.path.split(pth)

self.assertEqual(tail, "pysal")
self.assertEqual(head, tempfile.gettempdir())


def test_get_url(self):
self.assertEqual(get_url("10740"), None)
url = "https://geodacenter.github.io/data-and-lab//data/baltimore.zip"
Expand Down

0 comments on commit 6a49151

Please sign in to comment.