From 84262f3055c3894644099845296cf57d8647f7db Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Mon, 20 Sep 2021 21:26:51 +0300 Subject: [PATCH 1/5] Python 3.10 type hint test --- .github/workflows/CI.yml | 2 +- atest/DynamicTypesLibrary.py | 4 ++-- atest/Python310Library.py | 14 ++++++++++++++ atest/run.py | 3 ++- atest/tests_types.robot | 14 ++++++++++++++ 5 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 atest/Python310Library.py diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index ef3d47b..18291e5 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.7, 3.9, 3.10.0-rc.1] + python-version: [3.7, 3.9, 3.10.0-rc.2] rf-version: [4.0.2, 4.1.1] steps: diff --git a/atest/DynamicTypesLibrary.py b/atest/DynamicTypesLibrary.py index 3626fe7..0d079ed 100644 --- a/atest/DynamicTypesLibrary.py +++ b/atest/DynamicTypesLibrary.py @@ -58,8 +58,8 @@ def keyword_none(self, arg=None): return '{}: {}'.format(arg, type(arg)) @keyword - def is_python_3(self): - return sys.version_info >= (3,) + def is_python_3_10(self): + return sys.version_info >= (3, 10) @keyword @def_deco diff --git a/atest/Python310Library.py b/atest/Python310Library.py new file mode 100644 index 0000000..d773b0b --- /dev/null +++ b/atest/Python310Library.py @@ -0,0 +1,14 @@ +from robot.api import logger + +from robotlibcore import DynamicCore, keyword + +class Python310Library(DynamicCore): + + def __init__(self): + DynamicCore.__init__(self, []) + + @keyword + def python310_style(self, arg: int | dict): + typing = f"arg: {arg}, type: {type(arg)}" + logger.info(typing) + return typing diff --git a/atest/run.py b/atest/run.py index c4e4e30..26df6b7 100755 --- a/atest/run.py +++ b/atest/run.py @@ -25,7 +25,8 @@ sys.exit(rc) process_output(output, verbose=False) output = join(outdir, 'lib-DynamicTypesLibrary-python-{}-robot-{}.xml'.format(python_version, rf_version)) -rc = run(tests_types, name='Types', output=output, report=None, log=None, loglevel='debug') +exclude = "py310" if sys.version_info < (3, 10) else "" +rc = run(tests_types, name='Types', output=output, report=None, log=None, loglevel='debug', exclude=exclude) if rc > 250: sys.exit(rc) process_output(output, verbose=False) diff --git a/atest/tests_types.robot b/atest/tests_types.robot index eee8e48..66874a0 100644 --- a/atest/tests_types.robot +++ b/atest/tests_types.robot @@ -91,3 +91,17 @@ Type Conversion With Union And Multiple Types ${types} = Keyword Union With None {"key": 1} Should Contain ${types} arg: {"key": 1}, Should Contain ${types} + +Python 3.10 New Type Hints + [Tags] py310 + [Setup] Import DynamicTypesAnnotationsLibrary In Python 3.10 Only + ${types} = Python310 Style 111 + Should Be Equal ${types} arg: 111, type: + ${types} = Python310 Style {"key": 1} + Should Be Equal ${types} arg: {'key': 1}, type: + +*** Keywords *** +Import DynamicTypesAnnotationsLibrary In Python 3.10 Only + ${py3} = DynamicTypesLibrary.Is Python 3 10 + Run Keyword If ${py3} + ... Import Library Python310Library.py From e67787bbd2682f2f08ffc1b27da1133f2d09586c Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Mon, 20 Sep 2021 21:32:50 +0300 Subject: [PATCH 2/5] RF 4.0.1 fix --- atest/DynamicTypesLibrary.py | 6 ++++++ atest/tests_types.robot | 11 +++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/atest/DynamicTypesLibrary.py b/atest/DynamicTypesLibrary.py index 0d079ed..1ea9e8c 100644 --- a/atest/DynamicTypesLibrary.py +++ b/atest/DynamicTypesLibrary.py @@ -1,6 +1,8 @@ import functools import sys +from robot import version as rf_version + from robotlibcore import DynamicCore, keyword @@ -61,6 +63,10 @@ def keyword_none(self, arg=None): def is_python_3_10(self): return sys.version_info >= (3, 10) + @keyword + def is_rf_401(self): + return "4.0." in rf_version.VERSION + @keyword @def_deco def keyword_with_def_deco(self): diff --git a/atest/tests_types.robot b/atest/tests_types.robot index 66874a0..0ccb842 100644 --- a/atest/tests_types.robot +++ b/atest/tests_types.robot @@ -96,6 +96,12 @@ Python 3.10 New Type Hints [Tags] py310 [Setup] Import DynamicTypesAnnotationsLibrary In Python 3.10 Only ${types} = Python310 Style 111 + ${rf401} = DynamicTypesLibrary.Is Rf 401 + IF ${rf401} != ${True} + Should Be Equal ${types} arg: 111, type: + ELSE + Should Be Equal ${types} arg: 111, type: + END Should Be Equal ${types} arg: 111, type: ${types} = Python310 Style {"key": 1} Should Be Equal ${types} arg: {'key': 1}, type: @@ -103,5 +109,6 @@ Python 3.10 New Type Hints *** Keywords *** Import DynamicTypesAnnotationsLibrary In Python 3.10 Only ${py3} = DynamicTypesLibrary.Is Python 3 10 - Run Keyword If ${py3} - ... Import Library Python310Library.py + IF ${py3} + Import Library Python310Library.py + END From 65c074be444fed24795b33227af47df79e3698b3 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Mon, 20 Sep 2021 21:44:35 +0300 Subject: [PATCH 3/5] Fix unit test --- atest/DynamicTypesLibrary.py | 8 ++++---- utest/test_get_keyword_source.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/atest/DynamicTypesLibrary.py b/atest/DynamicTypesLibrary.py index 1ea9e8c..b196fbd 100644 --- a/atest/DynamicTypesLibrary.py +++ b/atest/DynamicTypesLibrary.py @@ -63,10 +63,6 @@ def keyword_none(self, arg=None): def is_python_3_10(self): return sys.version_info >= (3, 10) - @keyword - def is_rf_401(self): - return "4.0." in rf_version.VERSION - @keyword @def_deco def keyword_with_def_deco(self): @@ -85,3 +81,7 @@ def varargs_and_kwargs(self, *args, **kwargs): @keyword def keyword_booleans(self, arg1=True, arg2=False): return '{}: {}, {}: {}'.format(arg1, type(arg1), arg2, type(arg2)) + + @keyword + def is_rf_401(self): + return "4.0." in rf_version.VERSION \ No newline at end of file diff --git a/utest/test_get_keyword_source.py b/utest/test_get_keyword_source.py index 95d65a0..212e19d 100644 --- a/utest/test_get_keyword_source.py +++ b/utest/test_get_keyword_source.py @@ -50,7 +50,7 @@ def test_location_in_class(lib, lib_path_components): def test_decorator_wrapper(lib_types, lib_path_types): source = lib_types.get_keyword_source('keyword_wrapped') - assert source == '%s:72' % lib_path_types + assert source == '%s:74' % lib_path_types def test_location_in_class_custom_keyword_name(lib, lib_path_components): @@ -79,7 +79,7 @@ def test_no_path_and_no_line_number(lib, when): def test_def_in_decorator(lib_types, lib_path_types): source = lib_types.get_keyword_source('keyword_with_def_deco') - assert source == '%s:66' % lib_path_types + assert source == '%s:68' % lib_path_types def test_error_in_getfile(lib, when): From b82babf9ee5c732dd962f4a93b30755198088858 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Mon, 20 Sep 2021 21:47:52 +0300 Subject: [PATCH 4/5] Always upload artifacts --- .github/workflows/CI.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 18291e5..b5e4f9a 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -37,6 +37,7 @@ jobs: run: | python atest/run.py - uses: actions/upload-artifact@v1 + if: ${{ always() }} with: name: atest_results path: atest/results From 15a7084abf2dd16aafb0e0dd9d03eaa38012a268 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Mon, 20 Sep 2021 21:49:37 +0300 Subject: [PATCH 5/5] Fix atest --- atest/tests_types.robot | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/atest/tests_types.robot b/atest/tests_types.robot index 0ccb842..ab9af7d 100644 --- a/atest/tests_types.robot +++ b/atest/tests_types.robot @@ -102,9 +102,12 @@ Python 3.10 New Type Hints ELSE Should Be Equal ${types} arg: 111, type: END - Should Be Equal ${types} arg: 111, type: ${types} = Python310 Style {"key": 1} - Should Be Equal ${types} arg: {'key': 1}, type: + IF ${rf401} != ${True} + Should Be Equal ${types} arg: {'key': 1}, type: + ELSE + Should Be Equal ${types} arg: {"key": 1}, type: + END *** Keywords *** Import DynamicTypesAnnotationsLibrary In Python 3.10 Only