parse parameters and generate cartesian product. Args: parameters (Dict) parameters: parameter name and value mapping parameter value may be in three types: (1) data list, e.g. ["iOS/10.1", "iOS/10.2", "iOS/10.3"] (2) call built-in parameteriz
(
parameters: Dict,
)
| 477 | |
| 478 | |
| 479 | def parse_parameters( |
| 480 | parameters: Dict, |
| 481 | ) -> List[Dict]: |
| 482 | """parse parameters and generate cartesian product. |
| 483 | |
| 484 | Args: |
| 485 | parameters (Dict) parameters: parameter name and value mapping |
| 486 | parameter value may be in three types: |
| 487 | (1) data list, e.g. ["iOS/10.1", "iOS/10.2", "iOS/10.3"] |
| 488 | (2) call built-in parameterize function, "${parameterize(account.csv)}" |
| 489 | (3) call custom function in debugtalk.py, "${gen_app_version()}" |
| 490 | |
| 491 | Returns: |
| 492 | list: cartesian product list |
| 493 | |
| 494 | Examples: |
| 495 | >>> parameters = { |
| 496 | "user_agent": ["iOS/10.1", "iOS/10.2", "iOS/10.3"], |
| 497 | "username-password": "${parameterize(account.csv)}", |
| 498 | "app_version": "${gen_app_version()}", |
| 499 | } |
| 500 | >>> parse_parameters(parameters) |
| 501 | |
| 502 | """ |
| 503 | parsed_parameters_list: List[List[Dict]] = [] |
| 504 | |
| 505 | # load project_meta functions |
| 506 | project_meta = loader.load_project_meta(os.getcwd()) |
| 507 | functions_mapping = project_meta.functions |
| 508 | |
| 509 | for parameter_name, parameter_content in parameters.items(): |
| 510 | parameter_name_list = parameter_name.split("-") |
| 511 | |
| 512 | if isinstance(parameter_content, List): |
| 513 | # (1) data list |
| 514 | # e.g. {"app_version": ["2.8.5", "2.8.6"]} |
| 515 | # => [{"app_version": "2.8.5", "app_version": "2.8.6"}] |
| 516 | # e.g. {"username-password": [["user1", "111111"], ["test2", "222222"]} |
| 517 | # => [{"username": "user1", "password": "111111"}, {"username": "user2", "password": "222222"}] |
| 518 | parameter_content_list: List[Dict] = [] |
| 519 | for parameter_item in parameter_content: |
| 520 | if not isinstance(parameter_item, (list, tuple)): |
| 521 | # "2.8.5" => ["2.8.5"] |
| 522 | parameter_item = [parameter_item] |
| 523 | |
| 524 | # ["app_version"], ["2.8.5"] => {"app_version": "2.8.5"} |
| 525 | # ["username", "password"], ["user1", "111111"] => {"username": "user1", "password": "111111"} |
| 526 | parameter_content_dict = dict(zip(parameter_name_list, parameter_item)) |
| 527 | parameter_content_list.append(parameter_content_dict) |
| 528 | |
| 529 | elif isinstance(parameter_content, Text): |
| 530 | # (2) & (3) |
| 531 | parsed_parameter_content: List = parse_data( |
| 532 | parameter_content, {}, functions_mapping |
| 533 | ) |
| 534 | if not isinstance(parsed_parameter_content, List): |
| 535 | raise exceptions.ParamsError( |
| 536 | f"parameters content should be in List type, got {parsed_parameter_content} for {parameter_content}" |
nothing calls this directly
no test coverage detected