Skip to content

Commit 8a46116

Browse files
committed
Refactor _director and _utils modules; add %OnNew method in Common.cls and implement tests for production settings
1 parent c2a9fb3 commit 8a46116

File tree

9 files changed

+90
-12
lines changed

9 files changed

+90
-12
lines changed

src/iop/_director.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import signal
77
from dataclasses import dataclass
88

9-
from iop._business_host import _BusinessHost
109
from iop._dispatch import dispatch_deserializer, dispatch_serializer
1110
from iop._utils import _Utils
1211

@@ -278,7 +277,6 @@ def test_component(target,message=None,classname=None,body=None):
278277
else:
279278
message.json = _Utils.string_to_stream("{}")
280279
# serialize the message
281-
business_host = _BusinessHost()
282280
serial_message = dispatch_serializer(message)
283281
response = iris.cls('IOP.Utils').dispatchTestComponent(target,serial_message)
284282
try:

src/iop/_utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import xmltodict
77
import pkg_resources
88
import importlib
9+
import importlib.util
910
import json
1011
from iop._message import _Message, _PydanticMessage
1112
from pydantic import TypeAdapter
@@ -241,7 +242,7 @@ def migrate(filename=None):
241242
settings = _Utils.import_module_from_path('settings',filename)
242243
else:
243244
# import settings from the settings module
244-
import settings
245+
import settings # type: ignore
245246
# get the path of the settings file
246247
path = os.path.dirname(inspect.getfile(settings))
247248
try:
@@ -261,7 +262,7 @@ def migrate(filename=None):
261262
except AttributeError:
262263
print("No schemas to register")
263264
try:
264-
sys.path.remove(path)
265+
sys.path.remove(os.path.normpath(path))
265266
except ValueError:
266267
pass
267268

src/iop/cls/IOP/Common.cls

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,17 @@ Method GetModule() As %String
3737
Return ..%module
3838
}
3939

40+
Method %OnNew(pConfigName As %String) As %Status
41+
{
42+
$$$ThrowOnError(..Connect())
43+
Quit $method($this,"initConfig",.pConfigName) ; call subclass
44+
}
45+
4046
Method OnInit() As %Status
4147
{
4248
set tSC = $$$OK
4349
try {
44-
$$$ThrowOnError(..Connect())
50+
4551
do ..%class."_dispatch_on_init"($this)
4652
} catch ex {
4753
set tSC = ex.AsStatus()
File renamed without changes.
File renamed without changes.

src/tests/bench/settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from bo import BenchIoPOperation
2-
from bp import BenchIoPProcess
1+
from bench_bo import BenchIoPOperation
2+
from bench_bp import BenchIoPProcess
33

44
import os
55

src/tests/registerFilesIop/bo.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,14 @@ def OnMessage(self, pRequest):
125125
self.Adapter.PutLine(filename, " * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *")
126126

127127
return
128-
128+
129129
class MyOperation(BusinessOperation):
130130

131+
def OnMessage(self, request):
132+
self.log_info("Received message: "+str(request))
133+
134+
class MySettingOperation(BusinessOperation):
135+
131136
my_empty_var : str
132137
my_none_var = None
133138
my_int_var :int = 0
@@ -136,8 +141,8 @@ class MyOperation(BusinessOperation):
136141
my_str_var = "foo"
137142

138143
def OnMessage(self, request):
139-
self.LOGINFO('hello')
140-
return MyResponse(request.StringValue)
144+
attr = request.StringValue
145+
return MyResponse(self.__getattribute__(attr))
141146

142147
if __name__ == "__main__":
143148

src/tests/registerFilesIop/settings.py

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
CLASSES = {
99
'Python.RedditService': RedditService,
1010
'Python.FilterPostRoutingRule': bp.FilterPostRoutingRule,
11-
'Python.FileOperation': FileOperation,
1211
'Python.bp': bp,
12+
'Python.FileOperation': FileOperation,
13+
'UnitTest.MySettingOperation': MySettingOperation,
1314
}
1415

1516
PRODUCTIONS = [
@@ -21,5 +22,43 @@
2122
"Description": "",
2223
"ActorPoolSize": "2"
2324
}
25+
},
26+
{
27+
"Python.TestSettingProduction": {
28+
"@Name": "Python.TestSettingProduction",
29+
"@TestingEnabled": "true",
30+
"@LogGeneralTraceEvents": "false",
31+
"Description": "",
32+
"ActorPoolSize": "2",
33+
"Item": [
34+
{
35+
"@Name": "UnitTest.MySettingOperation",
36+
"@Enabled": "true",
37+
"@ClassName": "UnitTest.MySettingOperation",
38+
"Setting": [
39+
{
40+
"@Target": "Host",
41+
"@Name": "my_int_var",
42+
"#text": "1"
43+
},
44+
{
45+
"@Target": "Host",
46+
"@Name": "my_float_var",
47+
"#text": "1.0"
48+
},
49+
{
50+
"@Target": "Host",
51+
"@Name": "my_untyped_var",
52+
"#text": "1"
53+
},
54+
{
55+
"@Target": "Host",
56+
"@Name": "my_str_var",
57+
"#text": "bar"
58+
}
59+
]
60+
}
61+
]
62+
}
2463
}
25-
]
64+
]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from iop._director import _Director
2+
from iop._utils import _Utils
3+
4+
import os
5+
6+
import iris
7+
8+
class TestProductionSettings:
9+
@classmethod
10+
def setup_class(cls):
11+
path = os.path.join(iris.__getattribute__('__ospath'),'src/tests/registerFilesIop/settings.py')
12+
_Utils.migrate(path)
13+
_Director.stop_production()
14+
_Director.set_default_production('Python.TestSettingProduction')
15+
_Director.start_production()
16+
17+
def test_my_none_var(self):
18+
rsp = _Director.test_component('UnitTest.MySettingOperation',None,'iris.Ens.StringRequest',"my_none_var")
19+
assert rsp.value == ''
20+
21+
def test_my_str_var(self):
22+
rsp = _Director.test_component('UnitTest.MySettingOperation',None,'iris.Ens.StringRequest',"my_str_var")
23+
assert rsp.value == "bar"
24+
25+
26+
@classmethod
27+
def teardown_class(cls):
28+
_Director.stop_production()
29+
_Director.set_default_production('test')

0 commit comments

Comments
 (0)