Skip to content
This repository was archived by the owner on Feb 22, 2020. It is now read-only.

Commit 24f9fd1

Browse files
author
hanhxiao
committed
test: fix yaml_path missing in the test
1 parent 2191b27 commit 24f9fd1

File tree

6 files changed

+28
-15
lines changed

6 files changed

+28
-15
lines changed

gnes/cli/parser.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def set_loadable_service_parser(parser=None):
157157
from ..service.base import SocketType
158158
set_service_parser(parser)
159159

160-
parser.add_argument('--yaml_path', type=resolve_yaml_path,
160+
parser.add_argument('--yaml_path', type=resolve_yaml_path, required=True,
161161
help='yaml config of the service, it should be a readable stream,'
162162
' or a valid file path, or a supported class name.')
163163

@@ -179,8 +179,6 @@ def set_router_service_parser(parser=None):
179179
if not parser:
180180
parser = set_base_parser()
181181
set_loadable_service_parser(parser)
182-
parser.set_defaults(yaml_path='BaseRouter')
183-
184182
parser.set_defaults(read_only=True)
185183
return parser
186184

gnes/composer/base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ class YamlComposer:
4343
}
4444

4545
comp2args = {
46-
'Encoder': set_loadable_service_parser().parse_args([]),
47-
'Router': set_router_service_parser().parse_args([]),
48-
'Indexer': set_indexer_service_parser().parse_args([]),
46+
'Encoder': set_loadable_service_parser().parse_args(['--yaml_path', 'BaseEncoder']),
47+
'Router': set_router_service_parser().parse_args(['--yaml_path', 'BaseRouter']),
48+
'Indexer': set_indexer_service_parser().parse_args(['--yaml_path', 'BaseIndexer']),
4949
'gRPCFrontend': set_grpc_frontend_parser().parse_args([]),
50-
'Preprocessor': set_preprocessor_service_parser().parse_args([])
50+
'Preprocessor': set_preprocessor_service_parser().parse_args(['--yaml_path', 'BasePreprocessor'])
5151
}
5252

5353
class Layer:

tests/test_preprocessor.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ def setUp(self):
1414
self.single_cn = '矫矫珍木巅,得无金丸惧。'
1515
self.single_en = 'When forty winters shall besiege thy brow. And dig deep trenches in thy beautys field.'
1616
self.dirname = os.path.dirname(__file__)
17+
self.yaml_path = os.path.join(self.dirname, 'yaml', 'test-preprocessor.yml')
1718

1819
def test_preprocessor_service_empty(self):
19-
args = set_preprocessor_service_parser().parse_args([])
20+
args = set_preprocessor_service_parser().parse_args(['--yaml_path', 'BasePreprocessor'])
2021
with PreprocessorService(args):
2122
pass
2223

2324
def test_preprocessor_service_echo(self):
24-
args = set_preprocessor_service_parser().parse_args([])
25+
args = set_preprocessor_service_parser().parse_args(['--yaml_path', 'BasePreprocessor'])
2526
c_args = _set_client_parser().parse_args([
2627
'--port_in', str(args.port_out),
2728
'--port_out', str(args.port_in)
@@ -38,7 +39,7 @@ def test_preprocessor_service_echo(self):
3839
print(r)
3940

4041
def test_preprocessor_service_realdata(self):
41-
args = set_preprocessor_service_parser().parse_args([])
42+
args = set_preprocessor_service_parser().parse_args(['--yaml_path', self.yaml_path])
4243
c_args = _set_client_parser().parse_args([
4344
'--port_in', str(args.port_out),
4445
'--port_out', str(args.port_in)

tests/test_router.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def setUp(self):
2222
self.concat_router_yaml = 'ConcatEmbedRouter'
2323

2424
def test_service_empty(self):
25-
args = set_router_service_parser().parse_args([])
25+
args = set_router_service_parser().parse_args(['--yaml_path', 'BaseRouter'])
2626
with RouterService(args):
2727
pass
2828

@@ -287,25 +287,29 @@ def test_multimap_multireduce(self):
287287
'--socket_in', str(SocketType.SUB_CONNECT),
288288
'--socket_out', str(SocketType.PUSH_CONNECT),
289289
'--port_in', str(p21.port_out),
290-
'--port_out', str(r41.port_in)
290+
'--port_out', str(r41.port_in),
291+
'--yaml_path', 'BaseRouter'
291292
])
292293
r312 = set_router_service_parser().parse_args([
293294
'--socket_in', str(SocketType.SUB_CONNECT),
294295
'--socket_out', str(SocketType.PUSH_CONNECT),
295296
'--port_in', str(p21.port_out),
296-
'--port_out', str(r41.port_in)
297+
'--port_out', str(r41.port_in),
298+
'--yaml_path', 'BaseRouter'
297299
])
298300
r321 = set_router_service_parser().parse_args([
299301
'--socket_in', str(SocketType.SUB_CONNECT),
300302
'--socket_out', str(SocketType.PUSH_CONNECT),
301303
'--port_in', str(p22.port_out),
302-
'--port_out', str(r42.port_in)
304+
'--port_out', str(r42.port_in),
305+
'--yaml_path', 'BaseRouter'
303306
])
304307
r322 = set_router_service_parser().parse_args([
305308
'--socket_in', str(SocketType.SUB_CONNECT),
306309
'--socket_out', str(SocketType.PUSH_CONNECT),
307310
'--port_in', str(p22.port_out),
308-
'--port_out', str(r42.port_in)
311+
'--port_out', str(r42.port_in),
312+
'--yaml_path', 'BaseRouter'
309313
])
310314

311315
c_args = _set_client_parser().parse_args([

tests/test_stream_grpc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def test_grpc_frontend(self):
4949
'--port_out', str(args.port_in),
5050
'--socket_in', str(SocketType.PULL_CONNECT),
5151
'--socket_out', str(SocketType.PUSH_CONNECT),
52+
'--yaml_path', 'BaseRouter'
5253
])
5354

5455
with RouterService(p_args), GRPCFrontend(args), grpc.insecure_channel(
@@ -72,13 +73,15 @@ def test_async_block(self):
7273
'--port_out', '8899',
7374
'--socket_in', str(SocketType.PULL_CONNECT),
7475
'--socket_out', str(SocketType.PUSH_CONNECT),
76+
'--yaml_path', 'BaseRouter'
7577
])
7678

7779
p2_args = set_router_service_parser().parse_args([
7880
'--port_in', str(p1_args.port_out),
7981
'--port_out', str(args.port_in),
8082
'--socket_in', str(SocketType.PULL_BIND),
8183
'--socket_out', str(SocketType.PUSH_CONNECT),
84+
'--yaml_path', 'BaseRouter'
8285
])
8386

8487
with GRPCFrontend(args), Router1(p1_args), Router2(p2_args), grpc.insecure_channel(

tests/yaml/test-preprocessor.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
!TextPreprocessor
2+
parameter:
3+
start_doc_id: 0
4+
random_doc_id: True
5+
deliminator: "[.。!?!?]+"
6+
gnes_config:
7+
is_trained: true

0 commit comments

Comments
 (0)