configurationengine/doc/plugins/dev-plugin/example-plugin.rst
author terytkon
Thu, 11 Mar 2010 17:04:37 +0200
changeset 0 2e8eeb919028
child 3 e7e0ae78773e
permissions -rw-r--r--
Adding EPL version of configurationengine.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     1
.. _plugin-howto-example-plugin:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     2
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     3
Example plug-in
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     4
===============
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     5
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     6
The example plug-in implements a simple Implementation Markup Language that can write
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     7
text files with possibly some content coming from ConfML setting values. The plug-in
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     8
demonstrates some recommended practices for developing ConE plug-ins:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     9
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    10
- Plug-in structure:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    11
    - Reader class
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    12
    - Implementation class
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    13
    - Implementation model
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    14
- Using ``cone.public.utils`` for ConfML setting reference handling
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    15
- Unit tests:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    16
    - Testing the reader class, the implementation class and the model classes separately
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    17
    - Output generation testing (plug-in scope integration test)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    18
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    19
The ExampleML language
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    20
----------------------
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    21
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    22
The Implementation Markup Language in the example plug-in is ExampleML. The language
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    23
offers a simple mechanism to write text files to the output directory. For example:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    24
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    25
.. code-block :: xml
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    26
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    27
    <?xml version="1.0" encoding="UTF-8"?>
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    28
    <exampleml xmlns="http://www.example.org/xml/exampleml/1">
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    29
        <output file="test1.txt" encoding="UTF-8">Test</output>
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    30
        <output file="some/dir/test2.txt" encoding="UTF-16">Test</output>
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    31
    </exampleml>
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    32
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    33
To demonstrate the use of ConfML setting references, the language supports also
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    34
those with the form ``${Feature.Setting}``. This is the usual way of using them
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    35
in implementation languages, and it is recommended to use the same convention
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    36
in all ImplMLs. For example:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    37
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    38
.. code-block :: xml
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    39
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    40
    <?xml version="1.0" encoding="UTF-8"?>
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    41
    <exampleml xmlns="http://www.example.org/xml/exampleml/1">
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    42
        <output file="${SomeFeature.OutputDir}/test2.txt"
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    43
                encoding="${SomeFeature.OutputEncoding}">
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    44
            Value from ConfML: ${SomeFeature.OutputText}
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    45
        </output>
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    46
    </exampleml>
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    47
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    48
.. _plugin-howto-example-plugin-dir-structure:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    49
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    50
Directory structure
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    51
-------------------
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    52
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    53
- ``plugins/`` - Root directory for all ConE plug-in sources
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    54
    - ``example/`` - Example plug-in package directory
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    55
        - ``ConeExamplePlugin/`` - Source for the example plug-in
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    56
            - ``examplemlplugin/`` - Module directory containing all plug-in code
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    57
                - ``tests/`` - Unit tests and test data for the plug-in
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    58
                    - ``project/`` - Configuration project used in the tests
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    59
                    - ``gen_expected/`` - Expected output for generation test case
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    60
                    - ``__init__.py`` - Test module initialization file
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    61
                    - ``runtests.py`` - Script for running all test cases
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    62
                    - ``unittest_exampleml_impl.py`` - File containing test cases
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    63
                    - ``unittest_exampleml_reader.py`` - File containing test cases
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    64
                    - ``unittest_exampleml_generation.py`` - File containing test cases
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    65
                - ``__init__.py`` - Plug-in module initialization file
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    66
                - ``exampleml_impl.py`` - Plug-in source file
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    67
                - ``exampleml_reader.py`` - Plug-in source file
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    68
            - ``setup.py`` - Setup script for packaging the plug-in into an .egg file
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    69
            - ``setup.cfg`` - Configuration file for ``setup.py``
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    70
        - ``integration-test/`` - Integration tests for the example plug-in package
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    71
            - ``testdata/`` - Test data for the integration tests
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    72
            - ``__init__.py`` - Test module initialization file
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    73
            - ``runtests.py`` - Script for running all test cases
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    74
            - ``export_standalone.py`` - Script for exporting extra data for standalone test export
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    75
            - ``unittest_generate.py`` - File containing test cases
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    76
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    77
Logical structure
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    78
-----------------
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    79
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    80
Logically the plug-in is divided into three parts:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    81
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    82
- *Implementation model*, represents the logical model of the implementation specified in the XML data
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    83
- *Implementation class*, works as the interface of the plug-in towards ConE and uses the model to do the actual work
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    84
- *Implementation reader*, converts the XML data into the logical model and creates a new implementation class instance
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    85
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    86
In this case the *model* consists just of the class Output, which corresponds to the ``<output>`` element.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    87
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    88
Plug-in code
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    89
------------
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    90
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    91
exampleml_model.py
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    92
..................
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    93
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    94
This file defines the ``Output`` class, which comprises the whole implementation model
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    95
in this case. The class contains the same attributes as its XML element counterpart:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    96
file, encoding and text, as well as the methods for generating output from the
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    97
``Output`` object.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    98
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    99
.. literalinclude:: /../source/plugins/example/ConeExamplePlugin/examplemlplugin/exampleml_model.py
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   100
   :linenos:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   101
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   102
Notice the use of ``cone.public.utils`` to handle the ConfML settings references. Usage of
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   103
setting refs is common enough to warrant a set of functions related to their handling in ``utils``.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   104
It is strongly recommended to use these utility functions instead of creating your own.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   105
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   106
.. note::
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   107
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   108
    The expanding of ConfML setting references is done here, in the ``Output`` object, instead of in the reader
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   109
    when the implementation is parsed. If it was done in the parsing phase, ConfML setting values changed
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   110
    in rules would not be expanded to their new values.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   111
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   112
Another noteworthy thing is that the ``Output`` class implements the methods ``__eq__()``,
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   113
``__ne__()`` and ``__repr__()``. These have no real use in the actual implementation, but they
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   114
make unit testing easier, as will be seen later on.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   115
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   116
The logic for creating the output is here encoded directly in the model, but in cases where
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   117
the model is more complex, it may be necessary to create a separate writer class, particularly
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   118
if there is more than one output format to be created based on the same model.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   119
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   120
exampleml_impl.py
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   121
.................
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   122
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   123
This file defines the implementation class. As can be seen, the class is quite simple, since
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   124
it uses the model class to do the actual work and only works as an interface towards ConE.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   125
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   126
.. literalinclude:: /../source/plugins/example/ConeExamplePlugin/examplemlplugin/exampleml_impl.py
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   127
   :linenos:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   128
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   129
exampleml_reader.py
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   130
...................
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   131
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   132
This file defines the reader class. Note how the reading of a single element is given its
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   133
own method. Again, this is to make unit testing easier.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   134
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   135
.. literalinclude:: /../source/plugins/example/ConeExamplePlugin/examplemlplugin/exampleml_reader.py
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   136
   :linenos:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   137
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   138
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   139
Unit tests
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   140
----------
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   141
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   142
Due to the dynamic nature of Python, an extensive set of unit tests is required for every plug-in.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   143
The unit tests for a ConE plug-in should be in a ``tests`` module (directory) under the plug-in's
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   144
main module directory, and contain a set ``unittests_*.py`` files. The naming here is important,
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   145
since the ``runtests.py`` file used to run all the unit tests at once collects test cases only
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   146
from .py files starting with ``unittest_``.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   147
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   148
Unit tests can be executed by running each individual unit test file separately using "Run as" -> "Python unit-test" or
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   149
all of the plug-in's unit tests at once by using "Run as" -> "Python run" on ``runtests.py``.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   150
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   151
.. image:: run_unittest.png
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   152
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   153
*Running a single unit test file*
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   154
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   155
It is recommended (well, actually required) to make sure that all unit tests pass before committing changes made to
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   156
the code of any plug-in. Also, it should be checked that all of the plug-in's unit tests pass when run as part
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   157
of all plug-in unit tests. It is possible that tests that pass when running ``runtests.py`` fail when running them
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   158
as part of the whole plug-in test set, as in that case the working directory is not the same. The entire plug-in test
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   159
set can be run from ``source/plugins/tests/runtests.py``.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   160
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   161
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   162
unittest_exampleml_reader.py
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   163
............................
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   164
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   165
This file tests that the reader class functions properly. See how there is a test case for reading
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   166
a single ``<output>`` element that tests all the special cases there, and then another that
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   167
tests the top-level reader method. Here it becomes obvious why it is worthwhile to implement the
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   168
``__eq__()`` etc. methods in model classes, as in the tests we can just give the parser an XML
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   169
string and specify exactly what kind of a Python object is expected to be parsed from it.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   170
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   171
.. literalinclude:: /../source/plugins/example/ConeExamplePlugin/examplemlplugin/tests/unittest_exampleml_reader.py
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   172
   :linenos:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   173
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   174
unittest_exampleml_impl.py
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   175
..........................
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   176
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   177
This file tests that the implementation class works as expected. The methods to test are ``has_ref()``
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   178
and ``list_output_files()``, since it is vital for the plug-in's correct operation that these methods
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   179
do what they are supposed to. Note that ``generate()`` is not tested here, as it is tested in its own
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   180
file.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   181
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   182
.. literalinclude:: /../source/plugins/example/ConeExamplePlugin/examplemlplugin/tests/unittest_exampleml_impl.py
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   183
   :linenos:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   184
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   185
unittest_exampleml_generation.py
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   186
................................
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   187
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   188
This file tests that the plug-in works correctly throughout its lifecycle, so it works as an integration test.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   189
Note that plug-in instances are not created manually, but an implementation container is created from the project.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   190
This means that the test also makes sure that the plug-in interoperates correctly with ConE's plug-in machinery.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   191
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   192
Also note that the output is checked against an expected set of files using the method ``assert_dir_contents_equal()``,
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   193
which comes from a unit test base class defined in a special ``testautomation`` module. This module contains also other
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   194
helper methods for use in unit tests, so if you need something more sophisticated than the simple methods provided
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   195
by the ``unittest`` module, you should check the ``testautomation`` module before writing the methods yourself.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   196
The module can be found under ``source/``.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   197
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   198
Notice also how the generation output directory is set to be in a ``temp/`` directory in the same directory
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   199
as the test .py file is. It is recommended to keep all temporary test data in a single place like this, so that
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   200
they don't litter e.g. the current working directory. When using a single ``temp/`` directory, it can also be
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   201
ignored in version control to avoid unnecessarily listing the temporary data when checking for modification in
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   202
the workding copy.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   203
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   204
.. literalinclude:: /../source/plugins/example/ConeExamplePlugin/examplemlplugin/tests/unittest_exampleml_generation.py
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   205
   :linenos:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   206
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   207
Plug-in packaging
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   208
-----------------
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   209
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   210
The file ``setup.py`` handles the packaging of the plug-in into an egg file.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   211
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   212
The most important thing here is the plug-in's entry point info. The
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   213
plug-in's reader classes must be specified as entry points, or they won't be
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   214
loaded.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   215
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   216
.. literalinclude:: /../source/plugins/example/ConeExamplePlugin/setup.py
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   217
   :linenos:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   218
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   219
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   220
.. _plugin-howto-example-plugin-integration-tests:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   221
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   222
Integration tests
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   223
-----------------
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   224
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   225
In addition to the unit tests inside the plug-in itself there is a separate integration test set.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   226
The purpose of these tests is to make sure that the plug-ins in the package work properly
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   227
together with other implementations from the CLI level. E.g. a common case that is good to
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   228
test is to check that ConfML settings changed in rules affect the implementations using
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   229
references to those settings work properly.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   230
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   231
These tests are also exported as part of the standalone test set used to test a pre-built
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   232
ConE distribution (see :ref:`installation-export-tests`). This affects the way some things
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   233
are handled in the test cases, for example the way the command to run is determined.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   234
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   235
The integration test set is plug-in package specific, not plug-in specific, so the test
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   236
project(s) used there should contain implementations of all the implementation languages
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   237
provided by the plug-ins in the package. Of course, in this case there are only ExampleML
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   238
implementations, since the example plug-in is the only plug-in in the example package.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   239
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   240
runtests.py
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   241
...........
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   242
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   243
This file simply acts as a shortcut to run all test cases easily.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   244
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   245
__init__.py
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   246
...........
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   247
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   248
This file performs all integration test specific initialization using the plug-in utility
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   249
functions in the root ``plugins/`` directory. Note that when the integration test set is
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   250
exported as standalone, the contents of this file are erased (the integration test
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   251
initialization cannot be done there, since the full ConE source is not available). Because
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   252
of this, you should not put anything that is always needed in this file.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   253
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   254
export_standalone.py
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   255
....................
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   256
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   257
This file contains a function for exporting any needed extra data into the standalone test
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   258
set (e.g. something from under the plug-in sources). The file doesn't necessarily need to
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   259
exist if there is no extra data in need of exporting, but in this example it exists to show
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   260
what could be done in it.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   261
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   262
.. literalinclude:: /../source/plugins/example/integration-test/export_standalone.py
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   263
   :linenos:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   264
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   265
unittest_generate.py
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   266
....................
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   267
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   268
This file contains tests for generating output using the example plug-in.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   269
Note the following things:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   270
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   271
- The use of the variable ``CONE_CMD`` in ``get_cmd()``. This variable is set to
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   272
  contain the actual ConE command to run if the tests are being run from the
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   273
  exported standalone test set. In practice this will be something like
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   274
  ``C:/cone_test/cone/cone.cmd``.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   275
- The actual generation and testing is done in a separate function, ``run_test_generate()``,
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   276
  and there are two actual test functions that call it. One runs the test directly on the
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   277
  test project on the file system, and another first zips the test project and then runs
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   278
  the test on that. It is a good idea to test that generation works the same in both cases,
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   279
  since it can be easy to forget to take into account generation from a ZIP file when creating
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   280
  a plug-in (e.g. using ``shutil`` functions to perform copy operations when the ConE API
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   281
  should be used).
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   282
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   283
.. literalinclude:: /../source/plugins/example/integration-test/unittest_generate.py
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   284
   :linenos: