Test module#

class ansys.scadeone.core.swan.harness.TestModule(name: PathIdentifier, use_directives: List[UseDirective] | None = None, declarations: List[GlobalDeclaration] | None = None, pragmas: List[Pragma] | None = None)#

Bases: Module, TestModuleCreator

Test module definition.

body() ModuleBody | None#

Return the module body for a module interface if it exists.

filter_declarations(filter_fn: Callable[[ModuleItem], bool]) List[ModuleItem]#

Return declarations matched by a filter.

Parameters:
filter_fnCallable[[common.ModuleItem], bool]

A function of one argument of type ModuleItem, returning True or False.

Returns:
List[ModuleItem]

List of matching declarations.

get_declaration(name: str) Declaration | None#

Return the type, sensor, group, constant, or operator declaration searching by namespace.

get_full_path() str#

Full Swan path of module.

get_use_directive(module_name: str) UseDirective | None#

Return the use directive searching by module name or alias name.

Aliases are searched first, the module name is searched if no alias is found. When a module name is searched, use directive with first occurrence is returned.

Parameters:
module_namestr

Name of the module (last part of a path) or alias.

Returns:
Found UseDirective or None
interface() ModuleInterface | None#

Return the module interface for a module body if it exists.

static module_name_from_path(path: Path) str#

Returns a module name from a path.

Parameters:
pathPath

Path to the module, e.g. /path/to/namespace-module.swan

Returns:
str

Module name, e.g. namespace::module

static set_owner(owner: SwanItem | IModel | None, children: SwanItem | Iterable[SwanItem] | None) None#

Helper to set owner as the owner of each item in the Iterable items.

Parameters:
ownerSwanItem

Owner of the items.

childrenUnion[SwanItem, Iterable[SwanItem], None]

Items to set owner.

use(module: swan.Module | str, alias: str = None) swan.UseDirective#

Add a use directive to the module.

Parameters:
module: Module

Module name.

alias: str

Module alias.

Returns:
UseDirective

UseDirective object.

property constants: List[ConstDecl]#

Return a list of constant declarations.

property declarations: List[ModuleItem]#

Module’s declarations

property extension: str#

Returns module extension, with ‘.’ included.

property file_name: str#

Return a file name based on module name and namespaces.

property groups: List[GroupDecl]#

Return a list of group declarations.

property is_protected: bool#

Tell if a construct item is syntactically protected with some markup and is stored as a string (without the markup).

property model: IModel#

Return model containing the Swan item.

property module: ModuleBase | None#

Module containing the item.

Returns:

ModuleBase: module container, see ModuleBody and ModuleInterface or None if the object is itself a module.

property name: PathIdentifier#

Module or Interface name.

property operator_declarations: List[OperatorDeclaration]#

Return a list of operator declarations.

property operator_definitions: List[OperatorDefinition]#

Return a list of operator definitions.

property owner: SwanItem | IModel | None#

Owner of current Swan construct.

property pragmas: List[Pragma]#

List of pragmas.

property sensors: List[SensorDecl]#

Return a list of sensor declarations.

property source: str | None#

Source of the module, as a string (file name).

property test_harnesses: List[TestHarness]#

Return a list of test harness.

property types: List[TypeDecl]#

Return a list of type declarations.

property use_directives: List[UseDirective]#

Module’s use directives as a list.