Python API#

Each step is a function that takes the previous step’s data and returns its own. Use the tool from Python shows them together.

Step 1: read the requirements or test cases#

nominal_checks_from_jama.read_requirements(config='jama-checks.toml', *, jama=None, kind=ItemKind.REQUIREMENTS)#

Read every requirement, or every test case, of the item types the settings list.

Parameters:
  • config (Config | str | Path)

    The settings, or the path of the settings file.

  • jama (JamaClient | None)

    The Jama client; one signed in from the settings when None.

  • kind (ItemKind)

    Requirements, from [jama] item_types, or test cases, from [jama] test_case_types.

Returns:

The project and its requirements or test cases.

Return type:

Requirements

Raises:

ReadError – When no item types are listed, or Jama’s listing stopped early. A partial list would make items look removed.

class nominal_checks_from_jama.Requirements(source, requirements, kind=ItemKind.REQUIREMENTS)#

Every requirement, or every test case, read from one Jama project.

Parameters:
source#

The project.

Type:

Source

requirements#

Its requirements or test cases.

Type:

tuple[Requirement, …]

kind#

Which of the two they are.

Type:

ItemKind

save(path=None)#

Write the items to a file.

Parameters:

path (str | Path | None)

The file; requirements.json or test-cases.json when None.

Returns:

The file written.

Return type:

Path

classmethod load(path='requirements.json')#

Read requirements or test cases from a file save() wrote.

Parameters:

path (str | Path)

The file.

Returns:

The requirements or test cases.

Return type:

Requirements

Raises:

FileFormatError – When the file isn’t a requirements file this version reads.

class nominal_checks_from_jama.Requirement(item_id, document_key, name, text, html, url)#

One Jama requirement or test case, as Jama has it.

Parameters:
  • item_id (str)

  • document_key (str)

  • name (str)

  • text (str)

  • html (str)

  • url (str)

item_id#

The Jama item id.

Type:

str

document_key#

The item’s document key, such as WA-REQ-12, or its id when it has none.

Type:

str

name#

The item’s name.

Type:

str

text#

The item’s description as plain text, then a test case’s steps.

Type:

str

html#

The item’s description as Jama stores it, in HTML, then a test case’s steps.

Type:

str

url#

The item’s URL in Jama.

Type:

str

class nominal_checks_from_jama.Source(base_url, project, project_name)#

The Jama project the requirements come from.

Parameters:
  • base_url (str)

  • project (str)

  • project_name (str)

base_url#

The Jama instance’s URL.

Type:

str

project#

The project id.

Type:

str

project_name#

The project’s name.

Type:

str

class nominal_checks_from_jama.ItemKind(*values)#

Which Jama items a run works on.

REQUIREMENTS = 'requirements'#

Items of the types in [jama] item_types.

TEST_CASES = 'test_cases'#

Items of the types in [jama] test_case_types.

Step 2: make the checks#

nominal_checks_from_jama.build_checks(requirements, find_channels=None, *, markers=())#

Make a check for each requirement.

Parameters:
  • requirements (Requirements)

    The requirements, from step 1.

  • find_channels (ChannelFinder | None)

    Finds the channel names in a requirement. When None, the tool’s own: names marked with backticks, code formatting and markers.

  • markers (tuple[str, ...])

    The extra marker pairs the tool’s own finder uses, from PAIRS. Ignored when find_channels is given.

Returns:

The checks, ordered by document key.

Return type:

Checks

class nominal_checks_from_jama.Checks(source, checks, kind=ItemKind.REQUIREMENTS)#

Every check to keep for one Jama project’s requirements, or for its test cases.

Parameters:
source#

The Jama project.

Type:

Source

checks#

The checks, ordered by document key.

Type:

tuple[CheckSpec, …]

kind#

Whether the checks are for requirements or test cases. Each kind has its own checklist.

Type:

ItemKind

save(path=None)#

Write the checks to a file.

Parameters:

path (str | Path | None)

The file; checks.json or test-checks.json when None.

Returns:

The file written.

Return type:

Path

classmethod load(path='checks.json')#

Read checks from a file save() wrote, or that your own code wrote in the same layout.

Parameters:

path (str | Path)

The file.

Returns:

The checks.

Return type:

Checks

Raises:

FileFormatError – When the file isn’t a checks file this version reads.

class nominal_checks_from_jama.CheckSpec(item_id, document_key, url, lineage, title, description, channels=())#

One check to keep, for one requirement.

Parameters:
  • item_id (str)

  • document_key (str)

  • url (str)

  • lineage (str)

  • title (str)

  • description (str)

  • channels (tuple[str, ...])

item_id#

The requirement’s Jama item id.

Type:

str

document_key#

Its document key.

Type:

str

url#

Its URL in Jama.

Type:

str

lineage#

The check’s lineage in Nominal: a UUID made from the Jama URL and item id, the same on every run.

Type:

str

title#

The check’s title.

Type:

str

description#

The check’s description, ending with the line linking to Jama.

Type:

str

channels#

The channel names to make checklist variables for.

Type:

tuple[str, …]

nominal_checks_from_jama.lineage(base_url, item_id)#

The check lineage for a requirement: the same on every run, and when the requirement is renamed.

Parameters:
  • base_url (str)

    The Jama instance’s URL.

  • item_id (str)

    The Jama item id.

Returns:

The lineage, a UUID.

Return type:

str

nominal_checks_from_jama.checks_from_jama(config, *, find_channels=None, jama=None, kind=ItemKind.REQUIREMENTS)#

Read the project’s requirements or test cases from Jama and make their checks.

Parameters:
  • config (Config)

    The settings: the Jama project, and the channel markers that are on.

  • find_channels (ChannelFinder | None)

    Finds the channel names in an item; the tool’s own, with the settings’ markers, when None.

  • jama (JamaClient | None)

    The Jama client; one signed in from the settings when None.

  • kind (ItemKind)

    Requirements or test cases.

Returns:

The checks.

Return type:

Checks

nominal_checks_from_jama.checks_from_file(path, *, markers=(), find_channels=None)#

The checks from a checks file, or made from a requirements or test cases file.

Parameters:
  • path (str | Path)

    The file.

  • markers (tuple[str, ...])

    The channel markers that are on, for a requirements file.

  • find_channels (ChannelFinder | None)

    Finds the channel names, for a requirements file; the tool’s own when None.

Returns:

The checks.

Return type:

Checks

Raises:

FileFormatError – When the file is neither.

Finding channels#

nominal_checks_from_jama.markers.ChannelFinder#

Finds the channel names in one requirement, in the order they should become variables.

alias of Callable[[Requirement], Sequence[str]]

nominal_checks_from_jama.marked_channels(markers=())#

The tool’s own ChannelFinder: the names marked with backticks, code formatting and markers.

Parameters:

markers (Iterable[str])

The pairs from PAIRS that are on.

Returns:

The finder.

Return type:

ChannelFinder

nominal_checks_from_jama.channel_names(description_html, text, markers=())#

The channel names a requirement marks, in the order they first appear.

Parameters:
  • description_html (str)

    The requirement’s description as Jama stores it, for code formatting.

  • text (str)

    The same description as plain text, for the other markers.

  • markers (Iterable[str])

    The pairs from PAIRS that are on.

Returns:

The names, each once.

Return type:

tuple[str, …]

nominal_checks_from_jama.markers.PAIRS: dict[str, Pattern[str]]#

Pairs that can mark a channel name, besides backticks, by the name channel_markers uses.

Each pattern’s first group is the name. Add an entry to make a new pair available to channel_markers.

Output: your agent’s plan#

nominal_checks_from_jama.write_agent_plan(checks, *, target=None, checklist_name='', data_scope='default')#

Write the instructions for an agent from the checks.

Parameters:
  • checks (Checks)

    The checks, from step 2.

  • target (str | None)

    The RID of an asset or run whose channels the conditions should use. When None, the instructions tell the agent to ask, and to propose channel names if the user has no data yet.

  • checklist_name (str)

    The checklist’s name, if the agent creates it; <project name> requirements or <project name> test cases when empty.

  • data_scope (str)

    The data scope for channels the agent proposes, which the user’s runs should use: [nominal] ref_name in the settings.

Returns:

The instructions.

Return type:

AgentPlan

class nominal_checks_from_jama.AgentPlan(markdown, checks)#

The instructions, and what they cover.

Parameters:
  • markdown (str)

  • checks (tuple[str, ...])

markdown#

The file’s contents.

Type:

str

checks#

The titles of the checks they cover.

Type:

tuple[str, …]

Output: the checklist in Nominal#

nominal_checks_from_jama.sync(checks, *, nominal=None, update=(Field.TITLE, Field.DESCRIPTION), remove_missing=False, dry_run=False, checklists=None)#

Bring the Nominal checklist for the checks’ Jama project in line with them.

The first sync creates and publishes the checklist. Later syncs find it by its properties, jama_host, jama_project and jama_items. Requirements and test cases each have their own checklist.

Parameters:
  • checks (Checks)

    The checks, from step 2.

  • nominal (NominalSettings | None)

    The profile, priority, data source and checklist name to use; the defaults when None.

  • update (Iterable[Field])

    The fields to rewrite from Jama where a check differs. Empty to only report differences.

  • remove_missing (bool)

    Remove checks whose requirement is gone from Jama, rather than reporting them.

  • dry_run (bool)

    Work out the changes, but write nothing to Nominal.

  • checklists (Checklists | None)

    The Nominal connection; one from the profile when None.

Returns:

What it found and did.

Return type:

SyncResult

Raises:

SyncError – When more than one checklist is for the Jama project.

nominal_checks_from_jama.plan_sync(checks, version, *, priority='P3', ref_name='default', update=(Field.TITLE, Field.DESCRIPTION), remove_missing=False)#

Work out the checklist’s checks and variables from the checks and the checklist as it is.

Parameters:
  • checks (Checks)

    The checks, from step 2.

  • version (ChecklistVersion | None)

    The checklist’s latest version; None for a new checklist.

  • priority (str)

    The priority of new checks.

  • ref_name (str)

    The data source new variables read.

  • update (Iterable[Field])

    The fields to rewrite from Jama where a check differs. Empty to only report differences.

  • remove_missing (bool)

    Remove checks whose requirement is gone from Jama, rather than reporting them.

Returns:

The checks and variables to commit, and what happened to each.

Return type:

SyncPlan

class nominal_checks_from_jama.SyncResult(plan, checklist_rid, checklist_url, created, committed, dry_run)#

What a sync found and did.

Parameters:
  • plan (SyncPlan)

  • checklist_rid (str | None)

  • checklist_url (str | None)

  • created (bool)

  • committed (bool)

  • dry_run (bool)

plan#

Each requirement’s outcome, and the checks committed.

Type:

SyncPlan

checklist_rid#

The checklist, or None when there is none yet.

Type:

str | None

checklist_url#

Its URL in the Nominal app.

Type:

str | None

created#

Whether this sync created the checklist.

Type:

bool

committed#

Whether this sync committed a new version of it.

Type:

bool

dry_run#

Whether this was a dry run, which writes nothing.

Type:

bool

class nominal_checks_from_jama.SyncPlan(entries, variables, results, variable_results=())#

The checklist’s checks and variables after a sync, and what changed.

Parameters:
  • entries (tuple[NewCheck | Keep | Rewrite, ...])

  • variables (tuple[NewVariable | KeepVariable, ...])

  • results (tuple[Result, ...])

  • variable_results (tuple[VariableResult, ...])

entries#

Every check, in order: existing checks where they were, new ones after them.

Type:

tuple[Entry, …]

variables#

Every checklist variable, in order.

Type:

tuple[NewVariable | KeepVariable, …]

results#

One per requirement, and per check whose requirement is gone.

Type:

tuple[Result, …]

variable_results#

One per variable added.

Type:

tuple[VariableResult, …]

property changed: bool#

Whether the checklist needs a new commit.

Returns:

True when a check is created, updated or removed, or a variable is added.

Return type:

bool

counts()#

How many requirements had each outcome.

Returns:

The counts, for the outcomes that occurred.

Return type:

dict[Outcome, int]

class nominal_checks_from_jama.Result(item_id, title, outcome, differences=())#

One requirement’s outcome.

Parameters:
item_id#

The requirement’s Jama item id.

Type:

str

title#

Its check’s title.

Type:

str

outcome#

What happened.

Type:

Outcome

differences#

Where the check differed from Jama.

Type:

tuple[Difference, …]

class nominal_checks_from_jama.Difference(field, nominal, jama)#

One field where a check differs from its requirement.

Parameters:
  • field (Field)

  • nominal (str)

  • jama (str)

field#

The field.

Type:

Field

nominal#

What the check has.

Type:

str

jama#

What the requirement makes it.

Type:

str

class nominal_checks_from_jama.VariableResult(document_key, channel, name)#

A checklist variable the sync added for a marked channel.

Parameters:
  • document_key (str)

  • channel (str)

  • name (str)

document_key#

The requirement’s document key.

Type:

str

channel#

The channel.

Type:

str

name#

The variable’s ID in the checklist.

Type:

str

class nominal_checks_from_jama.Outcome(*values)#

What a sync did with one requirement’s check.

CREATED = 'created'#
UPDATED = 'updated from Jama'#
UNCHANGED = 'unchanged'#
DIFFERS = 'differs from Jama, not updated'#
CANT_UPDATE = "differs from Jama, not updated: the tool can't copy its condition"#
GONE = 'gone from Jama, kept'#
REMOVED = 'gone from Jama, removed'#
SEVERAL = 'has more than one check, left as they are'#

Such as a test case an agent split into a check for each pass criterion.

class nominal_checks_from_jama.Field(*values)#

A part of a check that comes from Jama.

TITLE = 'title'#
DESCRIPTION = 'description'#

Settings#

class nominal_checks_from_jama.Config(jama, nominal=<factory>, path=None)#

Everything in jama-checks.toml.

Parameters:
jama#

The Jama project and sign-in.

Type:

JamaSettings

nominal#

The checklist.

Type:

NominalSettings

path#

The file it was read from.

Type:

Path | None

classmethod load(path='jama-checks.toml')#

Read the settings from a TOML file.

Parameters:

path (str | Path)

The file.

Returns:

The settings.

Return type:

Config

Raises:
  • FileNotFoundError – When the file doesn’t exist. nominal-checks-from-jama init creates it.

  • ValueError – When a required setting is missing or a value is invalid.

save(path=None)#

Write the settings to a TOML file.

Parameters:

path (str | Path | None)

The file; the one it was loaded from when None.

Returns:

The file written.

Return type:

Path

class nominal_checks_from_jama.JamaSettings(base_url, project, item_types=(), auth=AuthKind.CLIENT_CREDENTIALS, account='', test_case_types=())#

The Jama project to read and how to sign in. The secret is kept in the operating system’s credential manager.

base_url#

The Jama instance’s URL. The URL of any page on it, copied from the browser, works too: it’s cut to the instance’s URL.

Type:

str

project#

The project id.

Type:

str

item_types#

The item type ids whose items are requirements.

Type:

tuple[str, …]

test_case_types#

The item type ids whose items are test cases.

Type:

tuple[str, …]

auth#

How to sign in.

Type:

AuthKind

account#

The API client ID for client_credentials, the username for basic, and a name of your choice for token. The credential manager stores the secret under it.

Type:

str

Raises:

ValueError – When base_url isn’t an http or https URL.

Parameters:
  • base_url (str)

  • project (str)

  • item_types (tuple[str, ...])

  • auth (AuthKind)

  • account (str)

  • test_case_types (tuple[str, ...])

class nominal_checks_from_jama.NominalSettings(profile='default', checklist_name='', priority='P3', ref_name='default', channel_markers=(), test_case_checklist_name='')#

Where the checklist goes and what its checks look like.

Parameters:
  • profile (str)

  • checklist_name (str)

  • priority (str)

  • ref_name (str)

  • channel_markers (tuple[str, ...])

  • test_case_checklist_name (str)

profile#

The Nominal config profile to connect with.

Type:

str

checklist_name#

The requirements checklist’s name when it’s created; <project name> requirements when empty. Renaming it in Nominal afterwards is fine.

Type:

str

priority#

The priority of new checks, P0 to P4.

Type:

str

ref_name#

The data source that channels marked in requirements are read from.

Type:

str

channel_markers#

Pairs that mark a channel name besides backticks, from {}, [] and <>.

Type:

tuple[str, …]

test_case_checklist_name#

The test case checklist’s name when it’s created; <project name> test cases when empty.

Type:

str

class nominal_checks_from_jama.AuthKind(*values)#

How the tool signs in to Jama.

CLIENT_CREDENTIALS = 'client_credentials'#

An API client ID and secret.

BASIC = 'basic'#

A username and password. Doesn’t work on instances that use single sign-on.

TOKEN = 'token'#

An access token, which nothing renews.

Errors#

exception nominal_checks_from_jama.ReadError#

Reading the requirements stopped before it had all of them.

exception nominal_checks_from_jama.SyncError#

The sync stopped before changing anything in Nominal.

exception nominal_checks_from_jama.NominalError#

Nominal refused a request, or returned something this tool can’t use.

exception nominal_checks_from_jama.ChecklistConflict#

Someone committed to the checklist between the tool reading it and committing.

exception nominal_checks_from_jama.FileFormatError#

A file isn’t the kind or version a step reads.

Jama Connect® is a registered trademark of Jama Software, Inc.