コード例 #1
0
ファイル: test_folders.py プロジェクト: dynod/grpc-helper
 def test_valid(self):
     # Verify folders are created
     f = Folders(Path("/tmp"), self.test_folder / "user",
                 self.test_folder / "workspace")
     assert f.system.name == "tmp"
     assert f.user.is_dir()
     assert f.workspace.is_dir()
コード例 #2
0
ファイル: test_config.py プロジェクト: dynod/grpc-helper
    def test_folder_without_file_default(self):
        # A simple config manager -- shouldn't be disturbed is folder is non-null, but no config file inside
        ConfigManager(static_items=[SampleConfig],
                      folders=Folders(workspace=self.workspace_path,
                                      system=Path("/missing/folder")))

        # Check default value
        assert SampleConfig.INT_ITEM.int_val == 12
コード例 #3
0
ファイル: test_config.py プロジェクト: dynod/grpc-helper
    def test_system_default(self, system_config):
        # A simple config manager
        ConfigManager(static_items=[SampleConfig],
                      folders=Folders(workspace=self.workspace_path,
                                      system=system_config))

        # Check default value
        assert SampleConfig.INT_ITEM.int_val == -78
コード例 #4
0
 def new_server_instance(self, with_workspace: bool = True):
     # Create new server instance
     self.server = RpcServer(
         self.rpc_port,
         self.sample_register,
         user_items=self.user_items,
         folders=self.folders if with_workspace else Folders(),
         with_events=True)
コード例 #5
0
 def test_server_busy(self, sample_server):
     try:
         # Try to use the same port again
         RpcServer(self.rpc_port,
                   self.sample_register,
                   folders=Folders(workspace=self.test_folder / "wks2"))
         raise AssertionError("Shouldn't get here")
     except RpcException as e:
         assert e.rc == ResultCode.ERROR_PORT_BUSY
コード例 #6
0
ファイル: test_config.py プロジェクト: dynod/grpc-helper
    def test_cli_default(self, system_config, user_config, env_config):
        # A simple config manager
        ConfigManager(
            static_items=[SampleConfig],
            folders=Folders(workspace=self.workspace_path,
                            system=system_config,
                            user=user_config),
            cli_config={"my-int-config": "357"},
        )

        # Check default value
        assert SampleConfig.INT_ITEM.int_val == 357
コード例 #7
0
ファイル: test_config.py プロジェクト: dynod/grpc-helper
    def test_invalid_json_model(self, system_config):
        # Dump non-object Json in config
        with (system_config / "config.json").open("w") as f:
            f.write('{"unclosed item')
        try:
            ConfigManager(static_items=[SampleConfig],
                          folders=Folders(workspace=self.workspace_path,
                                          system=system_config))
            raise AssertionError("Shouldn't get here")
        except RpcException as e:
            assert e.rc == ResultCode.ERROR_MODEL_INVALID

        # Dump object with non-string values Json in config
        with (system_config / "config.json").open("w") as f:
            json.dump({"some-int": 45}, f)
        try:
            ConfigManager(static_items=[SampleConfig],
                          folders=Folders(workspace=self.workspace_path,
                                          system=system_config))
            raise AssertionError("Shouldn't get here")
        except RpcException as e:
            assert e.rc == ResultCode.ERROR_MODEL_INVALID
コード例 #8
0
 def start_another_server(self, use_ip: bool):
     return RpcServer(
         self.rpc_another_port,
         [
             RpcServiceDescriptor(
                 grpc_helper,
                 "sample2",
                 SampleApiVersion,
                 AnotherSampleServicer2()
                 if use_ip else AnotherSampleServicer(),
                 add_AnotherSampleServiceServicer_to_server,
                 AnotherSampleServiceStub,
             )
         ],
         user_items=self.user_items2,
         folders=Folders(workspace=self.test_folder / "wks_another"),
         cli_config={RpcStaticConfig.MAIN_PORT.name: str(self.proxy_port)},
     )
コード例 #9
0
 def new_proxy_server(self):
     self.proxy_server = RpcServer(
         self.proxy_port,
         [
             # Proxy service definition for sample services
             RpcServiceDescriptor(grpc_helper, "sample", SampleApiVersion,
                                  SampleServiceServicer(),
                                  add_SampleServiceServicer_to_server,
                                  SampleServiceStub, True),
             RpcServiceDescriptor(
                 grpc_helper,
                 "sample2",
                 SampleApiVersion,
                 AnotherSampleServiceServicer(),
                 add_AnotherSampleServiceServicer_to_server,
                 AnotherSampleServiceStub,
                 True,
             ),
         ],
         folders=Folders(workspace=self.proxy_workspace),
         with_events=True,
         with_debug_signal=False,
     )
     return self.proxy_server
コード例 #10
0
ファイル: test_folders.py プロジェクト: dynod/grpc-helper
 def test_empty(self):
     # Verify None values are supported
     f = Folders()
     assert f.system is None
     assert f.user is None
     assert f.workspace is None
コード例 #11
0
 def folders(self) -> Folders:
     return Folders(workspace=(self.workspace_path))