When namespace

This namespace contains a set of functions to help with testing when and given process maybe considered ready. By default without the functions the only valid input is a number which would represent the time in second to wait. For many application the test to be ready can be defined such as does a file exists on disk. AuTest contains a various set of functions to help with common items to test for. More items will be added in future releases. New items can be added via the extention to add missing logic

Network

These test state of network ports.

PortOpen(port, address=None, timeout=None, address_family='inet')

Checks to see if a port is open. This function is more like a stat test in that no traffic happens. Only a check that the system sees the port is open. Even if the port is open the server may not be ready to accept data. If the code to do a netstat test on the system does not exist the code will fallback to a PortReady call

Parameters:
  • port (int) – The port to check.

  • address (Optional[str]) – The address to bind to.

  • timeout (Optional[int]) – How long to wait before timing out. Ignored unless code falls back to PortReady call.

  • address_family (str) – The family of space to use. Checks both IPv4 and Ipv6 spaces by default (‘inet’). For the possible values of this string, see the “kind” parameter to psutil.net_connections().

Examples

Don’t start the curl command until the port on the server is ready

Test.SkipUnless(Condition.HasProgram("curl","Curl need to be installed on system for this test to work"))

p=Test.Processes.Process("ts","my-server –port 8080")
t = Test.AddTestRun("server started properly")
t.StillRunningAfter = Test.Processes.ts

p = t.Processes.Default
p.Command = "curl http://127.0.0.1:8080"
p.ReturnCode = 0
p.StartBefore(Test.Processes.ts, ready = When.PortOpen(8080))
PortOpenv4(port, address=None, timeout=None)

The same as PortOpen(): except it will only check on ipv4 space

Parameters:
  • port (int) – The port to check.

  • address (Optional[str]) – The address to bind to.

  • timeout (Optional[int]) – How long to wait before timing out. Ignored unless code falls back to PortReady call.

PortOpenv6(port, address=None, timeout=None)

The same as PortOpen(): except it will only check on ipv6 space

Parameters:
  • port (int) – The port to check.

  • address (Optional[str]) – The address to bind to.

  • timeout (Optional[int]) – How long to wait before timing out. Ignored unless code falls back to PortReady call.

PortReady(port, address=None, timeout=None)

Detect whether the port is open via trying to connect the address and port. This causes some traffic on the host of the port, however this also means that the host is more likely to be ready to get traffic.

Note

This does not mean the host is “ready”. In such cases a different test of state may be needed, such as sending a test packet/message of some kind that the application understand and can send a response to

Parameters:
  • port (int) – The port to check.

  • address (Optional[str]) – The address to bind to. If not specified, both localhost and ip6-localhost will be checked.

  • timeout (Optional[float]) – How long to wait before timing out. Ignored unless code falls back to PortReady call.

Return type:

bool

PortsOpen(ports)

Test that all Ports are open via doing doing multipul calls to PortOpen() It will return true when all port return that they are open.

Parameters:

ports (List[int]) – List of port values to check

PortsReady(ports)

Test that all Ports are open via doing doing multipul calls to PortReady(). It will return true when all port return that they are ready.

Parameters:

ports (List[int]) – List of port values to check

File System

These test state of file or directories on disk.

DirectoryExists(directory_path)

Tests to see if the directory has exists.

Parameters:

directory_path (Union[str, Directory]) – The path to the directory to test

DirectoryModified(directory_path)

Tests to see if the directory has been modified. The change is done via checking for a time stamp difference. On most operating systems this only changes when a file or directory was added, or removed in that directory, not and subdirectories below it. If the directory does not exist, then it will test for existence of the directory

Parameters:

file_path – The path to the file to test

DirectoryNotExists(directory_path)

Tests to see if the directory does not exist.

Parameters:

directory_path (Union[str, Directory]) – The path to the directory to test

FileExists(file_path)

Tests that a file exists on disk.

Parameters:

file_path (Union[str, File]) – The path to the file to test

FileModified(file_path)

Tests to see if the file has been modified. If the file does not exist, then it will test for existence of the file

Parameters:

file_path (Union[str, File]) – The path to the file to test

FileNotExists(file_path)

Tests that a file not exists on disk.

Parameters:

file_path (Union[str, File]) – The path to the file to test

Random

Counter(count_to)

Will call this check the number of proved times then return True.

Parameters:

count_to (int) – number of times to call function before returning true.