Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ API Reference
.. automodapi:: hvpy.parameters
:allowed-package-names: hvpy.api_groups

.. automodapi:: hvpy.datasources
.. automodapi:: hvpy.datasource
:no-inheritance-diagram:

.. automodapi:: hvpy.utils
2 changes: 1 addition & 1 deletion hvpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .facade import *
from .config import set_api_url
from .version import __version__
from .datasources import *
from .datasource import *
from .utils import create_layers
4 changes: 2 additions & 2 deletions hvpy/datasources.py → hvpy/datasource.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from enum import Enum

__all__ = ["DataSources"]
__all__ = ["DataSource"]


class DataSources(Enum):
class DataSource(Enum):
"""
Enum for datasources hosted by the Helioviewer Project.
"""
Expand Down
4 changes: 2 additions & 2 deletions hvpy/tests/test_datasources.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any

from hvpy import DataSources, getDataSources
from hvpy import DataSource, getDataSources


def find_nested_keys(obj: dict, key: Any, out: list):
Expand All @@ -24,7 +24,7 @@ def find_nested_keys(obj: dict, key: Any, out: list):

def test_datasources():
source_ids = []
enum_values = [s_id.value for s_id in DataSources]
enum_values = [s_id.value for s_id in DataSource]
response = getDataSources()
find_nested_keys(response, "sourceId", source_ids)
for source_id in source_ids:
Expand Down
16 changes: 8 additions & 8 deletions hvpy/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import pytest

from hvpy import DataSources
from hvpy import DataSource
from hvpy.utils import _create_layer_string, _to_datasource, create_layers


def test_create_layers():
assert create_layers([(9, 100), (11, 50)]) == "[9,1,100],[11,1,50]"

with pytest.raises(ValueError, match="999 is not a valid DataSources"):
with pytest.raises(ValueError, match="999 is not a valid DataSource"):
create_layers([(9, 100), (999, 100)])

with pytest.raises(ValueError, match="must be between 0 and 100"):
Expand All @@ -18,15 +18,15 @@ def test_create_layers():


def test_to_datasource():
assert _to_datasource(9) == DataSources.AIA_131
assert _to_datasource(DataSources.AIA_94) == DataSources.AIA_94
with pytest.raises(ValueError, match="999 is not a valid DataSources"):
assert _to_datasource(9) == DataSource.AIA_131
assert _to_datasource(DataSource.AIA_94) == DataSource.AIA_94
with pytest.raises(ValueError, match="999 is not a valid DataSource"):
_to_datasource(999)


def test_create_layers_string():
assert _create_layer_string(DataSources.AIA_131, 100) == "[9,1,100]"
assert _create_layer_string(DataSource.AIA_131, 100) == "[9,1,100]"
with pytest.raises(ValueError, match="must be between 0 and 100"):
_create_layer_string(DataSources.AIA_131, 101)
_create_layer_string(DataSource.AIA_131, 101)
with pytest.raises(ValueError, match="must be between 0 and 100"):
_create_layer_string(DataSources.AIA_131, -1)
_create_layer_string(DataSource.AIA_131, -1)
16 changes: 8 additions & 8 deletions hvpy/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Any, Union, Callable
from datetime import datetime

from hvpy.datasources import DataSources
from hvpy.datasource import DataSource

__all__ = [
"convert_date_to_isoformat",
Expand Down Expand Up @@ -37,19 +37,19 @@ def convert_date_to_unix(v: list) -> str:
return ",".join([str(int(datetime.timestamp(d))) for d in v])


def _to_datasource(val: Union[int, DataSources]) -> DataSources:
def _to_datasource(val: Union[int, DataSource]) -> DataSource:
"""
Validates the input and converts it to a DataSources enum.
Validates the input and converts it to a DataSource enum.
"""
if isinstance(val, int) and val in [x.value for x in DataSources]:
return DataSources(val)
elif isinstance(val, DataSources):
if isinstance(val, int) and val in [x.value for x in DataSource]:
return DataSource(val)
elif isinstance(val, DataSource):
return val
else:
raise ValueError(f"{val} is not a valid DataSources")
raise ValueError(f"{val} is not a valid DataSource")


def _create_layer_string(source_id: DataSources, opacity: int) -> str:
def _create_layer_string(source_id: DataSource, opacity: int) -> str:
"""
Generates a string of the form "[source_id,1,opacity]" for a layer.
"""
Expand Down