diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7fcc8f2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.pyc +.idea/ \ No newline at end of file diff --git a/README.md b/README.md index fc6078b..1052899 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -# mw_robot_toolkit -Useful support for robot programs +# mw_robot_toolkit +Useful support for robot programs diff --git a/lib/gen_robot_keyword.py b/lib/gen_robot_keyword.py new file mode 100644 index 0000000..1bac73d --- /dev/null +++ b/lib/gen_robot_keyword.py @@ -0,0 +1,91 @@ +#!/usr/bin/env python + +r""" +This module provides robot keyword execution functions such as run_key.. +""" + +import gen_print as gp +from robot.libraries.BuiltIn import BuiltIn + + +def run_key(keyword_buf, + quiet=None, + test_mode=None, + ignore=0): + r""" + Run the given keyword, return the status and the keyword return values. + + The advantage of using this function verses having robot simply run your keyword is the handling of + parameters like quiet, test_mode and ignore. + + Description of arguments: + keyword_buf The keyword string to be run. + quiet Indicates whether this function should run the pissuing function to print + 'Issuing: ' to stdout. + test_mode If test_mode is set, this function will not actually run the command. If + quiet is 0, it will print a message indicating what it would have run + (e.g. "Issuing: (test_mode) your command"). + ignore Ignore errors from running keyword. If this is 0, this function will + fail with whatever error occurred when running the keyword. + + Example usage from a robot script: + + ${status} ${ret_values}= Run Key My Keyword \ Arg1 \ Arg2 + + Note that to get robot to pass your command + args as a single string to this function, you must escape + extra spaces with a backslash. + + Also note that ret_values is a python list: + ret_values: + ret_values[0]: value1 + ret_values[1]: value2 + """ + + # Set these vars to default values if they are None. + quiet = int(gp.get_var_value(quiet, 0)) + test_mode = int(gp.get_var_value(test_mode, 0)) + ignore = int(ignore) + + # Convert the keyword_buf into a list split wherever 2 or more spaces are found. + keyword_list = keyword_buf.split(' ') + # Strip spaces from each argument to make the output look clean and uniform. + keyword_list = [item.strip(' ') for item in keyword_list] + + if not quiet: + # Join the list back into keyword_buf for the sake of output. + keyword_buf = ' '.join(keyword_list) + gp.pissuing(keyword_buf, test_mode) + + if test_mode: + return 'PASS', "" + + try: + status, ret_values = \ + BuiltIn().run_keyword_and_ignore_error(*keyword_list) + except Exception as my_assertion_error: + status = "FAIL" + ret_values = my_assertion_error.args[0] + + if status != 'PASS': + # Output the error message to stderr. + BuiltIn().log_to_console(ret_values, stream='STDERR') + if not ignore: + # Fail with the given error message. + BuiltIn().fail(ret_values) + + return status, ret_values + + +def run_key_u(keyword_buf, + quiet=None, + ignore=0): + r""" + Run keyword unconditionally (i.e. without regard to global test_mode setting). + + This function will simply call the run_key function passing on all of the callers parameters except + test_mode which will be hard-coded to 0. See run_key (above) for details. + + See the proglog of "run_key" function above for description of arguments. + """ + + return run_key(keyword_buf, test_mode=0, quiet=quiet, ignore=ignore) diff --git a/lib/gen_robot_print.py b/lib/gen_robot_print.py index 7dd1384..37149fa 100755 --- a/lib/gen_robot_print.py +++ b/lib/gen_robot_print.py @@ -1,143 +1,143 @@ -#!/usr/bin/env python - -r""" -This file contains functions useful for printing to stdout from robot programs. -""" - -import re -import os - -import gen_print as gp -import func_args as fa - -from robot.libraries.BuiltIn import BuiltIn - -gen_robot_print_debug = int(os.environ.get('GEN_ROBOT_PRINT_DEBUG', '0')) - - -def sprint_vars(*args, **kwargs): - r""" - Sprint the values of one or more variables to the console. - - This is a robot re-definition of the sprint_vars function in gen_print.py. Given a list of variable - names, this keyword will string print each variable name and value such that each value lines up in the - same column as messages printed with sprint_time(). - - Description of argument(s): - args The names of the variables to be printed (e.g. var1 rather than ${var1}). - kwargs See sprint_varx in gen_print.py for descriptions of all other arguments. - """ - - if 'fmt' in kwargs: - # Find format option names in kwargs['fmt'] and wrap them with "gp." and "()" to make them into - # function calls. For example, verbose would be converted to "gp.verbose()". This allows the user - # to simply specify "fmt=verbose" (vs. fmt=gp.verbose()). - # Note "terse" has been explicitly added for backward compatibility. Once the repo has been purged - # of its use, this code can return to its original form. - regex = "(" + "|".join(gp.valid_fmts()) + "|terse)" - kwargs['fmt'] = \ - re.sub(regex, "gp.\\1()", kwargs['fmt']) - kwargs = fa.args_to_objects(kwargs) - buffer = "" - for var_name in args: - var_value = BuiltIn().get_variable_value("${" + str(var_name) + "}") - buffer += gp.sprint_varx(var_name, var_value, **kwargs) - - return buffer - - -def sprint_auto_vars(headers=0): - r""" - String print all of the Automatic Variables described in the Robot User's Guide using sprint_vars. - - NOTE: Not all automatic variables are guaranteed to exist. - - Description of argument(s): - headers This indicates that a header and footer should be printed. - """ - - buffer = "" - if int(headers) == 1: - buffer += gp.sprint_dashes() - buffer += "Automatic Variables:" - - buffer += \ - sprint_vars( - "TEST_NAME", "TEST_TAGS", "TEST_DOCUMENTATION", "TEST_STATUS", - "TEST_DOCUMENTATION", "TEST_STATUS", "TEST_MESSAGE", - "PREV_TEST_NAME", "PREV_TEST_STATUS", "PREV_TEST_MESSAGE", - "SUITE_NAME", "SUITE_SOURCE", "SUITE_DOCUMENTATION", - "SUITE_METADATA", "SUITE_STATUS", "SUITE_MESSAGE", - "KEYWORD_STATUS", "KEYWORD_MESSAGE", "LOG_LEVEL", "OUTPUT_FILE", - "LOG_FILE", "REPORT_FILE", "DEBUG_FILE", "OUTPUT_DIR") - - if int(headers) == 1: - buffer += gp.sprint_dashes() - - return buffer - - -def gp_debug_print(buffer): - r""" - Print the buffer value only if gen_robot_print_debug is set. - - This function is intended for use only by other functions in this module. - - Description of argument(s): - buffer The string to be printed. - """ - - if not gen_robot_print_debug: - return - gp.gp_print(buffer) - - -# In the following section of code, we will dynamically create print versions for several of the sprint -# functions defined above. For example, where we have an sprint_vars() function defined above that returns -# formatted variable print outs in a string, we will create a corresponding rprint_vars() function that will -# print that string directly to stdout. - -# It can be complicated to follow what's being created below. Here is an example of the rprint_vars() -# function that will be created: - -# def rprint_vars(*args, **kwargs): -# gp.gp_print(gp.replace_passwords(sprint_vars(*args, **kwargs)), stream='stdout') - -# For sprint_vars (defined above), the following functions will be created: - -# rprint_vars Robot Print Vars -# rqprint_vars Robot Print Vars if ${quiet} is set to ${0}. -# rdprint_vars Robot Print Vars if ${debug} is set to ${1}. -# rlprint_vars Robot Print Vars to the log instead of to the console. - -# Abbreviated names are created for all of the preceding function names: -# rpvars -# rqpvars -# rdpvars -# rlpvars - -# Users are encouraged to only use the abbreviated forms for development but to then ultimately switch to -# full names. -# Rprint Vars (instead of Rpvars) - -replace_dict = {'output_stream': 'stdout', 'mod_qualifier': 'gp.'} - -gp_debug_print("gp.robot_env: " + str(gp.robot_env) + "\n") - -# func_names contains a list of all rprint functions which should be created from their sprint counterparts. -func_names = [ - 'print_vars', 'print_auto_vars' -] - -# stderr_func_names is a list of functions whose output should go to stderr rather than stdout. -stderr_func_names = [] - -func_defs = gp.create_print_wrapper_funcs(func_names, stderr_func_names, - replace_dict, "r") -gp_debug_print(func_defs) -exec(func_defs) - -# Define an alias. rpvar is just a special case of rpvars where the args list contains only one element. -cmd_buf = "rpvar = rpvars" -gp_debug_print("\n" + cmd_buf + "\n") -exec(cmd_buf) +#!/usr/bin/env python + +r""" +This file contains functions useful for printing to stdout from robot programs. +""" + +import re +import os + +import gen_print as gp +import func_args as fa + +from robot.libraries.BuiltIn import BuiltIn + +gen_robot_print_debug = int(os.environ.get('GEN_ROBOT_PRINT_DEBUG', '0')) + + +def sprint_vars(*args, **kwargs): + r""" + Sprint the values of one or more variables to the console. + + This is a robot re-definition of the sprint_vars function in gen_print.py. Given a list of variable + names, this keyword will string print each variable name and value such that each value lines up in the + same column as messages printed with sprint_time(). + + Description of argument(s): + args The names of the variables to be printed (e.g. var1 rather than ${var1}). + kwargs See sprint_varx in gen_print.py for descriptions of all other arguments. + """ + + if 'fmt' in kwargs: + # Find format option names in kwargs['fmt'] and wrap them with "gp." and "()" to make them into + # function calls. For example, verbose would be converted to "gp.verbose()". This allows the user + # to simply specify "fmt=verbose" (vs. fmt=gp.verbose()). + # Note "terse" has been explicitly added for backward compatibility. Once the repo has been purged + # of its use, this code can return to its original form. + regex = "(" + "|".join(gp.valid_fmts()) + "|terse)" + kwargs['fmt'] = \ + re.sub(regex, "gp.\\1()", kwargs['fmt']) + kwargs = fa.args_to_objects(kwargs) + buffer = "" + for var_name in args: + var_value = BuiltIn().get_variable_value("${" + str(var_name) + "}") + buffer += gp.sprint_varx(var_name, var_value, **kwargs) + + return buffer + + +def sprint_auto_vars(headers=0): + r""" + String print all of the Automatic Variables described in the Robot User's Guide using sprint_vars. + + NOTE: Not all automatic variables are guaranteed to exist. + + Description of argument(s): + headers This indicates that a header and footer should be printed. + """ + + buffer = "" + if int(headers) == 1: + buffer += gp.sprint_dashes() + buffer += "Automatic Variables:" + + buffer += \ + sprint_vars( + "TEST_NAME", "TEST_TAGS", "TEST_DOCUMENTATION", "TEST_STATUS", + "TEST_DOCUMENTATION", "TEST_STATUS", "TEST_MESSAGE", + "PREV_TEST_NAME", "PREV_TEST_STATUS", "PREV_TEST_MESSAGE", + "SUITE_NAME", "SUITE_SOURCE", "SUITE_DOCUMENTATION", + "SUITE_METADATA", "SUITE_STATUS", "SUITE_MESSAGE", + "KEYWORD_STATUS", "KEYWORD_MESSAGE", "LOG_LEVEL", "OUTPUT_FILE", + "LOG_FILE", "REPORT_FILE", "DEBUG_FILE", "OUTPUT_DIR") + + if int(headers) == 1: + buffer += gp.sprint_dashes() + + return buffer + + +def gp_debug_print(buffer): + r""" + Print the buffer value only if gen_robot_print_debug is set. + + This function is intended for use only by other functions in this module. + + Description of argument(s): + buffer The string to be printed. + """ + + if not gen_robot_print_debug: + return + gp.gp_print(buffer) + + +# In the following section of code, we will dynamically create print versions for several of the sprint +# functions defined above. For example, where we have an sprint_vars() function defined above that returns +# formatted variable print outs in a string, we will create a corresponding rprint_vars() function that will +# print that string directly to stdout. + +# It can be complicated to follow what's being created below. Here is an example of the rprint_vars() +# function that will be created: + +# def rprint_vars(*args, **kwargs): +# gp.gp_print(gp.replace_passwords(sprint_vars(*args, **kwargs)), stream='stdout') + +# For sprint_vars (defined above), the following functions will be created: + +# rprint_vars Robot Print Vars +# rqprint_vars Robot Print Vars if ${quiet} is set to ${0}. +# rdprint_vars Robot Print Vars if ${debug} is set to ${1}. +# rlprint_vars Robot Print Vars to the log instead of to the console. + +# Abbreviated names are created for all of the preceding function names: +# rpvars +# rqpvars +# rdpvars +# rlpvars + +# Users are encouraged to only use the abbreviated forms for development but to then ultimately switch to +# full names. +# Rprint Vars (instead of Rpvars) + +replace_dict = {'output_stream': 'stdout', 'mod_qualifier': 'gp.'} + +gp_debug_print("gp.robot_env: " + str(gp.robot_env) + "\n") + +# func_names contains a list of all rprint functions which should be created from their sprint counterparts. +func_names = [ + 'print_vars', 'print_auto_vars' +] + +# stderr_func_names is a list of functions whose output should go to stderr rather than stdout. +stderr_func_names = [] + +func_defs = gp.create_print_wrapper_funcs(func_names, stderr_func_names, + replace_dict, "r") +gp_debug_print(func_defs) +exec(func_defs) + +# Define an alias. rpvar is just a special case of rpvars where the args list contains only one element. +cmd_buf = "rpvar = rpvars" +gp_debug_print("\n" + cmd_buf + "\n") +exec(cmd_buf) diff --git a/lib/gen_robot_valid.py b/lib/gen_robot_valid.py index df8038c..3eb2694 100755 --- a/lib/gen_robot_valid.py +++ b/lib/gen_robot_valid.py @@ -1,240 +1,240 @@ -#!/usr/bin/env python - -r""" -This module provides validation functions like valid_value(), valid_integer(), etc. for robot programs. -""" - -import re -import gen_print as gp -import gen_valid as gv -import func_args as fa - -from robot.libraries.BuiltIn import BuiltIn - - -def valid_var_name(var_name): - r""" - Validate the robot variable name and return its value. - - If the variable is undefined, this function will print an error message and call BuiltIn().fail(). - - Description of arguments(): - var_name The name of the robot variable (e.g. "var1"). Do not include "${}" (e.g. - "${var1}". Just provide the simple name of the variable. - """ - - # Note: get_variable_value() seems to have no trouble with local variables. - var_value = BuiltIn().get_variable_value("${" + var_name + "}") - if var_value is None: - var_value = "" - error_message = gv.valid_value(var_value, invalid_values=[var_value], - var_name=var_name) - BuiltIn().fail(error_message) - - return var_value - - -def valid_init(var_name, *args, **kwargs): - r""" - Do initialization for variable validation and return var_name, args and kwargs. - - This function is to be called by all of the various validation functions in this module. - - This function is designed solely for use by other functions in this file. - - Description of argument(s): - var_name The name of the variable to be validated. - args The positional arguments to be passed to a validation function. - kwargs The keyword arguments to be passed to a validation function. - """ - - var_value = valid_var_name(var_name) - # Convert python string object definitions to objects (useful for robot callers). - args = fa.args_to_objects(args) - kwargs = fa.args_to_objects(kwargs) - return var_value, args, kwargs - - -def process_error_message(error_message): - r""" - Process an error message. - - If error_message is non-blank, fail. Otherwise, do nothing. - - This function is designed solely for use by other functions in this file. - - Description of argument(s): - error_message The error message to be processed. - """ - - if error_message: - error_message = gp.sprint_error_report(error_message) - BuiltIn().fail(error_message) - - -# The docstring header will be pre-pended to each validation function's existing docstring. -docstring_header = \ - r""" - Fail if the variable named by var_name is invalid. - """ - - -def customize_doc_string(doc_string): - r""" - Customize a gen_valid function docstring and return the result. - - This function is designed solely for use by other functions in this file. - - The caller should pass a docstring from a gen_valid.py validation function. This docstring will be - changed to make a suitable docstring for this module's corresponding validation function. - - For example: - - Let's suppose that gen_valid.py has a function called "valid_value()". This module could make the - following call to essentially copy gen_valid's "valid_value()" function, modify it and then assign it to - the local version of the valid_value() function. - - valid.__doc__ = customize_doc_string(gv.valid.__doc__) - - Description of argument(s): - doc_string The docstring to be customized. - """ - - doc_string = docstring_header + doc_string - doc_string = doc_string.split("\n") - - start_ix = 0 - # Find the "var_value" line. - start_ix = next((index for index, value in - enumerate(doc_string[start_ix:], start_ix) - if re.match("[ ]+var_value ", value)), None) - # Replace the "var_value" line with our "var_name" line. - doc_string[start_ix] = " var_name " \ - + "The name of the variable to be validated." - - return "\n".join(doc_string) - - -# All of the following functions are robot wrappers for the equivalent functions defined in gen_valid.py. -# Note that the only difference between any two of these locally defined functions is the function name and -# the gv. which they call. Also, note that the docstring for each is created by modifying the -# docstring from the supporting gen_valid.py function. - -def valid_type(var_name, *args, **kwargs): - - var_value, args, kwargs = valid_init(var_name, *args, **kwargs) - error_message = \ - gv.valid_type(var_value, *args, var_name=var_name, **kwargs) - process_error_message(error_message) - - -def valid_value(var_name, *args, **kwargs): - - var_value, args, kwargs = valid_init(var_name, *args, **kwargs) - error_message = \ - gv.valid_value(var_value, *args, var_name=var_name, **kwargs) - process_error_message(error_message) - - -def valid_range(var_name, *args, **kwargs): - - var_value, args, kwargs = valid_init(var_name, *args, **kwargs) - error_message = \ - gv.valid_range(var_value, *args, var_name=var_name, **kwargs) - process_error_message(error_message) - - -def valid_integer(var_name, *args, **kwargs): - - var_value, args, kwargs = valid_init(var_name, *args, **kwargs) - error_message = \ - gv.valid_integer(var_value, *args, var_name=var_name, **kwargs) - process_error_message(error_message) - - -def valid_float(var_name, *args, **kwargs): - - var_value, args, kwargs = valid_init(var_name, *args, **kwargs) - error_message = \ - gv.valid_float(var_value, *args, var_name=var_name, **kwargs) - process_error_message(error_message) - - -def valid_date_time(var_name, *args, **kwargs): - - var_value, args, kwargs = valid_init(var_name, *args, **kwargs) - error_message = \ - gv.valid_date_time(var_value, *args, var_name=var_name, **kwargs) - process_error_message(error_message) - - -def valid_dir_path(var_name, *args, **kwargs): - - var_value, args, kwargs = valid_init(var_name, *args, **kwargs) - error_message = \ - gv.valid_dir_path(var_value, *args, var_name=var_name, **kwargs) - process_error_message(error_message) - - -def valid_file_path(var_name, *args, **kwargs): - - var_value, args, kwargs = valid_init(var_name, *args, **kwargs) - error_message = \ - gv.valid_file_path(var_value, *args, var_name=var_name, **kwargs) - process_error_message(error_message) - - -def valid_path(var_name, *args, **kwargs): - - var_value, args, kwargs = valid_init(var_name, *args, **kwargs) - error_message = \ - gv.valid_path(var_value, *args, var_name=var_name, **kwargs) - process_error_message(error_message) - - -def valid_list(var_name, *args, **kwargs): - - var_value, args, kwargs = valid_init(var_name, *args, **kwargs) - error_message = \ - gv.valid_list(var_value, *args, var_name=var_name, **kwargs) - process_error_message(error_message) - - -def valid_dict(var_name, *args, **kwargs): - - var_value, args, kwargs = valid_init(var_name, *args, **kwargs) - error_message = \ - gv.valid_dict(var_value, *args, var_name=var_name, **kwargs) - process_error_message(error_message) - - -def valid_program(var_name, *args, **kwargs): - - var_value, args, kwargs = valid_init(var_name, *args, **kwargs) - error_message = \ - gv.valid_program(var_value, *args, var_name=var_name, **kwargs) - process_error_message(error_message) - - -def valid_length(var_name, *args, **kwargs): - - var_value, args, kwargs = valid_init(var_name, *args, **kwargs) - error_message = \ - gv.valid_length(var_value, *args, var_name=var_name, **kwargs) - process_error_message(error_message) - - -# Modify the validation function docstrings by calling customize_doc_string for each function in the -# func_names list. -func_names = [ - "valid_type", "valid_value", "valid_range", "valid_integer", - "valid_dir_path", "valid_file_path", "valid_path", "valid_list", - "valid_dict", "valid_program", "valid_length", "valid_float", - "valid_date_time" -] - -for func_name in func_names: - cmd_buf = func_name \ - + ".__doc__ = customize_doc_string(gv.raw_doc_strings['" \ - + func_name + "'])" - exec(cmd_buf) +#!/usr/bin/env python + +r""" +This module provides validation functions like valid_value(), valid_integer(), etc. for robot programs. +""" + +import re +import gen_print as gp +import gen_valid as gv +import func_args as fa + +from robot.libraries.BuiltIn import BuiltIn + + +def valid_var_name(var_name): + r""" + Validate the robot variable name and return its value. + + If the variable is undefined, this function will print an error message and call BuiltIn().fail(). + + Description of arguments(): + var_name The name of the robot variable (e.g. "var1"). Do not include "${}" (e.g. + "${var1}". Just provide the simple name of the variable. + """ + + # Note: get_variable_value() seems to have no trouble with local variables. + var_value = BuiltIn().get_variable_value("${" + var_name + "}") + if var_value is None: + var_value = "" + error_message = gv.valid_value(var_value, invalid_values=[var_value], + var_name=var_name) + BuiltIn().fail(error_message) + + return var_value + + +def valid_init(var_name, *args, **kwargs): + r""" + Do initialization for variable validation and return var_name, args and kwargs. + + This function is to be called by all of the various validation functions in this module. + + This function is designed solely for use by other functions in this file. + + Description of argument(s): + var_name The name of the variable to be validated. + args The positional arguments to be passed to a validation function. + kwargs The keyword arguments to be passed to a validation function. + """ + + var_value = valid_var_name(var_name) + # Convert python string object definitions to objects (useful for robot callers). + args = fa.args_to_objects(args) + kwargs = fa.args_to_objects(kwargs) + return var_value, args, kwargs + + +def process_error_message(error_message): + r""" + Process an error message. + + If error_message is non-blank, fail. Otherwise, do nothing. + + This function is designed solely for use by other functions in this file. + + Description of argument(s): + error_message The error message to be processed. + """ + + if error_message: + error_message = gp.sprint_error_report(error_message) + BuiltIn().fail(error_message) + + +# The docstring header will be pre-pended to each validation function's existing docstring. +docstring_header = \ + r""" + Fail if the variable named by var_name is invalid. + """ + + +def customize_doc_string(doc_string): + r""" + Customize a gen_valid function docstring and return the result. + + This function is designed solely for use by other functions in this file. + + The caller should pass a docstring from a gen_valid.py validation function. This docstring will be + changed to make a suitable docstring for this module's corresponding validation function. + + For example: + + Let's suppose that gen_valid.py has a function called "valid_value()". This module could make the + following call to essentially copy gen_valid's "valid_value()" function, modify it and then assign it to + the local version of the valid_value() function. + + valid.__doc__ = customize_doc_string(gv.valid.__doc__) + + Description of argument(s): + doc_string The docstring to be customized. + """ + + doc_string = docstring_header + doc_string + doc_string = doc_string.split("\n") + + start_ix = 0 + # Find the "var_value" line. + start_ix = next((index for index, value in + enumerate(doc_string[start_ix:], start_ix) + if re.match("[ ]+var_value ", value)), None) + # Replace the "var_value" line with our "var_name" line. + doc_string[start_ix] = " var_name " \ + + "The name of the variable to be validated." + + return "\n".join(doc_string) + + +# All of the following functions are robot wrappers for the equivalent functions defined in gen_valid.py. +# Note that the only difference between any two of these locally defined functions is the function name and +# the gv. which they call. Also, note that the docstring for each is created by modifying the +# docstring from the supporting gen_valid.py function. + +def valid_type(var_name, *args, **kwargs): + + var_value, args, kwargs = valid_init(var_name, *args, **kwargs) + error_message = \ + gv.valid_type(var_value, *args, var_name=var_name, **kwargs) + process_error_message(error_message) + + +def valid_value(var_name, *args, **kwargs): + + var_value, args, kwargs = valid_init(var_name, *args, **kwargs) + error_message = \ + gv.valid_value(var_value, *args, var_name=var_name, **kwargs) + process_error_message(error_message) + + +def valid_range(var_name, *args, **kwargs): + + var_value, args, kwargs = valid_init(var_name, *args, **kwargs) + error_message = \ + gv.valid_range(var_value, *args, var_name=var_name, **kwargs) + process_error_message(error_message) + + +def valid_integer(var_name, *args, **kwargs): + + var_value, args, kwargs = valid_init(var_name, *args, **kwargs) + error_message = \ + gv.valid_integer(var_value, *args, var_name=var_name, **kwargs) + process_error_message(error_message) + + +def valid_float(var_name, *args, **kwargs): + + var_value, args, kwargs = valid_init(var_name, *args, **kwargs) + error_message = \ + gv.valid_float(var_value, *args, var_name=var_name, **kwargs) + process_error_message(error_message) + + +def valid_date_time(var_name, *args, **kwargs): + + var_value, args, kwargs = valid_init(var_name, *args, **kwargs) + error_message = \ + gv.valid_date_time(var_value, *args, var_name=var_name, **kwargs) + process_error_message(error_message) + + +def valid_dir_path(var_name, *args, **kwargs): + + var_value, args, kwargs = valid_init(var_name, *args, **kwargs) + error_message = \ + gv.valid_dir_path(var_value, *args, var_name=var_name, **kwargs) + process_error_message(error_message) + + +def valid_file_path(var_name, *args, **kwargs): + + var_value, args, kwargs = valid_init(var_name, *args, **kwargs) + error_message = \ + gv.valid_file_path(var_value, *args, var_name=var_name, **kwargs) + process_error_message(error_message) + + +def valid_path(var_name, *args, **kwargs): + + var_value, args, kwargs = valid_init(var_name, *args, **kwargs) + error_message = \ + gv.valid_path(var_value, *args, var_name=var_name, **kwargs) + process_error_message(error_message) + + +def valid_list(var_name, *args, **kwargs): + + var_value, args, kwargs = valid_init(var_name, *args, **kwargs) + error_message = \ + gv.valid_list(var_value, *args, var_name=var_name, **kwargs) + process_error_message(error_message) + + +def valid_dict(var_name, *args, **kwargs): + + var_value, args, kwargs = valid_init(var_name, *args, **kwargs) + error_message = \ + gv.valid_dict(var_value, *args, var_name=var_name, **kwargs) + process_error_message(error_message) + + +def valid_program(var_name, *args, **kwargs): + + var_value, args, kwargs = valid_init(var_name, *args, **kwargs) + error_message = \ + gv.valid_program(var_value, *args, var_name=var_name, **kwargs) + process_error_message(error_message) + + +def valid_length(var_name, *args, **kwargs): + + var_value, args, kwargs = valid_init(var_name, *args, **kwargs) + error_message = \ + gv.valid_length(var_value, *args, var_name=var_name, **kwargs) + process_error_message(error_message) + + +# Modify the validation function docstrings by calling customize_doc_string for each function in the +# func_names list. +func_names = [ + "valid_type", "valid_value", "valid_range", "valid_integer", + "valid_dir_path", "valid_file_path", "valid_path", "valid_list", + "valid_dict", "valid_program", "valid_length", "valid_float", + "valid_date_time" +] + +for func_name in func_names: + cmd_buf = func_name \ + + ".__doc__ = customize_doc_string(gv.raw_doc_strings['" \ + + func_name + "'])" + exec(cmd_buf) diff --git a/lib/pgm_template.py b/lib/pgm_template.py new file mode 100644 index 0000000..62952d9 --- /dev/null +++ b/lib/pgm_template.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python + +r""" +This module is the python counterpart to pgm_template.py. +""" + +import gen_print as gp +import gen_robot_valid as grv + + +def suite_setup(): + r""" + Do test suite setup tasks. + """ + + gp.qprintn() + + validate_suite_parms() + + gp.qprint_pgm_header() + + +def test_setup(): + r""" + Do test case setup tasks. + """ + + gp.qprintn() + gp.qprint_executing() + + +def validate_suite_parms(): + r""" + Validate suite parameters. + """ + + # Programmer must add these. + # grv.valid_value("HOST") + + return + + +def suite_teardown(): + r""" + Clean up after this program. + """ + + gp.qprint_pgm_footer() diff --git a/lib/pgm_template.robot b/lib/pgm_template.robot new file mode 100644 index 0000000..745d3e5 --- /dev/null +++ b/lib/pgm_template.robot @@ -0,0 +1,33 @@ +*** Settings *** + +# Copy this template as a base to get a start on a robot program. You may remove any generic comments (like +# this one). + +Documentation Base to get a start on a robot program. + +Library pgm_template.py +Library gen_print.py +Library gen_robot_print.py +Library gen_robot_valid.py +Library gen_robot_keyword.py + +Suite Setup Suite Setup +Suite Teardown Suite Teardown +Test Setup Test Setup + +*** Variables *** +# Initialize program parameters variables. +# Create parm_list containing all of our program parameters. +@{parm_list} TEST_MODE QUIET DEBUG + +# Initialize each program parameter. +${TEST_MODE} 0 +${QUIET} 0 +${DEBUG} 0 + + +*** Test Cases *** +Test Case 1 + [Documentation] Test case 1 documentation. + + Qprint Timen First test case.