Skip to content

Commit f25eacd

Browse files
authored
Use Enum values (#30)
* use values * bump version
1 parent be82eef commit f25eacd

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

src/starplot/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Star charts and maps"""
22

3-
__version__ = "0.3.2"
3+
__version__ = "0.3.3"
44

55
from .base import StarPlot # noqa: F401
66
from .zenith import ZenithPlot # noqa: F401

src/starplot/styles/base.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ def merge_dict(dict_1: dict, dict_2: dict) -> None:
3636
dict_1[k] = dict_2[k]
3737

3838

39+
class BaseStyle(BaseModel):
40+
class Config:
41+
use_enum_values = True
42+
43+
3944
class FillStyleEnum(str, Enum):
4045
"""Constants that represent the possible fill styles for markers."""
4146

@@ -99,7 +104,7 @@ class DashCapStyleEnum(str, Enum):
99104
ROUND = "round"
100105

101106

102-
class MarkerStyle(BaseModel):
107+
class MarkerStyle(BaseStyle):
103108
"""
104109
Styling properties for markers.
105110
@@ -154,7 +159,7 @@ def matplot_kwargs(self, size_multiplier: float = 1.0) -> dict:
154159
)
155160

156161

157-
class LineStyle(BaseModel):
162+
class LineStyle(BaseStyle):
158163
"""
159164
Styling properties for lines.
160165
@@ -204,7 +209,7 @@ def matplot_kwargs(self, size_multiplier: float = 1.0) -> dict:
204209
return result
205210

206211

207-
class PolygonStyle(BaseModel):
212+
class PolygonStyle(BaseStyle):
208213
"""
209214
Styling properties for polygons.
210215
@@ -244,7 +249,7 @@ def matplot_kwargs(self, size_multiplier: float = 1.0) -> dict:
244249
)
245250

246251

247-
class LabelStyle(BaseModel):
252+
class LabelStyle(BaseStyle):
248253
"""
249254
Styling properties for a label.
250255
@@ -295,7 +300,7 @@ def matplot_kwargs(self, size_multiplier: float = 1.0) -> dict:
295300
)
296301

297302

298-
class ObjectStyle(BaseModel):
303+
class ObjectStyle(BaseStyle):
299304
"""Defines the style for a SkyObject"""
300305

301306
marker: MarkerStyle = MarkerStyle()
@@ -305,7 +310,7 @@ class ObjectStyle(BaseModel):
305310
"""Style for the object's label (see [LabelStyle][starplot.styles.LabelStyle])"""
306311

307312

308-
class PathStyle(BaseModel):
313+
class PathStyle(BaseStyle):
309314
"""Defines the style for a path (e.g. constellation lines)"""
310315

311316
line: LineStyle = LineStyle()
@@ -315,7 +320,7 @@ class PathStyle(BaseModel):
315320
"""Style for the path's label (see [LabelStyle][starplot.styles.LabelStyle])"""
316321

317322

318-
class PlotStyle(BaseModel):
323+
class PlotStyle(BaseStyle):
319324
"""
320325
Defines the styling for a plot
321326
"""

tests/test_styles.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pydantic import ValidationError
44
from pydantic.color import Color
55

6-
from starplot.styles import PlotStyle, FontWeightEnum
6+
from starplot.styles import PlotStyle, FontWeightEnum, LineStyle, LineStyleEnum
77

88

99
@pytest.mark.parametrize(
@@ -38,3 +38,8 @@ def test_plot_style_valid(kwargs):
3838
def test_plot_style_invalid(kwargs):
3939
with pytest.raises(ValidationError):
4040
PlotStyle(**kwargs)
41+
42+
43+
def test_style_enums_use_strings():
44+
line_style = LineStyle(style=LineStyleEnum.DASHED)
45+
assert line_style.style == "dashed"

0 commit comments

Comments
 (0)