예제 #1
0
파일: router.py 프로젝트: vuiseng9/lpot
def get_model_graph(data: Dict[str, Any]) -> Graph:
    """Get model graph."""
    graph_reader = GraphReader()
    return graph_reader.read(
        model_path=RequestDataProcessor.get_string_value(data, "path"),
        expanded_groups=data.get("group", []),
    )
예제 #2
0
    def test_get_string_value_with_single_value(self) -> None:
        """Test get_string_value when single value was provided."""
        expected = "expected_value"
        data = {
            "requested_key": [expected],
        }

        self.assertEqual(
            "expected_value",
            RequestDataProcessor.get_string_value(data, "requested_key"),
        )
예제 #3
0
    def get_code_template(data: dict) -> Response:
        """Get code template file for requested Workload."""
        workload_id = RequestDataProcessor.get_string_value(data, "workload_id")
        workdir = Workdir()
        workload_data = workdir.get_workload_data(workload_id)
        code_template_path = workload_data.get("code_template_path")

        if not code_template_path:
            raise NotFoundException(f"Unable to find code template file for {workload_id}")

        return ResponseGenerator.serve_from_filesystem(
            path=code_template_path,
            mimetype="text/x-python",
        )
예제 #4
0
    def test_get_string_value_with_multiple_values(self) -> None:
        """Test get_string_value when many values were provided."""
        expected = "expected_value"
        data = {
            "requested_key": [
                expected,
                " and ",
                "some",
                "more",
            ],
        }

        self.assertEqual(
            "expected_value",
            RequestDataProcessor.get_string_value(data, "requested_key"),
        )
예제 #5
0
    def get_output(data: dict) -> Response:
        """Get config file for requested Workload."""
        workload_id = RequestDataProcessor.get_string_value(data, "workload_id")
        workdir = Workdir()
        workload_data = workdir.get_workload_data(workload_id)
        log_path = workload_data.get("log_path")

        if not log_path:
            raise NotFoundException(f"Unable to find output log for {workload_id}")

        try:
            response = ResponseGenerator.serve_from_filesystem(
                path=log_path,
                mimetype="text/plain",
            )
        except Exception as e:
            response = ResponseGenerator.from_exception(e)

        return ResponseGenerator.add_refresh(
            response=response,
            refresh_time=3,
        )
예제 #6
0
    def test_get_string_fails_when_data_missing(self) -> None:
        """Test get_string_value fails."""
        data: Dict[str, Any] = {}

        with self.assertRaisesRegex(ClientErrorException, "Missing requested_key parameter"):
            RequestDataProcessor.get_string_value(data, "requested_key")