Skip to content

Commit 5018631

Browse files
committed
comments
1 parent f73f888 commit 5018631

File tree

4 files changed

+23
-41
lines changed

4 files changed

+23
-41
lines changed

cadence/worker/_registry.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def __init__(self):
4646
def workflow(
4747
self,
4848
func: Optional[Callable] = None,
49-
**kwargs
49+
**kwargs: RegisterWorkflowOptions
5050
) -> Callable:
5151
"""
5252
Register a workflow function.
@@ -89,7 +89,7 @@ def decorator(f: Callable) -> Callable:
8989
def activity(
9090
self,
9191
func: Optional[Callable] = None,
92-
**kwargs
92+
**kwargs: RegisterActivityOptions
9393
) -> Callable:
9494
"""
9595
Register an activity function.

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,12 @@ dependencies = [
3030
"grpcio-tools>=1.50.0",
3131
"msgspec>=0.19.0",
3232
"protobuf==5.29.1",
33-
"pytest>=8.4.1",
3433
"typing-extensions>=4.0.0",
3534
]
3635

3736
[project.optional-dependencies]
3837
dev = [
39-
"pytest>=7.0.0",
38+
"pytest>=8.4.1",
4039
"pytest-cov>=4.0.0",
4140
"pytest-asyncio>=0.21.0",
4241
"black>=23.0.0",

tests/cadence/worker/test_registry.py

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@
44
"""
55

66
import pytest
7-
import sys
8-
import os
9-
10-
# Add the project root to the path
11-
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))
127

138
from cadence.worker import Registry, RegisterWorkflowOptions, RegisterActivityOptions
149

@@ -19,8 +14,10 @@ class TestRegistry:
1914
def test_basic_registry_creation(self):
2015
"""Test basic registry creation."""
2116
reg = Registry()
22-
assert len(reg._workflows) == 0
23-
assert len(reg._activities) == 0
17+
with pytest.raises(KeyError):
18+
reg.get_workflow("nonexistent")
19+
with pytest.raises(KeyError):
20+
reg.get_activity("nonexistent")
2421

2522
@pytest.mark.parametrize("registration_type", ["workflow", "activity"])
2623
def test_basic_registration_and_retrieval(self, registration_type):
@@ -32,14 +29,12 @@ def test_basic_registration_and_retrieval(self, registration_type):
3229
def test_func():
3330
return "test"
3431

35-
assert "test_func" in reg._workflows
3632
func = reg.get_workflow("test_func")
3733
else:
3834
@reg.activity
3935
def test_func():
4036
return "test"
4137

42-
assert "test_func" in reg._activities
4338
func = reg.get_activity("test_func")
4439

4540
assert func() == "test"
@@ -53,17 +48,12 @@ def test_func():
5348
return "direct_call"
5449

5550
if registration_type == "workflow":
56-
# Direct call behavior - should register and return the function
5751
registered_func = reg.workflow(test_func)
58-
assert "test_func" in reg._workflows
5952
func = reg.get_workflow("test_func")
6053
else:
61-
# Direct call behavior - should register and return the function
6254
registered_func = reg.activity(test_func)
63-
assert "test_func" in reg._activities
6455
func = reg.get_activity("test_func")
6556

66-
# Should be the same function
6757
assert registered_func == test_func
6858
assert func() == "direct_call"
6959

@@ -77,19 +67,19 @@ def test_decorator_with_options(self, registration_type):
7767
def test_func():
7868
return "decorator_with_options"
7969

80-
assert "custom_name" in reg._workflows
81-
assert "custom_alias" in reg._workflow_aliases
8270
func = reg.get_workflow("custom_name")
71+
func_by_alias = reg.get_workflow("custom_alias")
8372
else:
8473
@reg.activity(name="custom_name", alias="custom_alias")
8574
def test_func():
8675
return "decorator_with_options"
8776

88-
assert "custom_name" in reg._activities
89-
assert "custom_alias" in reg._activity_aliases
9077
func = reg.get_activity("custom_name")
78+
func_by_alias = reg.get_activity("custom_alias")
9179

9280
assert func() == "decorator_with_options"
81+
assert func_by_alias() == "decorator_with_options"
82+
assert func == func_by_alias
9383

9484
@pytest.mark.parametrize("registration_type", ["workflow", "activity"])
9585
def test_direct_call_with_options(self, registration_type):
@@ -100,20 +90,18 @@ def test_func():
10090
return "direct_call_with_options"
10191

10292
if registration_type == "workflow":
103-
# Direct call with options
10493
registered_func = reg.workflow(test_func, name="custom_name", alias="custom_alias")
105-
assert "custom_name" in reg._workflows
106-
assert "custom_alias" in reg._workflow_aliases
10794
func = reg.get_workflow("custom_name")
95+
func_by_alias = reg.get_workflow("custom_alias")
10896
else:
109-
# Direct call with options
11097
registered_func = reg.activity(test_func, name="custom_name", alias="custom_alias")
111-
assert "custom_name" in reg._activities
112-
assert "custom_alias" in reg._activity_aliases
11398
func = reg.get_activity("custom_name")
99+
func_by_alias = reg.get_activity("custom_name")
114100

115101
assert registered_func == test_func
116102
assert func() == "direct_call_with_options"
103+
assert func_by_alias() == "direct_call_with_options"
104+
assert func == func_by_alias
117105

118106
@pytest.mark.parametrize("registration_type", ["workflow", "activity"])
119107
def test_not_found_error(self, registration_type):
@@ -161,15 +149,16 @@ def test_alias_functionality(self, registration_type):
161149
def test_func():
162150
return "test"
163151

164-
assert "custom_name" in reg._workflows
165152
func = reg.get_workflow("custom_name")
166153
else:
167154
@reg.activity(alias="custom_alias")
168155
def test_func():
169156
return "test"
170157

171-
assert "custom_alias" in reg._activity_aliases
172158
func = reg.get_activity("custom_alias")
159+
func_by_name = reg.get_activity("test_func")
160+
assert func_by_name() == "test"
161+
assert func == func_by_name
173162

174163
assert func() == "test"
175164

@@ -185,22 +174,18 @@ def test_options_class(self, registration_type):
185174
def test_func():
186175
return "test"
187176

188-
assert "custom_name" in reg._workflows
189-
assert "custom_alias" in reg._workflow_aliases
190177
func = reg.get_workflow("custom_name")
178+
func_by_alias = reg.get_workflow("custom_alias")
191179
else:
192180
options = RegisterActivityOptions(name="custom_name", alias="custom_alias")
193181

194182
@reg.activity(**options.__dict__)
195183
def test_func():
196184
return "test"
197185

198-
assert "custom_name" in reg._activities
199-
assert "custom_alias" in reg._activity_aliases
200186
func = reg.get_activity("custom_name")
187+
func_by_alias = reg.get_activity("custom_alias")
201188

202189
assert func() == "test"
203-
204-
205-
if __name__ == "__main__":
206-
pytest.main([__file__])
190+
assert func_by_alias() == "test"
191+
assert func == func_by_alias

uv.lock

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)