From 8aa20bb7b6597c34e197e80287359ea276612cdd Mon Sep 17 00:00:00 2001 From: nickgorodilov Date: Mon, 25 Aug 2025 15:37:28 +0400 Subject: [PATCH] Add async methods tests for Ch. 16.3.3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue:https://gitee.com/openharmony/arkcompiler_runtime_core/issues/ICVIKW Testing: all pre-merge tests passed, logs available in ggWatcher Signed-off-by: Iaroslav_Antonov --- ..._function_returns_promise_predefined0.ets} | 24 +---- .../03.async_methods/async_method0.ets | 35 ------- .../03.async_methods/async_method11.ets | 39 -------- .../03.async_methods/async_method12.ets | 35 ------- .../03.async_methods/async_method14.ets | 35 ------- .../03.async_methods/async_method2.ets | 35 ------- .../03.async_methods/async_method23.ets | 39 -------- ...nc_method_returns_promise_predefined0.ets} | 24 +---- .../async_returns_predefined0.base.jinja | 68 +++++++++++++ .../predefined_types.jinja | 98 +++++++++++++++++++ .../plugins/ets/ets_templates/template.py | 11 ++- 11 files changed, 182 insertions(+), 261 deletions(-) rename static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/{03.async_methods/async_method13.ets => 01.async_functions/return_type_is_promise/no_input_params/predefined_types/async_function_returns_promise_predefined0.ets} (53%) delete mode 100644 static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method0.ets delete mode 100644 static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method11.ets delete mode 100644 static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method12.ets delete mode 100644 static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method14.ets delete mode 100644 static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method2.ets delete mode 100644 static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method23.ets rename static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/{async_method1.ets => return_type_is_promise/no_input_params/predefined_types/async_method_returns_promise_predefined0.ets} (53%) create mode 100644 static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/async_returns_predefined0.base.jinja create mode 100644 static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/predefined_types.jinja diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method13.ets b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/01.async_functions/return_type_is_promise/no_input_params/predefined_types/async_function_returns_promise_predefined0.ets similarity index 53% rename from static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method13.ets rename to static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/01.async_functions/return_type_is_promise/no_input_params/predefined_types/async_function_returns_promise_predefined0.ets index 04a715d4ce..639ebb7fd5 100644 --- a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method13.ets +++ b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/01.async_functions/return_type_is_promise/no_input_params/predefined_types/async_function_returns_promise_predefined0.ets @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,23 +13,7 @@ * limitations under the License. */ -/*--- -desc: Test cases for various usage scenarios of asynchronous method. - Asynchronous method returns null. ----*/ +{% from 'ets-templates/16.concurrency/03.asynchronous_api/predefined_types.jinja' import numeric_types_cases, boolean_types_cases, symbol_types_cases, no_value_types_cases %} +{% from 'ets-templates/16.concurrency/03.asynchronous_api/async_returns_predefined0.base.jinja' import generate_complete_test %} -class MethodReturnNull { - async methodReturnNull(): Promise { - return null; - } -} - -async function startTest() { - const example = new MethodReturnNull(); - const result = await example.methodReturnNull(); - arktest.assertEQ(result === null, true) -} - -function main(): void { - startTest(); -} \ No newline at end of file +{{ generate_complete_test(numeric_types_cases + boolean_types_cases + symbol_types_cases + no_value_types_cases, 'function') }} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method0.ets b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method0.ets deleted file mode 100644 index c3997cfd91..0000000000 --- a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method0.ets +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*--- -desc: Test cases for various usage scenarios of asynchronous method. - The asynchronous method returns a string. ----*/ - -class MethodReturnString { - async methodReturnString(): Promise { - return "Hello, World!"; - } -} - -function startTest() { - const example = new MethodReturnString(); - const result = await example.methodReturnString(); - arktest.assertEQ(result, "Hello, World!"); -} - -function main(): void { - startTest(); -} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method11.ets b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method11.ets deleted file mode 100644 index dcf299b5c8..0000000000 --- a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method11.ets +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*--- -desc: Test cases for various usage scenarios of asynchronous method. - Asynchronous methods return a promise.. ----*/ - -class MethodReturnNestedPromise { - async methodReturnString(): Promise { - return "Hello, World!"; - } - - async methodReturnNestedPromise(): Promise> { - return this.methodReturnString(); - } -} - -async function startTest() { - const example = new MethodReturnNestedPromise(); - const result = await example.methodReturnNestedPromise(); - arktest.assertEQ(result, "Hello, World!") -} - -function main(): void { - startTest(); -} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method12.ets b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method12.ets deleted file mode 100644 index bb58d7954c..0000000000 --- a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method12.ets +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*--- -desc: Test cases for various usage scenarios of asynchronous method. - Asynchronous method returns undefined. ----*/ - -class MethodReturnUndefined { - async methodReturnUndefined(): Promise { - return undefined; - } -} - -async function startTest() { - const example = new MethodReturnUndefined(); - const result = await example.methodReturnUndefined(); - arktest.assertEQ(result === undefined, true) -} - -function main(): void { - startTest(); -} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method14.ets b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method14.ets deleted file mode 100644 index 1cbb4ece9d..0000000000 --- a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method14.ets +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*--- -desc: Test cases for various usage scenarios of asynchronous method. - Asynchronous method returns boolean. ----*/ - -class MethodReturnBoolean { - async methodReturnBoolean(): Promise { - return true; - } -} - -async function startTest() { - const example = new MethodReturnBoolean(); - const result = await example.methodReturnBoolean(); - arktest.assertEQ(result === true, true) -} - -function main(): void { - startTest(); -} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method2.ets b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method2.ets deleted file mode 100644 index 21276bc69b..0000000000 --- a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method2.ets +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*--- -desc: Test cases for various usage scenarios of asynchronous method. - The asynchronous method returns a double. ----*/ - -class MethodReturnDouble { - async methodReturnDouble(): Promise { - return 10.0; - } -} - -function startTest() { - const example = new MethodReturnDouble(); - const result = await example.methodReturnDouble(); - arktest.assertEQ(result, 10.0); -} - -function main(): void { - startTest(); -} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method23.ets b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method23.ets deleted file mode 100644 index f28ee0bd26..0000000000 --- a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method23.ets +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*--- -desc: Test cases for various usage scenarios of asynchronous method. - Using loops in asynchronous methods. ----*/ - -class MethodWithLoop { - async methodWithLoop(): Promise { - let sum = 0.0; - for (let i = 1; i <= 5; i++) { - sum += i; - } - return sum; - } -} - -async function startTest() { - const example = new MethodWithLoop(); - const result = await example.methodWithLoop(); - arktest.assertEQ(result, 15); -} - -function main(): void { - startTest(); -} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method1.ets b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/return_type_is_promise/no_input_params/predefined_types/async_method_returns_promise_predefined0.ets similarity index 53% rename from static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method1.ets rename to static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/return_type_is_promise/no_input_params/predefined_types/async_method_returns_promise_predefined0.ets index 804d955519..60f2eeb6c7 100644 --- a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method1.ets +++ b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/return_type_is_promise/no_input_params/predefined_types/async_method_returns_promise_predefined0.ets @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,23 +13,7 @@ * limitations under the License. */ -/*--- -desc: Test cases for various usage scenarios of asynchronous method. - The asynchronous method returns a int. ----*/ +{% from 'ets-templates/16.concurrency/03.asynchronous_api/predefined_types.jinja' import numeric_types_cases, boolean_types_cases, symbol_types_cases, no_value_types_cases %} +{% from 'ets-templates/16.concurrency/03.asynchronous_api/async_returns_predefined0.base.jinja' import generate_complete_test %} -class MethodReturnInt { - async methodReturnInt(): Promise { - return 10; - } -} - -function startTest() { - const example = new MethodReturnInt(); - const result = await example.methodReturnInt(); - arktest.assertEQ(result, 10); -} - -function main(): void { - startTest(); -} \ No newline at end of file +{{ generate_complete_test(numeric_types_cases + boolean_types_cases + symbol_types_cases + no_value_types_cases, 'method') }} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/async_returns_predefined0.base.jinja b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/async_returns_predefined0.base.jinja new file mode 100644 index 0000000000..0932523b84 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/async_returns_predefined0.base.jinja @@ -0,0 +1,68 @@ +/** + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{% macro generate_complete_test(cases, declaration_type='function') %} +{% for c in cases %} +{% for type_name in [c.type, c.alias] | select %} + +/*--- +desc: The return type of an async function must be Promise<{{type_name}}>. +---*/ + +{% if declaration_type == 'function' %} +async function noParams(): Promise<{{type_name}}> { +{% elif declaration_type == 'lambda' %} +const noParams = async (): Promise<{{type_name}}> => { +{% elif declaration_type == 'method' %} +class AsyncMethodReturnClass { + async noParams(): Promise<{{type_name}}> { +{% endif %} + + {% if type_name in ['Byte', 'Short'] %} + const value: {{type_name}} = new {{type_name}}({{c.value}}) + {% else %} + const value: {{type_name}} = {{c.value}} + {% endif %} + return value + +} + +{% if declaration_type == 'method' %} +} {# Closing brace of class #} +{% endif %} + +function main(){ + + + {% if declaration_type == 'method' %} + let obj = new AsyncMethodReturnClass() + let result = obj.noParams() + {% else %} + let result = noParams() + {% endif %} + + arktest.assertTrue(result instanceof Promise) + let awaited_result = await result + arktest.assertTrue(awaited_result instanceof {{type_name}}) + {% if type_name in ['Byte', 'Short'] %} + arktest.assertTrue({{type_name}}.valueOf(awaited_result) === {{c.value}}) + {% else %} + arktest.assertTrue(awaited_result === {{c.value}}) + {% endif %} +} + +{% endfor %} +{% endfor %} +{% endmacro %} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/predefined_types.jinja b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/predefined_types.jinja new file mode 100644 index 0000000000..04e7bf6760 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/predefined_types.jinja @@ -0,0 +1,98 @@ +/** + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{% set numeric_types_cases = [ + {'type': 'int', 'alias': 'Int', 'value': '42'}, + {'type': 'number', 'alias': 'Number', 'value': '42.0'}, + {'type': 'byte', 'alias': 'Byte', 'value': '127'}, + {'type': 'short', 'alias': 'Short', 'value': '32767'}, + {'type': 'long', 'alias': 'Long', 'value': '9223372036854775807'}, + {'type': 'float', 'alias': 'Float', 'value': '3.14f'}, + {'type': 'double', 'alias': 'Double', 'value': '3.141592653589793'}, + {'type': 'bigint', 'alias': 'BigInt', 'value': '123456789012345678901234567890n'} +] %} + +{% set boolean_types_cases = [ + {'type': 'boolean', 'alias': 'Boolean', 'value': 'true'}, +] %} + +{% set symbol_types_cases = [ + {'type': 'string', 'alias': 'String', 'value': '"Hello, ArkTS!"'}, + {'type': 'char', 'alias': 'Char', 'value': "c'A'"}, +] %} + +{% set non_return_types_cases = [ + {'type': 'never', 'value': 'undefined'}, + {'type': 'void', 'value': 'undefined'} +] %} + +{% set no_value_types_cases = [ + {'type': 'undefined', 'value': 'undefined'}, + {'type': 'null', 'value': 'null'} +] %} + +{% set base_types_cases = [ + {'type': 'Any', 'value': '"Any value"'}, + {'type': 'Object', 'alias': 'object', 'value': 'new Object()'}, +]%} + +{% set resizable_array_types_cases = [ + {'type': 'int[]', 'value': '[1, 2, 3]'}, + {'type': 'number[]', 'value': '[1.0, 2.5, 3.7]'}, + {'type': 'string[]', 'value': '["Hello", "ArkTS", "World"]'}, + {'type': 'boolean[]', 'value': '[true, false, true]'}, + {'type': 'byte[]', 'value': '[127, -128, 0]'}, + {'type': 'short[]', 'value': '[32767, -32768, 0]'}, + {'type': 'long[]', 'value': '[9223372036854775807, 0]'}, + {'type': 'float[]', 'value': '[3.14f, -2.71f, 0.0f]'}, + {'type': 'double[]', 'value': '[3.141592653589793, 0.0]'}, + {'type': 'bigint[]', 'value': '[123456789012345678901234567890n]'}, + {'type': 'char[]', 'value': "[c'A', c'B', c'C']"}, + {'type': 'Any[]', 'value': '["mixed", 42, true]'}, + {'type': 'Object[]', 'value': '[new Object(), new Object()]'} +] %} + +{% set generic_array_types_cases = [ + {'type': 'Array', 'value': '[1, 2, 3]'}, + {'type': 'Array', 'value': '[1.0, 2.5, 3.7]'}, + {'type': 'Array', 'value': '["Hello", "ArkTS"]'}, + {'type': 'Array', 'value': '[true, false]'}, + {'type': 'Array', 'value': '["mixed", 42]'}, + {'type': 'Array', 'value': '[new Object(), new Object()]'} +] %} + +{% set fixed_array_types_cases = [ + {'type': 'FixedArray', 'value': '[1, 2, 3]'}, + {'type': 'FixedArray', 'value': '[1.0, 2.5, 3.7]'}, + {'type': 'FixedArray', 'value': '["Hello", "ArkTS"]'}, + {'type': 'FixedArray', 'value': '[true, false]'}, + {'type': 'FixedArray', 'value': '[127, -128]'}, + {'type': 'FixedArray', 'value': "[c'A', c'B']"} +] %} + +{% set multidimensional_array_types_cases = [ + {'type': 'int[][]', 'value': '[[1, 2], [3, 4]]'}, + {'type': 'string[][]', 'value': '[["Hello", "World"], ["ArkTS", "Test"]]'}, + {'type': 'Array>', 'value': '[[1, 2], [3, 4]]'}, + {'type': 'Array>', 'value': '[["Hello", "World"], ["ArkTS", "Test"]]'}, + {'type': 'FixedArray>', 'value': '[[1, 2], [3, 4]]'}, + {'type': 'FixedArray>', 'value': '[["A", "B"], ["C", "D"]]'} +] %} + +{% set empty_array_types_cases = [ + {'type': 'int[]', 'value': '[]'}, + {'type': 'Array', 'value': '[]'}, + {'type': 'FixedArray', 'value': '[]'} +] %} \ No newline at end of file diff --git a/static_core/tests/tests-u-runner/runner/plugins/ets/ets_templates/template.py b/static_core/tests/tests-u-runner/runner/plugins/ets/ets_templates/template.py index 9576a0583e..0cde48a097 100644 --- a/static_core/tests/tests-u-runner/runner/plugins/ets/ets_templates/template.py +++ b/static_core/tests/tests-u-runner/runner/plugins/ets/ets_templates/template.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -# Copyright (c) 2021-2024 Huawei Device Co., Ltd. +# Copyright (c) 2021-2025 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -21,7 +21,7 @@ from pathlib import Path from typing import Dict, Any, List, Tuple import yaml -from jinja2 import Environment, select_autoescape, TemplateSyntaxError +from jinja2 import Environment, select_autoescape, TemplateSyntaxError, FileSystemLoader from runner.plugins.ets.utils.constants import META_COPYRIGHT, META_START_STRING, \ META_END_STRING, META_START_COMMENT, META_END_COMMENT from runner.plugins.ets.utils.exceptions import \ @@ -29,6 +29,8 @@ from runner.plugins.ets.utils.exceptions import \ from runner.utils import read_file ROOT_PATH = Path(os.path.realpath(os.path.dirname(__file__))) +PROJECT_ROOT = ROOT_PATH.parent.parent.parent.parent.parent.parent.parent +ETS_TESTS_ROOT = PROJECT_ROOT / "static_core" / "plugins" / "ets" / "tests" BENCH_PATH = ROOT_PATH / "test_template.tpl" COPYRIGHT_PATH = ROOT_PATH / "copyright.txt" @@ -44,7 +46,10 @@ class Template: self.test_path = str(test_path) self.text = read_file(test_path) self.__params = params - self.__jinja_env = Environment(autoescape=select_autoescape()) + self.__jinja_env = Environment( + loader=FileSystemLoader([str(test_path.parent), str(ETS_TESTS_ROOT)]), + autoescape=select_autoescape() + ) if self.is_copyright: self.__copyright = read_file(COPYRIGHT_PATH) -- Gitee