Skip to content

Commit bde0a1e

Browse files
committed
Use doctests in README
1 parent 63eeb0a commit bde0a1e

3 files changed

Lines changed: 61 additions & 32 deletions

File tree

‎README.rst‎

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -98,63 +98,73 @@ to your working directory (or to any directory in your Python path).
9898
Usage
9999
-----
100100

101-
First, import the module::
101+
First, import the module:
102102

103-
import jack
103+
>>> import jack
104104

105-
Then, you most likely want to create a new JACK client::
105+
Then, you most likely want to create a new JACK client:
106106

107-
client = jack.Client("MyGreatClient")
107+
>>> client = jack.Client("MyGreatClient")
108108

109-
You probably want to create some input and output ports, too::
109+
You probably want to create some input and output ports, too:
110110

111-
client.inports.register("input_1")
112-
client.outports.register("output_1")
111+
>>> client.inports.register("input_1")
112+
jack.OwnPort('MyGreatClient:input_1')
113+
>>> client.outports.register("output_1")
114+
jack.OwnPort('MyGreatClient:output_1')
113115

114-
These functions return the newly created port, so you can save it for later::
116+
As you can see, these functions return the newly created port, so you can save
117+
it for later:
115118

116-
in2 = client.inports.register("input_2")
117-
out2 = client.outports.register("output_2")
119+
>>> in2 = client.inports.register("input_2")
120+
>>> out2 = client.outports.register("output_2")
118121

119122
To see what you can do with the returned objects, have a look at the
120123
documentation of the class `jack.OwnPort`.
121124

122-
You can also check what other JACK ports are available::
125+
You can also check what other JACK ports are available (your output may have
126+
additional ports in it):
123127

124-
portlist = client.get_ports()
128+
>>> client.get_ports() # doctest: +SKIP
129+
[jack.Port('system:capture_1'),
130+
jack.Port('system:capture_2'),
131+
jack.Port('system:playback_1'),
132+
jack.Port('system:playback_2'),
133+
jack.OwnPort('MyGreatClient:input_1'),
134+
jack.OwnPort('MyGreatClient:output_1'),
135+
jack.OwnPort('MyGreatClient:input_2'),
136+
jack.OwnPort('MyGreatClient:output_2')]
125137

126138
If you want, you can also set all kinds of callback functions, for details see
127139
the API documentation for the class `jack.Client`.
128140

129-
Once you are ready to run, you should activate your client::
141+
Once you are ready to run, you should activate your client:
130142

131-
client.activate()
143+
>>> client.activate()
132144

133145
Once the client is activated, you can make connections (this isn't possible
134-
before activating the client)::
146+
before activating the client):
135147

136-
client.connect("system:capture_1", "MyGreatClient:input_1")
137-
client.connect("MyGreatClient:output_1", "system:playback_1")
148+
>>> client.connect("system:capture_1", "MyGreatClient:input_1")
149+
>>> client.connect("MyGreatClient:output_1", "system:playback_1")
138150

139-
You can also use the port objects from before instead of port names::
151+
You can also use the port objects from before instead of port names:
140152

141-
client.connect(out2, "system:playback_2")
142-
in2.connect("system:capture_2")
153+
>>> client.connect(out2, "system:playback_2")
154+
>>> in2.connect("system:capture_2")
143155

144-
You can also disconnect ports, there are again several possibilities::
156+
You can also disconnect ports, there are again several possibilities:
145157

146-
client.disconnect("system:capture_1", "MyGreatClient:input_1")
147-
client.disconnect(out2, "system:playback_2")
148-
# disconnect all connections with in2:
149-
in2.disconnect()
158+
>>> client.disconnect("system:capture_1", "MyGreatClient:input_1")
159+
>>> client.disconnect(out2, "system:playback_2")
160+
>>> in2.disconnect() # disconnect all connections with in2
150161

151-
If you don't need your ports anymore, you can un-register them::
162+
If you don't need your ports anymore, you can un-register them:
152163

153-
in2.unregister()
154-
# unregister all output ports:
155-
client.outports.clear()
164+
>>> in2.unregister()
165+
>>> client.outports.clear() # unregister all output ports
156166

157-
Finally, you can de-activate your JACK client and close it::
167+
Finally, you can de-activate your JACK client and close it:
158168

159-
client.deactivate()
160-
client.close()
169+
>>> client.deactivate()
170+
>>> client.close()

‎pytest.ini‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[pytest]
2+
addopts = --doctest-glob=*.rst

‎setup.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
1+
import sys
12
from setuptools import setup
3+
from setuptools.command.test import test as TestCommand
4+
5+
class PyTest(TestCommand):
6+
def finalize_options(self):
7+
TestCommand.finalize_options(self)
8+
self.test_args = []
9+
self.test_suite = True
10+
11+
def run_tests(self):
12+
# import here, cause outside the eggs aren't loaded
13+
import pytest
14+
errno = pytest.main(self.test_args)
15+
sys.exit(errno)
16+
217

318
# "import" __version__
419
for line in open("jack.py"):
@@ -28,4 +43,6 @@
2843
"Programming Language :: Python :: 3",
2944
"Topic :: Multimedia :: Sound/Audio",
3045
],
46+
tests_require=['pytest'],
47+
cmdclass={'test': PyTest},
3148
)

0 commit comments

Comments
 (0)