44"""
55
66import 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
138from 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
0 commit comments