From 5913f315ce254bdc118f46379791fa82f7068a3a Mon Sep 17 00:00:00 2001 From: Rene Date: Fri, 22 Dec 2023 23:17:31 +0100 Subject: [PATCH] added RF7 support Signed-off-by: Rene --- .../ConfigKeyword/custom_reader.robot | 4 +++- atest/TestCases/Defaults/CSV/defaults.robot | 2 +- .../TestCases/custom_reader/custom_reader.py | 3 +-- .../custom_reader/custom_reader.robot | 4 +++- .../custom_reader/custom_reader_local.robot | 4 +++- .../file_search_strategy_none.robot | 4 +++- .../custom_reader/with_path_and_file.robot | 4 +++- atest/run_atest.py | 9 ++++++++- pyproject.toml | 1 + setup.py | 10 +++++----- src/DataDriver/AbstractReaderClass.py | 1 - src/DataDriver/DataDriver.py | 20 +++++++++++++++---- src/DataDriver/ReaderConfig.py | 2 -- src/DataDriver/argument_utils.py | 6 +++--- src/DataDriver/search.py | 3 +-- 15 files changed, 51 insertions(+), 26 deletions(-) diff --git a/atest/TestCases/ConfigKeyword/custom_reader.robot b/atest/TestCases/ConfigKeyword/custom_reader.robot index 14ce035..d191299 100644 --- a/atest/TestCases/ConfigKeyword/custom_reader.robot +++ b/atest/TestCases/ConfigKeyword/custom_reader.robot @@ -13,7 +13,9 @@ test default 1 2 *** Keywords *** check vars [Arguments] ${var_1} ${var_2} - Should Be Equal ${var_1} ${var_2} + Should Be Equal As Integers ${var_1} ${var_2} + Should Be True ${{isinstance($var1, int)}} + Should Be True ${{isinstance($var2, str)}} Config Reader [Arguments] ${config} diff --git a/atest/TestCases/Defaults/CSV/defaults.robot b/atest/TestCases/Defaults/CSV/defaults.robot index 265139f..053e586 100644 --- a/atest/TestCases/Defaults/CSV/defaults.robot +++ b/atest/TestCases/Defaults/CSV/defaults.robot @@ -12,7 +12,7 @@ default ${var_1} ${var_2} a a defaults This is the *** Keywords *** Check Variables - [Arguments] ${var_1} ${var_2} ${var_name} ${var_doc} ${var_tags} + [Arguments] ${var_1} ${var_2} ${var_name}=None ${var_doc}=None ${var_tags}=None Verify Variable ${var_1} ${var_2} a Verify Variable ${TEST_DOCUMENTATION} ${var_doc} This is the Default Documentation Verify Variable ${TEST_NAME} ${var_name} defaults diff --git a/atest/TestCases/custom_reader/custom_reader.py b/atest/TestCases/custom_reader/custom_reader.py index 1da43e9..0b70233 100644 --- a/atest/TestCases/custom_reader/custom_reader.py +++ b/atest/TestCases/custom_reader/custom_reader.py @@ -22,13 +22,12 @@ class custom_reader(AbstractReaderClass): - # This method will be called from DataDriver to get the TestCaseData list. def get_data_from_source(self): test_data = [] for i in range(int(self.min), int(self.max)): # Dummy code to just generate some data args = { - "${var_1}": str(i), + "${var_1}": i, "${var_2}": str(i), } # args is a dictionary. Variable name is the key, value is value. test_data.append( diff --git a/atest/TestCases/custom_reader/custom_reader.robot b/atest/TestCases/custom_reader/custom_reader.robot index 03c6631..7d83201 100644 --- a/atest/TestCases/custom_reader/custom_reader.robot +++ b/atest/TestCases/custom_reader/custom_reader.robot @@ -11,4 +11,6 @@ test default 1 2 *** Keywords *** check vars [Arguments] ${var_1} ${var_2} - Should Be Equal ${var_1} ${var_2} \ No newline at end of file + Should Be Equal As Integers ${var_1} ${var_2} + Should Be True ${{isinstance($var1, int)}} + Should Be True ${{isinstance($var2, str)}} \ No newline at end of file diff --git a/atest/TestCases/custom_reader/custom_reader_local.robot b/atest/TestCases/custom_reader/custom_reader_local.robot index a2b24d5..0eabced 100644 --- a/atest/TestCases/custom_reader/custom_reader_local.robot +++ b/atest/TestCases/custom_reader/custom_reader_local.robot @@ -11,4 +11,6 @@ test default 1 2 *** Keywords *** check vars [Arguments] ${var_1} ${var_2} - Should Be Equal ${var_1} ${var_2} \ No newline at end of file + Should Be Equal As Integers ${var_1} ${var_2} + Should Be True ${{isinstance($var1, int)}} + Should Be True ${{isinstance($var2, str)}} \ No newline at end of file diff --git a/atest/TestCases/custom_reader/file_search_strategy_none.robot b/atest/TestCases/custom_reader/file_search_strategy_none.robot index 9304e1a..eaaf8e4 100644 --- a/atest/TestCases/custom_reader/file_search_strategy_none.robot +++ b/atest/TestCases/custom_reader/file_search_strategy_none.robot @@ -13,4 +13,6 @@ test default 1 2 *** Keywords *** check vars [Arguments] ${var_1} ${var_2} - Should Be Equal ${var_1} ${var_2} \ No newline at end of file + Should Be Equal As Integers ${var_1} ${var_2} + Should Be True ${{isinstance($var1, int)}} + Should Be True ${{isinstance($var2, str)}} \ No newline at end of file diff --git a/atest/TestCases/custom_reader/with_path_and_file.robot b/atest/TestCases/custom_reader/with_path_and_file.robot index eecb0ff..abef135 100644 --- a/atest/TestCases/custom_reader/with_path_and_file.robot +++ b/atest/TestCases/custom_reader/with_path_and_file.robot @@ -13,4 +13,6 @@ test default 1 2 *** Keywords *** check vars [Arguments] ${var_1} ${var_2} - Should Be Equal ${var_1} ${var_2} \ No newline at end of file + Should Be Equal As Integers ${var_1} ${var_2} + Should Be True ${{isinstance($var1, int)}} + Should Be True ${{isinstance($var2, str)}} \ No newline at end of file diff --git a/atest/run_atest.py b/atest/run_atest.py index 00e329d..27d5aa9 100644 --- a/atest/run_atest.py +++ b/atest/run_atest.py @@ -2,5 +2,12 @@ # robot -d logs --listener RobotStackTracer --exclude performanceORfailingORfiltered --loglevel TRACE:INFO --extension robot . -result = run(".", outputdir="logs", listener="RobotStackTracer", exclude="performanceORfailingORfiltered", loglevel="TRACE:INFO", extension="robot") +result = run( + ".", + outputdir="logs", + listener="RobotStackTracer", + exclude="performanceORfailingORfiltered", + loglevel="TRACE:INFO", + extension="robot", +) print(result) diff --git a/pyproject.toml b/pyproject.toml index 8494d1b..a9b6405 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,6 +26,7 @@ ignore = [ "N801", # Class name `xxx` should use CapWords convention "PLR0913", # Too many arguments to function call "N999", # Invalid module name: + "PTH207", # Replace `glob` with `Path.glob` or `Path.rglob` ] target-version = "py37" select = [ diff --git a/setup.py b/setup.py index 2a55627..6b32941 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,9 @@ with Path("Readme.rst").open(encoding="utf-8") as fh: long_description = fh.read() -with (Path(__file__).resolve().parent / "src" / "DataDriver" / "DataDriver.py").open(encoding="utf-8") as f: +with (Path(__file__).resolve().parent / "src" / "DataDriver" / "DataDriver.py").open( + encoding="utf-8" +) as f: VERSION = re.search('\n__version__ = "(.*)"', f.read()).group(1) setup( @@ -22,8 +24,6 @@ packages=find_packages("src"), classifiers=[ "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.6", - "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", @@ -34,7 +34,7 @@ "Topic :: Software Development :: Testing :: Acceptance", "Framework :: Robot Framework", ], - install_requires=["robotframework >= 4.0.2", "docutils", "Pygments"], + install_requires=["robotframework >= 4.0.2, < 8.0", "docutils", "Pygments"], extras_require={"xls": ["pandas", "xlrd >= 1.2.0", "openpyxl"]}, - python_requires=">=3.7.12", + python_requires=">=3.8.0", ) diff --git a/src/DataDriver/AbstractReaderClass.py b/src/DataDriver/AbstractReaderClass.py index af05949..e0c5d09 100644 --- a/src/DataDriver/AbstractReaderClass.py +++ b/src/DataDriver/AbstractReaderClass.py @@ -27,7 +27,6 @@ class AbstractReaderClass(ABC): def __init__(self, reader_config: ReaderConfig): - self.reader_config = reader_config self.file = reader_config.file self.csv_encoding = reader_config.encoding diff --git a/src/DataDriver/DataDriver.py b/src/DataDriver/DataDriver.py index 50dd05c..64865d9 100644 --- a/src/DataDriver/DataDriver.py +++ b/src/DataDriver/DataDriver.py @@ -24,6 +24,7 @@ from robot.libraries.BuiltIn import BuiltIn # type: ignore from robot.model.tags import Tags # type: ignore from robot.model.testsuite import TestSuite # type: ignore +from robot.running import ArgInfo # type: ignore from robot.running.model import TestCase # type: ignore from robot.utils.dotdict import DotDict # type: ignore from robot.utils.importer import Importer # type: ignore @@ -34,6 +35,7 @@ ReaderConfig, # type: ignore TestCaseData, # type: ignore ) +from .search import search_variable # type: ignore from .utils import ( # type: ignore Encodings, PabotOpt, @@ -49,7 +51,7 @@ warn, ) -__version__ = "1.9.0" +__version__ = "1.10.0" class DataDriver: @@ -1866,11 +1868,21 @@ def _replace_test_case_keywords(self): def _get_template_arguments(self): return_arguments = [] + unassigned_arguments = [] for arg in self.template_keyword.args: - if arg in self.test_case_data.arguments: - return_arguments.append(self.test_case_data.arguments[arg]) + if isinstance(arg, str): + variable_match = search_variable(arg) + arg_name = variable_match.name + elif isinstance(arg, ArgInfo): + arg_name = f"${{{arg.name}}}" else: - return_arguments.append(arg) + raise TypeError(f"Unknown argument type: {type(arg)} (DataDriver.py: 1869)") + if arg_name in self.test_case_data.arguments: + if unassigned_arguments: + raise ValueError(f"Unassigned argument(s) detected: {unassigned_arguments}.") + return_arguments.append(self.test_case_data.arguments[arg_name]) + else: + unassigned_arguments.append(arg_name) return return_arguments def _add_test_case_tags(self): diff --git a/src/DataDriver/ReaderConfig.py b/src/DataDriver/ReaderConfig.py index 7fcf4d5..63dfcef 100644 --- a/src/DataDriver/ReaderConfig.py +++ b/src/DataDriver/ReaderConfig.py @@ -21,7 +21,6 @@ class ReaderConfig: - TEST_CASE_TABLE_NAME = "*** Test Cases ***" def __init__( @@ -47,7 +46,6 @@ def __init__( optimize_pabot: PabotOpt = PabotOpt.Equal, **kwargs, ): - self.file = file self.encoding = encoding self.dialect = dialect diff --git a/src/DataDriver/argument_utils.py b/src/DataDriver/argument_utils.py index 53dc47a..243b55a 100644 --- a/src/DataDriver/argument_utils.py +++ b/src/DataDriver/argument_utils.py @@ -22,10 +22,10 @@ def robot_options(): ) cli_args = arg_parser.parse_args(filter_args(arg_parser))[0] try: - options = BuiltIn().get_variable_value(name='${options}') + options = BuiltIn().get_variable_value(name="${options}") if options is not None: - cli_args['include'] = options['include'] - cli_args['exclude'] = options['exclude'] + cli_args["include"] = options["include"] + cli_args["exclude"] = options["exclude"] except Exception: pass return cli_args diff --git a/src/DataDriver/search.py b/src/DataDriver/search.py index 372185d..f2ded18 100644 --- a/src/DataDriver/search.py +++ b/src/DataDriver/search.py @@ -198,8 +198,7 @@ def _validate_end_state(self, state): items = "".join("[%s]" % i for i in self.items) incomplete = "".join(self.item_chars) raise VariableError( - "Variable item '{}{}[{}' was not closed " - "properly.".format(variable, items, incomplete) + f"Variable item '{variable}{items}[{incomplete}' was not closed properly." )