File: consumers.rst

package info (click to toggle)
tap.py 3.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 476 kB
  • sloc: python: 1,808; makefile: 164; sh: 40
file content (157 lines) | stat: -rw-r--r-- 4,694 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
TAP Consumers
=============

tappy Tool
----------

The ``tappy`` command line tool is a `TAP consumer
<http://testanything.org/consumers.html>`_.
The tool accepts TAP files or directories containing TAP files
and provides a standard Python ``unittest`` style summary report.
Check out ``tappy -h`` for the complete list of options.
You can also use the tool's shorter alias of ``tap``.

.. code-block:: console

    $ tappy *.tap
    ................F..................................
    ======================================================================
    FAIL: <file=TestParser.tap>
    - The parser extracts a bail out line.
    ----------------------------------------------------------------------

    ----------------------------------------------------------------------
    Ran 51 tests in 0.002s

    FAILED (failures=1)

TAP Stream
~~~~~~~~~~

``tappy`` can read a TAP stream directly STDIN.
This permits any TAP producer to pipe its results to ``tappy``
without generating intermediate output files.
``tappy`` will read from STDIN
when no arguments are provided
or when a dash character is the only argument.

Here is an example of ``nosetests`` piping to ``tappy``:

.. code-block:: console

    $ nosetests --with-tap --tap-stream 2>&1 | tappy
    ......................................................................
    ...............................................
    ----------------------------------------------------------------------
    Ran 117 tests in 0.003s

    OK

In this example,
``nosetests`` puts the TAP stream on STDERR
so it must be redirected to STDOUT
because the Unix pipe expects input on STDOUT.

``tappy`` can use redirected input
from a shell.

.. code-block:: console

    $ tappy < TestAdapter.tap
    ........
    ----------------------------------------------------------------------
    Ran 8 tests in 0.000s

    OK

This final example shows ``tappy`` consuming TAP
from Perl's test tool, ``prove``.
The example includes the optional dash character.

.. code-block:: console

    $ prove t/array.t -v | tappy -
    ............
    ----------------------------------------------------------------------
    Ran 12 tests in 0.001s

    OK

API
---

In addition to a command line interface, tappy enables programmatic access to
TAP files for users to create their own TAP consumers. This access comes in
two forms:

1. A ``Loader`` class which provides a ``load`` method to load a set of TAP
   files into a ``unittest.TestSuite``. The ``Loader`` can receive files or
   directories.

   .. code-block:: pycon

       >>> loader = Loader()
       >>> suite = loader.load(['foo.tap', 'bar.tap', 'baz.tap'])

2. A ``Parser`` class to provide a lower level interface. The ``Parser`` can
   parse a file via ``parse_file`` and return parsed lines that categorize the
   file contents.

   .. code-block:: pycon

       >>> parser = Parser()
       >>> for line in parser.parse_file('foo.tap'):
       ...     # Do whatever you want with the processed line.
       ...     pass

The API specifics are listed below.

.. autoclass:: tap.loader.Loader
   :members:

.. autoclass:: tap.parser.Parser
   :members:

.. _tap-version-13:

TAP version 13
~~~~~~~~~~~~~~

The specification for TAP version 13 adds support for `yaml blocks <https://testanything.org/tap-version-13-specification.html#yaml-blocks>`_
to provide additional information about the preceding test. In order to consume
yaml blocks, ``tappy`` requires `pyyaml <https://pypi.org/project/PyYAML/>`_ and
`more-itertools <https://pypi.org/project/more-itertools/>`_ to be installed.

These dependencies are optional. If they are not installed, TAP output will still
be consumed, but any yaml blocks will be parsed as :class:`tap.line.Unknown`. If a
:class:`tap.line.Result` object has an associated yaml block, :attr:`~tap.line.Result.yaml_block`
will return the block converted to a ``dict``. Otherwise, it will return ``None``.

``tappy`` provides a strict interpretation of the specification. A yaml block will
only be associated with a result if it immediately follows that result. Any 
:class:`diagnostic <tap.line.Diagnostic>` between a :class:`result <tap.line.Result>` and a yaml
block will result in the block lines being parsed as :class:`tap.line.Unknown`.

Line Categories
~~~~~~~~~~~~~~~

The parser returns ``Line`` instances. Each line contains different properties
depending on its category.

.. autoclass:: tap.line.Result
   :members:

.. autoclass:: tap.line.Plan
   :members:

.. autoclass:: tap.line.Diagnostic
   :members:

.. autoclass:: tap.line.Bail
   :members:

.. autoclass:: tap.line.Version
   :members:

.. autoclass:: tap.line.Unknown
   :members: