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.0.tar.gz (21.2 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.0-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for okw_contract_utils-0.2.0.tar.gz
Algorithm Hash digest
SHA256 95b441d6a0e345355905a038e4b37fe3b7c91927b75053d29acc651666978b0f
MD5 c566aa5391583150416645ee86299434
BLAKE2b-256 386bb3d1730db6daea155ad24122e309e552a89e5239ef4d499e8df27e866b7f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for okw_contract_utils-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 40b77ab1e4a9ea01cc1b943827f4d74c2d55d11298f2e5722ee49d273f74f83e
MD5 d51e39ca3322aa1ab1f114332bf9d1ee
BLAKE2b-256 cbd63f3b8559a2cd1edc04724e9c15af1a876c60299b182cc3d6ce321db15453

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