Skip to content

Commit

Permalink
feat: clone handle add (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
SAKURA-CAT authored Dec 9, 2024
1 parent 6cbb528 commit 09489b9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ build-backend = "hatchling.build"

[project]
name = "swankit"
version = "0.1.2b3"
version = "0.1.2b4"
dynamic = ["readme", "dependencies"]
description = "Base toolkit for SwanLab"
license = "Apache-2.0"
Expand Down
13 changes: 13 additions & 0 deletions swankit/callback/models/key.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ def __init__(self, y_range: YRange = None, chart_name: Optional[str] = None, met
self.chart_name: Optional[str] = chart_name
self.metric_name: Optional[str] = metric_name

def clone(self, y_range: YRange = None, chart_name: Optional[str] = None, metric_name: Optional[str] = None):
"""
克隆一个新的ColumnConfig对象,并且可以修改其中的参数
:param y_range: y轴范围
:param chart_name: 图表名称
:param metric_name: 指标名称
"""
return ColumnConfig(
y_range=y_range if y_range is not None else self.y_range,
chart_name=chart_name if chart_name is not None else self.chart_name,
metric_name=metric_name if metric_name is not None else self.metric_name,
)


class ColumnInfo:
"""
Expand Down
15 changes: 15 additions & 0 deletions test/unit/callback/models/test_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@
from swankit.core import ChartType


def test_column_config():
c = K.ColumnConfig(y_range=(0, 100), chart_name="CPU Utilization (%)")
assert c.y_range == (0, 100)
assert c.chart_name == "CPU Utilization (%)"
assert c.metric_name is None
clone = c.clone(y_range=None, metric_name="12345")
assert clone.y_range == (0, 100)
assert clone.chart_name == c.chart_name
assert clone.metric_name == "12345"
clone = c.clone(y_range=(0, 50), chart_name="CPU Utilization (%)", metric_name="12345")
assert clone.y_range == (0, 50)
assert clone.chart_name == c.chart_name
assert clone.metric_name == "12345"


def test_column_info():
c = K.ColumnInfo(
key="a/1",
Expand Down

0 comments on commit 09489b9

Please sign in to comment.