Skip to content

Commit 89122f1

Browse files
authored
Rename DataSources enum to DataSource (#69)
1 parent c8d31f5 commit 89122f1

File tree

6 files changed

+22
-22
lines changed

6 files changed

+22
-22
lines changed

docs/api.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ API Reference
1313
.. automodapi:: hvpy.parameters
1414
:allowed-package-names: hvpy.api_groups
1515

16-
.. automodapi:: hvpy.datasources
16+
.. automodapi:: hvpy.datasource
1717
:no-inheritance-diagram:
1818

1919
.. automodapi:: hvpy.utils

hvpy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from .facade import *
22
from .config import set_api_url
33
from .version import __version__
4-
from .datasources import *
4+
from .datasource import *
55
from .utils import create_layers
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from enum import Enum
22

3-
__all__ = ["DataSources"]
3+
__all__ = ["DataSource"]
44

55

6-
class DataSources(Enum):
6+
class DataSource(Enum):
77
"""
88
Enum for datasources hosted by the Helioviewer Project.
99
"""

hvpy/tests/test_datasources.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Any
22

3-
from hvpy import DataSources, getDataSources
3+
from hvpy import DataSource, getDataSources
44

55

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

2525
def test_datasources():
2626
source_ids = []
27-
enum_values = [s_id.value for s_id in DataSources]
27+
enum_values = [s_id.value for s_id in DataSource]
2828
response = getDataSources()
2929
find_nested_keys(response, "sourceId", source_ids)
3030
for source_id in source_ids:

hvpy/tests/test_utils.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import pytest
22

3-
from hvpy import DataSources
3+
from hvpy import DataSource
44
from hvpy.utils import _create_layer_string, _to_datasource, create_layers
55

66

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

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

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

1919

2020
def test_to_datasource():
21-
assert _to_datasource(9) == DataSources.AIA_131
22-
assert _to_datasource(DataSources.AIA_94) == DataSources.AIA_94
23-
with pytest.raises(ValueError, match="999 is not a valid DataSources"):
21+
assert _to_datasource(9) == DataSource.AIA_131
22+
assert _to_datasource(DataSource.AIA_94) == DataSource.AIA_94
23+
with pytest.raises(ValueError, match="999 is not a valid DataSource"):
2424
_to_datasource(999)
2525

2626

2727
def test_create_layers_string():
28-
assert _create_layer_string(DataSources.AIA_131, 100) == "[9,1,100]"
28+
assert _create_layer_string(DataSource.AIA_131, 100) == "[9,1,100]"
2929
with pytest.raises(ValueError, match="must be between 0 and 100"):
30-
_create_layer_string(DataSources.AIA_131, 101)
30+
_create_layer_string(DataSource.AIA_131, 101)
3131
with pytest.raises(ValueError, match="must be between 0 and 100"):
32-
_create_layer_string(DataSources.AIA_131, -1)
32+
_create_layer_string(DataSource.AIA_131, -1)

hvpy/utils.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Any, Union, Callable
22
from datetime import datetime
33

4-
from hvpy.datasources import DataSources
4+
from hvpy.datasource import DataSource
55

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

3939

40-
def _to_datasource(val: Union[int, DataSources]) -> DataSources:
40+
def _to_datasource(val: Union[int, DataSource]) -> DataSource:
4141
"""
42-
Validates the input and converts it to a DataSources enum.
42+
Validates the input and converts it to a DataSource enum.
4343
"""
44-
if isinstance(val, int) and val in [x.value for x in DataSources]:
45-
return DataSources(val)
46-
elif isinstance(val, DataSources):
44+
if isinstance(val, int) and val in [x.value for x in DataSource]:
45+
return DataSource(val)
46+
elif isinstance(val, DataSource):
4747
return val
4848
else:
49-
raise ValueError(f"{val} is not a valid DataSources")
49+
raise ValueError(f"{val} is not a valid DataSource")
5050

5151

52-
def _create_layer_string(source_id: DataSources, opacity: int) -> str:
52+
def _create_layer_string(source_id: DataSource, opacity: int) -> str:
5353
"""
5454
Generates a string of the form "[source_id,1,opacity]" for a layer.
5555
"""

0 commit comments

Comments
 (0)