Skip to content
Snippets Groups Projects
Commit a2294172 authored by Carl Schaffer's avatar Carl Schaffer
Browse files

Merge branch 'path_fix' into 'master'

adding basic test for hmi context retrieval

See merge request !205
parents e2127384 cfdabb22
No related branches found
No related tags found
1 merge request!205adding basic test for hmi context retrieval
import unittest
from datetime import datetime
from pathlib import Path
from unittest.mock import patch
from kis_tools.util.locplot import get_hmi_continuum
# Define a placeholder function to replace the actual download
def download_placeholder(date, *args, directory=None, **kwargs):
target = Path(directory) / "placeholder"
with (target).open("w+") as foo:
foo.write("#Placeholder File#\n" * 10)
return target
class TestUtil(unittest.TestCase):
"""Tests for util package"""
def test_get_image(self):
with patch("sunpy.net.helioviewer.HelioviewerClient.download_jp2", download_placeholder):
get_hmi_continuum(date=datetime(2014, 4, 26, 12, 0), use_cache=False)
......@@ -26,7 +26,7 @@ def get_hmi_continuum(date, use_cache=True):
Get HMI continuum jp2 image. Check /dat/sdc/hmi_context_cache first, if nothing is found, download from SDO via Helioviewer
Args:
date: datetime query
use_cache: default True use the context cahe. if false, force pull of a new image.
use_cache: default True use the context cache. if false, force pull of a new image.
Returns:
path: path to the jp2 file
......@@ -40,11 +40,12 @@ def get_hmi_continuum(date, use_cache=True):
except:
path = expanduser("~")
if not use_cache:
path = TemporaryDirectory()
directory = TemporaryDirectory()
path = directory.name
file_path = join(path, filename)
if not exists(file_path):
hv = HelioviewerClient()
file = hv.download_jp2(date, source_id=18)
file = hv.download_jp2(date, source_id=18, directory=path)
if not file:
raise IOError(f"Could not download file for {date}")
move(file, file_path)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment