-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: provide a way to set property during testing (#395)
* fix: make tester init_test_app_property_from_json internal * feat: support set property for single extension testing * feat: add more python standalone test case * fix: refine codes * fix: refine codes --------- Co-authored-by: Hu Yueh-Wei <[email protected]>
- Loading branch information
Showing
17 changed files
with
238 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...include_internal/ten_runtime/binding/cpp/detail/test/extension_tester_internal_accessor.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// Copyright © 2024 Agora | ||
// This file is part of TEN Framework, an open source project. | ||
// Licensed under the Apache License, Version 2.0, with certain conditions. | ||
// Refer to the "LICENSE" file in the root directory for more information. | ||
// | ||
#pragma once | ||
|
||
#include "ten_runtime/binding/cpp/detail/test/extension_tester.h" | ||
|
||
namespace ten { | ||
|
||
class extension_tester_internal_accessor_t { | ||
public: | ||
static void init_test_app_property_from_json(extension_tester_t &tester, | ||
const char *property_json_str) { | ||
TEN_ASSERT(property_json_str, "Invalid argument."); | ||
ten_extension_tester_init_test_app_property_from_json( | ||
tester.c_extension_tester, property_json_str); | ||
} | ||
}; | ||
|
||
} // namespace ten |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...gration/python/standalone_test_python/default_extension_python/tests/test_set_property.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# | ||
# Copyright © 2024 Agora | ||
# This file is part of TEN Framework, an open source project. | ||
# Licensed under the Apache License, Version 2.0, with certain conditions. | ||
# Refer to the "LICENSE" file in the root directory for more information. | ||
# | ||
from pathlib import Path | ||
from typing import Optional | ||
from ten import ( | ||
ExtensionTester, | ||
TenEnvTester, | ||
Cmd, | ||
CmdResult, | ||
StatusCode, | ||
TenError, | ||
) | ||
|
||
|
||
class ExtensionTesterSetProperty(ExtensionTester): | ||
def check_greeting( | ||
self, | ||
ten_env: TenEnvTester, | ||
result: Optional[CmdResult], | ||
error: Optional[TenError], | ||
): | ||
if error is not None: | ||
assert False, error | ||
|
||
assert result is not None | ||
|
||
statusCode = result.get_status_code() | ||
print("receive hello_world, status:" + str(statusCode)) | ||
|
||
if statusCode == StatusCode.OK: | ||
detail = result.get_property_string("detail") | ||
assert detail == "hola" | ||
|
||
ten_env.stop_test() | ||
|
||
def on_start(self, ten_env: TenEnvTester) -> None: | ||
cmd = Cmd.create("greeting") | ||
|
||
ten_env.send_cmd( | ||
cmd, | ||
lambda ten_env, result, error: self.check_greeting( | ||
ten_env, result, error | ||
), | ||
) | ||
|
||
print("tester on_start_done") | ||
ten_env.on_start_done() | ||
|
||
|
||
def test_set_property(): | ||
tester = ExtensionTesterSetProperty() | ||
tester.add_addon_base_dir(str(Path(__file__).resolve().parent.parent)) | ||
tester.set_test_mode_single( | ||
"default_extension_python", '{"greeting": "hola"}' | ||
) | ||
tester.run() | ||
|
||
|
||
if __name__ == "__main__": | ||
test_set_property() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.