PyUseOCL’s Documentation¶
PyUseOCL is a python wrapper around the excellent USE OCL tool (see also ScribesTools/UseOCL). OCL refers here to the Object Constraint Language, a part of the UML standard. USE OCL is a java-based environment based on OCL.
By parsing different kind of output of the USE OCL command line tool, PyUseOCL provides an “poor-man” integration means for python programs (through the PyUseOCL API). PyUseOCL is mostly intended for automation. PyUseOCL also provides a few features out of the box via the a very simple command line.
Features¶
PyUseOCL features includes:
- a python-based AST for structural part of “use” models.
The structural content of
.use
class models is made avaible in python in the form of abstract syntax trees. Thepyuseocl.model
API provides classes such asClass
,Attribute
,Association
,Invariant
, etc. PyUseOCL is just based on hand-craft raw surface parser, so the content of operations and invariants is not made available.
an model evaluation API. The result of evaluation
.soil
files (i.e. object models) against.use
file (i.e. class model) is made available as a set of python objects (seepyuseocl.evaluation
).support for assertions. Assertions like the following can be added in .soil files as comments:
-- @assert MyClass::MyInvariant1 OK -- @assert MyClass::MyInvariant2 Failed -- @assert MyClass::MyInvariant6 OK
An evaluator is then is available to check which assertions are OK, KO or are failure. If needed, the result is readily available via an API (see
pyuseocl.assertion
)a simple testing framework providing for instance a class
TestSuite
.
Quick Start Guide¶
You should be able to install and try PyUseOCL in minutes (assuming that you have pip).
Installation¶
Just like nearly all python packages, PyUseOCL can be installed using pip:
$ pip install pyuseocl
You can also download the source from the PyUseOCL github project.
Command Line Interface¶
PyUseOCL provides a very simple Command Line Interface (CLI).
Compiling a class model¶
To compile a class model use:
python pyuse.py MyClassModel.use
This command launchs the use tool, parse the result and provide output in a slightly different format. Not a big deal.
Evaluating some states¶
To evaluate one or more object files against a model use:
python pyuse.py MyClassModel.use MyState1.soil MyState2.soil ...
This evaluate the assertions in each state files and report which one pass or not.
API¶
PyUseOCL is decomposed in the following modules.
pyuseocl |
Wrapper of the USE (OCL) tool. |
pyuseocl.useengine |
Wrapper to the USE engine. |
pyuseocl.analyzer |
This module allows to analyze a USE OCL .use source file: |
pyuseocl.model |
Partial AST for USE OCL Model. |
pyuseocl.printer |
Generate a USE OCL specification from a modeL. |
pyuseocl.converter |
Simple converter from canonical USE OCL expression (expressions returned by USE after parsing) to pyalaocl expression. |
pyuseocl.soil |
Interpreter of soil specifications. |
pyuseocl.state |
Simple metamodel for object states. |
pyuseocl.evaluation |
Model the result of the evaluation of a USE OCL state (a soil file) against a USE OCL model. |
pyuseocl.evaluator |
|
pyuseocl.assertion |
Add support for “assertions” in USE OCL. |
pyuseocl.tester |
|
pyuseocl.utils |
Utilities independent from the use tool. |
pyuseocl.utils.errors |
|
pyuseocl.utils.fragments |
|
pyuseocl.utils.sources |
|
pyuseocl.utils.zip |