Skip to main content

Shared contract utilities for the OKW ecosystem: matchers (EXACT/WCM/REGX), global tokens ($IGNORE/$EMPTY/$DELETE), YES/NO existence model, and $MEM{KEY} value expansion.

Project description

okw-contract-utils

Shared utilities for the OKW ecosystem. This package defines cross-library contracts such as matchers (EXACT/WCM/REGX), value expansion ($MEM{KEY}), global OKW tokens, and the YES/NO existence model.

Features

  • Match modes: EXACT (equality), WCM (wildcard via fnmatch: * = any chars, ? = one char), REGX (regex via re.search)
  • Value expansion: $MEM{KEY} placeholder expansion via expand_mem(text, store)
  • Global tokens: $IGNORE, $EMPTY, $DELETE
  • YES/NO existence model: parse_yes_no(), assert_exists()
  • Timeout helper: wait_until(predicate, timeout_s, interval_s)
  • Exceptions: OkwAssertionError, OkwTimeoutError, OkwConfigError

Non-goals

  • No Robot Framework keywords
  • No SSH/Selenium/GUI dependencies
  • No environment/provider logic

Match Modes

All match modes normalize newlines (\r\n to \n) before comparing.

Mode Function Description
EXACT a == e Exact string equality
WCM fnmatch(a, e) Wildcard pattern match (* = any chars, ? = one char)
REGX re.search(e, a) Regular expression search (multiline)

Usage:

from okw_contract_utils import assert_match, MatchMode

assert_match("Hello World", "Hello World", MatchMode.EXACT)
assert_match("Hello World", "Hello*", MatchMode.WCM)
assert_match("Hello World", r"Hello\s+\w+", MatchMode.REGX)

Global Token Model

OKW defines a small set of global tokens. Tokens are case-insensitive and evaluated after trimming surrounding whitespace.

Tokens are defined here (contract) and may be implemented selectively by concrete keyword libraries. Not every library must implement every token.

Tokens

  • $IGNORE (control token)

    • Meaning: the keyword becomes a no-op (PASS).
    • Use case: disable single steps inside reusable sequences without control structures.
  • $EMPTY (value-intent token)

    • Meaning: expected/target value is empty.
    • Use case: explicitly verify that a value is empty (e.g. stdout/stderr is empty), even if the underlying system does not represent emptiness strictly as "".
  • $DELETE (action-intent token)

    • Meaning: perform an explicit delete/clear action.
    • Typically used in GUI libraries (e.g. clear text fields).
    • Libraries that cannot implement delete semantics simply do not support $DELETE.

Robot Framework variables

Robot variables like ${IGNORE} are expanded by Robot before the keyword is executed. If ${IGNORE} is not defined, Robot fails before the library can handle it.

Recommended suite variables:

*** Variables ***
${IGNORE}    $IGNORE
${EMPTY}     $EMPTY
${DELETE}    $DELETE

Evaluation order (contract)

For keyword parameters of type Value/Expected/Command:

  • Robot Framework variable expansion (e.g. ${IGNORE} -> $IGNORE)
  • OKW value expansion (e.g. $MEM{KEY})
  • Token parsing ($IGNORE, $EMPTY, $DELETE)
  • Keyword semantics / adapter execution

YES/NO Existence Model

For keywords that verify whether a resource exists (files, directories, UI elements, etc.), OKW defines a standard YES/NO model.

Accepted values

Input Parsed as
YES, TRUE, 1 YES (must exist)
NO, FALSE, 0 NO (must not exist)

All values are case-insensitive and trimmed. Invalid values raise ValueError.

Usage

from okw_contract_utils.tokens import parse_yes_no, assert_exists, OkwYesNo

# Parse user input
yn = parse_yes_no("YES")       # -> OkwYesNo.YES
yn = parse_yes_no("false")     # -> OkwYesNo.NO
yn = parse_yes_no("1")         # -> OkwYesNo.YES

# Assert existence
assert_exists(True, OkwYesNo.YES)   # PASS
assert_exists(False, OkwYesNo.NO)   # PASS
assert_exists(False, OkwYesNo.YES)  # raises OkwAssertionError

Robot Framework integration

Keywords typically expose the expected parameter with a default of YES:

Verify Remote File Exists    session1    /tmp/data.txt           # default: YES
Verify Remote File Exists    session1    /tmp/data.txt    YES
Verify Remote File Exists    session1    /tmp/old.txt     NO     # must NOT exist

Value Expansion

expand_mem(text, store) replaces $MEM{KEY} placeholders with values from a dictionary. Missing keys cause an immediate error (no silent fallback).

from okw_contract_utils import expand_mem

store = {"USER": "admin", "HOST": "10.0.0.1"}
result = expand_mem("ssh $MEM{USER}@$MEM{HOST}", store)
# -> "ssh admin@10.0.0.1"

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

okw_contract_utils-0.2.1.tar.gz (20.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

okw_contract_utils-0.2.1-py3-none-any.whl (18.9 kB view details)

Uploaded Python 3

File details

Details for the file okw_contract_utils-0.2.1.tar.gz.

File metadata

  • Download URL: okw_contract_utils-0.2.1.tar.gz
  • Upload date:
  • Size: 20.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for okw_contract_utils-0.2.1.tar.gz
Algorithm Hash digest
SHA256 6803570d6dd36c13c44de19ff92ec41e6e89a254decbb76f23551bc72585ceed
MD5 5a5b7162d24bf592421805f66ff26d6a
BLAKE2b-256 da34e1dbb3f5759eb7a982e0a356205fb3463f85d82a84c96ac542a77e12ac7b

See more details on using hashes here.

File details

Details for the file okw_contract_utils-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for okw_contract_utils-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 aca63d9bb5efa20115e283572f829e5125ffafec58c82260faa17f5e32724036
MD5 834ded40528154e5e6b8d1b848c27ec4
BLAKE2b-256 0b7c7928e4f2abf07d759e18d18e7d3f5ea040035413c6605997ccece0d06aa6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page