Condition Namespace

The Condition space defines a number functions to test for certain states when doing conditional testing. It currently cannot be extended via the extension API.

Functions

IsPlatform(self, *lst)

Returns a condition that will resolve to True if one of the provided platform identifiers matches the value of python sys.platform, platform.system() or os.name. The string is tested in a case insensitive way. If a match is not found it will return False

Parameters:

*lst (str) – function list of string values to test

IsNotPlatform(self, *lst)

Returns a condition that will resolve to True if one of the provided platform identifiers does not matches the value of python sys.platform, platform.system() or os.name. The string is tested in a case insensitive way. If a match is found it will return False.

Parameters:

*lst (str) – function list of string values to test

RunCommand(self, command, msg, pass_value=0, shell=False)

Returns a condition that will run a command and test that return code matches the expected value. Use this to run custom command to test for state or to build more custom condition when creating an extension. :type command: str :param command: The command string with anyarguments :type msg: str :param msg: The message to print the condition fails :type pass_value: int :param pass_value: value to test for the condition to pass :param shell: run the command in a shell vs running it without a shell

CheckOutput(self, command, check_func, msg, pass_value=True, neg_msg=None, shell=False)

Returns a condition that will run a command and test the output via a callback function. The condition test will pass given that the command run without error and the return code of the function provided by the check_func argument matches the pass_value. :type command: str :param command: The command to run :type check_func: Callable[[str], bool] :param check_func: The callback function used to test the output of the command. :type msg: str :param msg: The message to print about the condition. :type pass_value: Any :param pass_value: Value to test for the condition to pass. :type neg_msg: Optional[str] :param neg_msg: Option message to print if the condition fails. :type shell: bool :param shell: Run the command in a shell vs running it without a shell.

EnsureVersion(self, command, min_version=None, max_version=None, msg=None, output_parser=None, shell=False)

Returns a condition that will run a command and test the output matches a predefined version match callback. :param command: The command to run to get the version value

The common form of this is <program> –version or <program> -v

Parameters:
  • min_version – Optional minimum version that we much match. If not provided and value less or equal to the max version will be accepted

  • max_version

    Optional maximum version that we much match. If not provided and value greater or equal to the min version will be accepted .. note:

    One value for min_version or max_version has to be provided.
    Both cannot be None.
    

  • msg – The message to print about the condition.

  • output_parser (Optional[Callable[[str], Optional[str]]]) – Optional callback function that can be used retrieve the version. The default function run a regular expression of “(?P<ver>d+.d+(?:.d+)*)” If this does not work for the application being tested a custom function can be provided here. The function will be given a string of the out of the command to parse. It has to return back a string with the version value in it or None is it failed to parse the value.

  • pass_value – Value to test for the condition to pass.

  • neg_msg – Option message to print if the condition fails.

  • shell – Run the command in a shell vs running it without a shell.

HasProgram(self, program, msg, pass_value=True, path=None)

Returns a condition that will test is a application can be found on the path. :type program: str :param program: The program to test for.

On windows .exe does not need to be added as the default environment variable of PATHEXT will be used.

Parameters:
  • msg – The message to print about the condition.

  • pass_value – Value to test for the condition to pass. In this case True is for program was found and False for when the it was not.

  • path – optional string of extra paths to check for the application the path most be formatted as the local system PATH variable with the local use of ‘:’ or ‘;’

IsElevated(self, msg, pass_value=0)

Returns a condition that test AuTest is running as a privilege process. On Unix based systems this mean root permission On Window this mean running with admin rights :type msg: str :param msg: The message to print the condition fails :type pass_value: int :param pass_value: advance value used to control what value is tested when checking the result of running privilege

HasPythonPackage(self, package, msg)

Returns a condition that test if a python package is installed by calling the current active pip. :type package: Union[str, List[str]] :param package: One or more packages to test for. The input can be a space seperated string or a list. :type msg: str :param msg: The message to print if the packages are not found

Examples

Test to see if requests is installed. .. code:: python3

Test.SkipUnless(Condition.HasProgram.HasPythonPackage(“requests”))

Test to see if requests and microserver is installed. .. code:: python3

Test.SkipUnless(Condition.HasProgram.HasPythonPackage(“requests microserver”))

or via a list. .. code:: python3

Test.SkipUnless(Condition.HasProgram.HasPythonPackage([“requests”,”microserver”]))

HasRegKey(self, root, keys, msg)

Returns a condition that will test if a given key are found in the registry on windows.

Parameters:
  • root (str) – The root path to check for the keys under

  • keys (List[str]) – the list of one or more keys to check for

  • msg (str) – The message to print about the condition.