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

Commit

Permalink
test: fix yaml_path missing in the test
Browse files Browse the repository at this point in the history
  • Loading branch information
hanhxiao committed Aug 7, 2019
1 parent 2191b27 commit 24f9fd1
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 15 deletions.
4 changes: 1 addition & 3 deletions gnes/cli/parser.py
Expand Up @@ -157,7 +157,7 @@ def set_loadable_service_parser(parser=None):
from ..service.base import SocketType from ..service.base import SocketType
set_service_parser(parser) set_service_parser(parser)


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


Expand All @@ -179,8 +179,6 @@ def set_router_service_parser(parser=None):
if not parser: if not parser:
parser = set_base_parser() parser = set_base_parser()
set_loadable_service_parser(parser) set_loadable_service_parser(parser)
parser.set_defaults(yaml_path='BaseRouter')

parser.set_defaults(read_only=True) parser.set_defaults(read_only=True)
return parser return parser


Expand Down
8 changes: 4 additions & 4 deletions gnes/composer/base.py
Expand Up @@ -43,11 +43,11 @@ class YamlComposer:
} }


comp2args = { comp2args = {
'Encoder': set_loadable_service_parser().parse_args([]), 'Encoder': set_loadable_service_parser().parse_args(['--yaml_path', 'BaseEncoder']),
'Router': set_router_service_parser().parse_args([]), 'Router': set_router_service_parser().parse_args(['--yaml_path', 'BaseRouter']),
'Indexer': set_indexer_service_parser().parse_args([]), 'Indexer': set_indexer_service_parser().parse_args(['--yaml_path', 'BaseIndexer']),
'gRPCFrontend': set_grpc_frontend_parser().parse_args([]), 'gRPCFrontend': set_grpc_frontend_parser().parse_args([]),
'Preprocessor': set_preprocessor_service_parser().parse_args([]) 'Preprocessor': set_preprocessor_service_parser().parse_args(['--yaml_path', 'BasePreprocessor'])
} }


class Layer: class Layer:
Expand Down
7 changes: 4 additions & 3 deletions tests/test_preprocessor.py
Expand Up @@ -14,14 +14,15 @@ def setUp(self):
self.single_cn = '矫矫珍木巅,得无金丸惧。' self.single_cn = '矫矫珍木巅,得无金丸惧。'
self.single_en = 'When forty winters shall besiege thy brow. And dig deep trenches in thy beautys field.' self.single_en = 'When forty winters shall besiege thy brow. And dig deep trenches in thy beautys field.'
self.dirname = os.path.dirname(__file__) self.dirname = os.path.dirname(__file__)
self.yaml_path = os.path.join(self.dirname, 'yaml', 'test-preprocessor.yml')


def test_preprocessor_service_empty(self): def test_preprocessor_service_empty(self):
args = set_preprocessor_service_parser().parse_args([]) args = set_preprocessor_service_parser().parse_args(['--yaml_path', 'BasePreprocessor'])
with PreprocessorService(args): with PreprocessorService(args):
pass pass


def test_preprocessor_service_echo(self): def test_preprocessor_service_echo(self):
args = set_preprocessor_service_parser().parse_args([]) args = set_preprocessor_service_parser().parse_args(['--yaml_path', 'BasePreprocessor'])
c_args = _set_client_parser().parse_args([ c_args = _set_client_parser().parse_args([
'--port_in', str(args.port_out), '--port_in', str(args.port_out),
'--port_out', str(args.port_in) '--port_out', str(args.port_in)
Expand All @@ -38,7 +39,7 @@ def test_preprocessor_service_echo(self):
print(r) print(r)


def test_preprocessor_service_realdata(self): def test_preprocessor_service_realdata(self):
args = set_preprocessor_service_parser().parse_args([]) args = set_preprocessor_service_parser().parse_args(['--yaml_path', self.yaml_path])
c_args = _set_client_parser().parse_args([ c_args = _set_client_parser().parse_args([
'--port_in', str(args.port_out), '--port_in', str(args.port_out),
'--port_out', str(args.port_in) '--port_out', str(args.port_in)
Expand Down
14 changes: 9 additions & 5 deletions tests/test_router.py
Expand Up @@ -22,7 +22,7 @@ def setUp(self):
self.concat_router_yaml = 'ConcatEmbedRouter' self.concat_router_yaml = 'ConcatEmbedRouter'


def test_service_empty(self): def test_service_empty(self):
args = set_router_service_parser().parse_args([]) args = set_router_service_parser().parse_args(['--yaml_path', 'BaseRouter'])
with RouterService(args): with RouterService(args):
pass pass


Expand Down Expand Up @@ -287,25 +287,29 @@ def test_multimap_multireduce(self):
'--socket_in', str(SocketType.SUB_CONNECT), '--socket_in', str(SocketType.SUB_CONNECT),
'--socket_out', str(SocketType.PUSH_CONNECT), '--socket_out', str(SocketType.PUSH_CONNECT),
'--port_in', str(p21.port_out), '--port_in', str(p21.port_out),
'--port_out', str(r41.port_in) '--port_out', str(r41.port_in),
'--yaml_path', 'BaseRouter'
]) ])
r312 = set_router_service_parser().parse_args([ r312 = set_router_service_parser().parse_args([
'--socket_in', str(SocketType.SUB_CONNECT), '--socket_in', str(SocketType.SUB_CONNECT),
'--socket_out', str(SocketType.PUSH_CONNECT), '--socket_out', str(SocketType.PUSH_CONNECT),
'--port_in', str(p21.port_out), '--port_in', str(p21.port_out),
'--port_out', str(r41.port_in) '--port_out', str(r41.port_in),
'--yaml_path', 'BaseRouter'
]) ])
r321 = set_router_service_parser().parse_args([ r321 = set_router_service_parser().parse_args([
'--socket_in', str(SocketType.SUB_CONNECT), '--socket_in', str(SocketType.SUB_CONNECT),
'--socket_out', str(SocketType.PUSH_CONNECT), '--socket_out', str(SocketType.PUSH_CONNECT),
'--port_in', str(p22.port_out), '--port_in', str(p22.port_out),
'--port_out', str(r42.port_in) '--port_out', str(r42.port_in),
'--yaml_path', 'BaseRouter'
]) ])
r322 = set_router_service_parser().parse_args([ r322 = set_router_service_parser().parse_args([
'--socket_in', str(SocketType.SUB_CONNECT), '--socket_in', str(SocketType.SUB_CONNECT),
'--socket_out', str(SocketType.PUSH_CONNECT), '--socket_out', str(SocketType.PUSH_CONNECT),
'--port_in', str(p22.port_out), '--port_in', str(p22.port_out),
'--port_out', str(r42.port_in) '--port_out', str(r42.port_in),
'--yaml_path', 'BaseRouter'
]) ])


c_args = _set_client_parser().parse_args([ c_args = _set_client_parser().parse_args([
Expand Down
3 changes: 3 additions & 0 deletions tests/test_stream_grpc.py
Expand Up @@ -49,6 +49,7 @@ def test_grpc_frontend(self):
'--port_out', str(args.port_in), '--port_out', str(args.port_in),
'--socket_in', str(SocketType.PULL_CONNECT), '--socket_in', str(SocketType.PULL_CONNECT),
'--socket_out', str(SocketType.PUSH_CONNECT), '--socket_out', str(SocketType.PUSH_CONNECT),
'--yaml_path', 'BaseRouter'
]) ])


with RouterService(p_args), GRPCFrontend(args), grpc.insecure_channel( with RouterService(p_args), GRPCFrontend(args), grpc.insecure_channel(
Expand All @@ -72,13 +73,15 @@ def test_async_block(self):
'--port_out', '8899', '--port_out', '8899',
'--socket_in', str(SocketType.PULL_CONNECT), '--socket_in', str(SocketType.PULL_CONNECT),
'--socket_out', str(SocketType.PUSH_CONNECT), '--socket_out', str(SocketType.PUSH_CONNECT),
'--yaml_path', 'BaseRouter'
]) ])


p2_args = set_router_service_parser().parse_args([ p2_args = set_router_service_parser().parse_args([
'--port_in', str(p1_args.port_out), '--port_in', str(p1_args.port_out),
'--port_out', str(args.port_in), '--port_out', str(args.port_in),
'--socket_in', str(SocketType.PULL_BIND), '--socket_in', str(SocketType.PULL_BIND),
'--socket_out', str(SocketType.PUSH_CONNECT), '--socket_out', str(SocketType.PUSH_CONNECT),
'--yaml_path', 'BaseRouter'
]) ])


with GRPCFrontend(args), Router1(p1_args), Router2(p2_args), grpc.insecure_channel( with GRPCFrontend(args), Router1(p1_args), Router2(p2_args), grpc.insecure_channel(
Expand Down
7 changes: 7 additions & 0 deletions tests/yaml/test-preprocessor.yml
@@ -0,0 +1,7 @@
!TextPreprocessor
parameter:
start_doc_id: 0
random_doc_id: True
deliminator: "[.。!?!?]+"
gnes_config:
is_trained: true

0 comments on commit 24f9fd1

Please sign in to comment.