Submit Search
Upload
using python module: doctest
•
Download as ODP, PDF
•
2 likes
•
2,243 views
M
mitnk
Follow
How to use the python module of doctest.
Read less
Read more
Technology
Report
Share
Report
Share
1 of 20
Download now
Recommended
Lean & Mean Tokyo Cabinet Recipes (with Lua) - FutureRuby '09
Lean & Mean Tokyo Cabinet Recipes (with Lua) - FutureRuby '09
Ilya Grigorik
An Introduction to Solr
An Introduction to Solr
tomhill
Python - Getting to the Essence - Points.com - Dave Park
Python - Getting to the Essence - Points.com - Dave Park
pointstechgeeks
How Xslate Works
How Xslate Works
Goro Fuji
HTTP and Your Angry Dog
HTTP and Your Angry Dog
Ross Tuck
The worst Ruby codes I’ve seen in my life - RubyKaigi 2015
The worst Ruby codes I’ve seen in my life - RubyKaigi 2015
Fernando Hamasaki de Amorim
PHP applications/environments monitoring: APM & Pinba
PHP applications/environments monitoring: APM & Pinba
Patrick Allaert
typemap in Perl/XS
typemap in Perl/XS
charsbar
Recommended
Lean & Mean Tokyo Cabinet Recipes (with Lua) - FutureRuby '09
Lean & Mean Tokyo Cabinet Recipes (with Lua) - FutureRuby '09
Ilya Grigorik
An Introduction to Solr
An Introduction to Solr
tomhill
Python - Getting to the Essence - Points.com - Dave Park
Python - Getting to the Essence - Points.com - Dave Park
pointstechgeeks
How Xslate Works
How Xslate Works
Goro Fuji
HTTP and Your Angry Dog
HTTP and Your Angry Dog
Ross Tuck
The worst Ruby codes I’ve seen in my life - RubyKaigi 2015
The worst Ruby codes I’ve seen in my life - RubyKaigi 2015
Fernando Hamasaki de Amorim
PHP applications/environments monitoring: APM & Pinba
PHP applications/environments monitoring: APM & Pinba
Patrick Allaert
typemap in Perl/XS
typemap in Perl/XS
charsbar
Elegant concurrency
Elegant concurrency
Mosky Liu
The Ring programming language version 1.8 book - Part 45 of 202
The Ring programming language version 1.8 book - Part 45 of 202
Mahmoud Samir Fayed
JFokus 50 new things with java 8
JFokus 50 new things with java 8
José Paumard
Unit Testing Lots of Perl
Unit Testing Lots of Perl
Workhorse Computing
Test::Base
Test::Base
Tatsuhiko Miyagawa
Lambdas and Streams Master Class Part 2
Lambdas and Streams Master Class Part 2
José Paumard
Effective Benchmarks
Effective Benchmarks
Workhorse Computing
Bringing modern PHP development to IBM i (ZendCon 2016)
Bringing modern PHP development to IBM i (ZendCon 2016)
James Titcumb
Implementing pattern-matching in JavaScript (short version)
Implementing pattern-matching in JavaScript (short version)
François-Guillaume Ribreau
On UnQLite
On UnQLite
charsbar
Advanced Perl Techniques
Advanced Perl Techniques
Dave Cross
Java SE 8 for Java EE developers
Java SE 8 for Java EE developers
José Paumard
Rhebok, High Performance Rack Handler / Rubykaigi 2015
Rhebok, High Performance Rack Handler / Rubykaigi 2015
Masahiro Nagano
PL/Perl - New Features in PostgreSQL 9.0 201012
PL/Perl - New Features in PostgreSQL 9.0 201012
Tim Bunce
Use PEG to Write a Programming Language Parser
Use PEG to Write a Programming Language Parser
Yodalee
Python在豆瓣的应用
Python在豆瓣的应用
Qiangning Hong
50 new things we can do with Java 8
50 new things we can do with Java 8
José Paumard
What you need to remember when you upload to CPAN
What you need to remember when you upload to CPAN
charsbar
Python高级编程(二)
Python高级编程(二)
Qiangning Hong
Intro To Spring Python
Intro To Spring Python
gturnquist
Test driven development_for_php
Test driven development_for_php
Lean Teams Consultancy
Intro to Testing in Zope, Plone
Intro to Testing in Zope, Plone
Quintagroup
More Related Content
What's hot
Elegant concurrency
Elegant concurrency
Mosky Liu
The Ring programming language version 1.8 book - Part 45 of 202
The Ring programming language version 1.8 book - Part 45 of 202
Mahmoud Samir Fayed
JFokus 50 new things with java 8
JFokus 50 new things with java 8
José Paumard
Unit Testing Lots of Perl
Unit Testing Lots of Perl
Workhorse Computing
Test::Base
Test::Base
Tatsuhiko Miyagawa
Lambdas and Streams Master Class Part 2
Lambdas and Streams Master Class Part 2
José Paumard
Effective Benchmarks
Effective Benchmarks
Workhorse Computing
Bringing modern PHP development to IBM i (ZendCon 2016)
Bringing modern PHP development to IBM i (ZendCon 2016)
James Titcumb
Implementing pattern-matching in JavaScript (short version)
Implementing pattern-matching in JavaScript (short version)
François-Guillaume Ribreau
On UnQLite
On UnQLite
charsbar
Advanced Perl Techniques
Advanced Perl Techniques
Dave Cross
Java SE 8 for Java EE developers
Java SE 8 for Java EE developers
José Paumard
Rhebok, High Performance Rack Handler / Rubykaigi 2015
Rhebok, High Performance Rack Handler / Rubykaigi 2015
Masahiro Nagano
PL/Perl - New Features in PostgreSQL 9.0 201012
PL/Perl - New Features in PostgreSQL 9.0 201012
Tim Bunce
Use PEG to Write a Programming Language Parser
Use PEG to Write a Programming Language Parser
Yodalee
Python在豆瓣的应用
Python在豆瓣的应用
Qiangning Hong
50 new things we can do with Java 8
50 new things we can do with Java 8
José Paumard
What you need to remember when you upload to CPAN
What you need to remember when you upload to CPAN
charsbar
Python高级编程(二)
Python高级编程(二)
Qiangning Hong
Intro To Spring Python
Intro To Spring Python
gturnquist
What's hot
(20)
Elegant concurrency
Elegant concurrency
The Ring programming language version 1.8 book - Part 45 of 202
The Ring programming language version 1.8 book - Part 45 of 202
JFokus 50 new things with java 8
JFokus 50 new things with java 8
Unit Testing Lots of Perl
Unit Testing Lots of Perl
Test::Base
Test::Base
Lambdas and Streams Master Class Part 2
Lambdas and Streams Master Class Part 2
Effective Benchmarks
Effective Benchmarks
Bringing modern PHP development to IBM i (ZendCon 2016)
Bringing modern PHP development to IBM i (ZendCon 2016)
Implementing pattern-matching in JavaScript (short version)
Implementing pattern-matching in JavaScript (short version)
On UnQLite
On UnQLite
Advanced Perl Techniques
Advanced Perl Techniques
Java SE 8 for Java EE developers
Java SE 8 for Java EE developers
Rhebok, High Performance Rack Handler / Rubykaigi 2015
Rhebok, High Performance Rack Handler / Rubykaigi 2015
PL/Perl - New Features in PostgreSQL 9.0 201012
PL/Perl - New Features in PostgreSQL 9.0 201012
Use PEG to Write a Programming Language Parser
Use PEG to Write a Programming Language Parser
Python在豆瓣的应用
Python在豆瓣的应用
50 new things we can do with Java 8
50 new things we can do with Java 8
What you need to remember when you upload to CPAN
What you need to remember when you upload to CPAN
Python高级编程(二)
Python高级编程(二)
Intro To Spring Python
Intro To Spring Python
Similar to using python module: doctest
Test driven development_for_php
Test driven development_for_php
Lean Teams Consultancy
Intro to Testing in Zope, Plone
Intro to Testing in Zope, Plone
Quintagroup
Testing My Patience
Testing My Patience
Adam Lowry
What is wrong on Test::More? / Test::Moreが抱える問題点とその解決策
What is wrong on Test::More? / Test::Moreが抱える問題点とその解決策
kwatch
Groovy
Groovy
Zen Urban
Java Boilerplate Busters
Java Boilerplate Busters
HamletDRC
Micro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicate
Kiev ALT.NET
SDC - Einführung in Scala
SDC - Einführung in Scala
Christian Baranowski
Scala 2 + 2 > 4
Scala 2 + 2 > 4
Emil Vladev
Scala introduction
Scala introduction
Alf Kristian Støyle
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008
Guillaume Laforge
GE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python Programming
Muthu Vinayagam
Round PEG, Round Hole - Parsing Functionally
Round PEG, Round Hole - Parsing Functionally
Sean Cribbs
Introduction to Client-Side Javascript
Introduction to Client-Side Javascript
Julie Iskander
Post Sharp Talk
Post Sharp Talk
willmation
Java operators
Java operators
Shehrevar Davierwala
Navigating the xDD Alphabet Soup
Navigating the xDD Alphabet Soup
Dror Helper
Java Script Workshop
Java Script Workshop
Dmitry Baranovskiy
Introduction to Protractor
Introduction to Protractor
Jie-Wei Wu
ITT 2015 - Saul Mora - Object Oriented Function Programming
ITT 2015 - Saul Mora - Object Oriented Function Programming
Istanbul Tech Talks
Similar to using python module: doctest
(20)
Test driven development_for_php
Test driven development_for_php
Intro to Testing in Zope, Plone
Intro to Testing in Zope, Plone
Testing My Patience
Testing My Patience
What is wrong on Test::More? / Test::Moreが抱える問題点とその解決策
What is wrong on Test::More? / Test::Moreが抱える問題点とその解決策
Groovy
Groovy
Java Boilerplate Busters
Java Boilerplate Busters
Micro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicate
SDC - Einführung in Scala
SDC - Einführung in Scala
Scala 2 + 2 > 4
Scala 2 + 2 > 4
Scala introduction
Scala introduction
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008
GE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python Programming
Round PEG, Round Hole - Parsing Functionally
Round PEG, Round Hole - Parsing Functionally
Introduction to Client-Side Javascript
Introduction to Client-Side Javascript
Post Sharp Talk
Post Sharp Talk
Java operators
Java operators
Navigating the xDD Alphabet Soup
Navigating the xDD Alphabet Soup
Java Script Workshop
Java Script Workshop
Introduction to Protractor
Introduction to Protractor
ITT 2015 - Saul Mora - Object Oriented Function Programming
ITT 2015 - Saul Mora - Object Oriented Function Programming
Recently uploaded
ECS 2024 Teams Premium - Pretty Secure
ECS 2024 Teams Premium - Pretty Secure
Femke de Vroome
Syngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdf
Syngulon
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
John Staveley
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
CzechDreamin
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
FIDO Alliance
Connecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAK
UXDXConf
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1
DianaGray10
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
Jennifer Lim
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
CzechDreamin
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
confluent
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Julian Hyde
AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101
vincent683379
Buy Epson EcoTank L3210 Colour Printer Online.pdf
Buy Epson EcoTank L3210 Colour Printer Online.pdf
EasyPrinterHelp
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024
IoTAnalytics
Strategic AI Integration in Engineering Teams
Strategic AI Integration in Engineering Teams
UXDXConf
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
FIDO Alliance
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
CzechDreamin
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
FIDO Alliance
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through Observability
ScyllaDB
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
IES VE
Recently uploaded
(20)
ECS 2024 Teams Premium - Pretty Secure
ECS 2024 Teams Premium - Pretty Secure
Syngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdf
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
Connecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAK
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101
Buy Epson EcoTank L3210 Colour Printer Online.pdf
Buy Epson EcoTank L3210 Colour Printer Online.pdf
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024
Strategic AI Integration in Engineering Teams
Strategic AI Integration in Engineering Teams
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through Observability
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
using python module: doctest
1.
doctest Testing through
documentation Honggang Wang @ Aragon Nov 2010
2.
3.
def multiply(a, b):
4.
“””
5.
This is a
demo function.
6.
>>> multiply(3, 4)
7.
12
8.
>>> multiply('a', 5)
9.
'aaaaa'
10.
“””
11.
12.
$ python -v
foo.py
13.
$ python -m
doctest -v foo.py
14.
Trying:
15.
multiply(3, 4)
16.
Expecting:
17.
12
18.
ok
19.
...
20.
2 passed and
0 failed.
21.
22.
23.
Object ids
24.
Precision of float
values
25.
Exceptions
26.
And more...
27.
28.
class A(object):
29.
pass
30.
def gene_list(obj):
31.
“””
32.
Put obj into
a list.
33.
>>> gene_list(A())
34.
[<unpredictable.A object at
0x9c2214c>]
35.
“””
36.
return [obj]
37.
38.
class A(object):
39.
pass
40.
def gene_list(obj):
41.
“””
42.
Put obj into
a list.
43.
>>> gene_list(A())
#doctest: +ELLIPSIS
44.
[<unpredictable2.A object at
0x...>]
45.
“””
46.
return [obj]
47.
48.
def double_space(lines):
49.
"""Prints a list
of lines double-spaced.
50.
>>> double_space(['Line one.',
'Line two.'])
51.
Line one.
52.
Line two.
53.
"""
54.
for l in
lines:
55.
print l
56.
print
57.
return
58.
59.
def double_space(lines):
60.
"""Prints a list
of lines double-spaced.
61.
>>> double_space(['Line one.',
'Line two.'])
62.
Line one.
63.
<BLANKLINE>
64.
Line two.
65.
<BLANKLINE>
66.
"""
67.
for l in
lines:
68.
print l
69.
print
70.
return
71.
72.
“””
73.
>>> A ==
B
74.
False
75.
“””
76.
class A(object): pass
77.
class B(object): pass
78.
79.
from b_cls import
B
80.
__test__ = {
81.
'test001': “””
82.
>>> A.__class__
83.
<type 'type'>
84.
“”” ,
85.
'external': B,
86.
}
87.
class A(object):
88.
89.
“””
90.
>>> 1 +
1
91.
3
92.
“””
93.
class B(object):
94.
“”” The
class B.
95.
>>> B.__name__
96.
B
97.
“””
98.
pass
99.
100.
def multiply(a, b):
101.
102.
How to use
foo2.py
103.
===============
104.
For numbers:
105.
>>> from foo2
import multiply
106.
>>> multiply(3, 7)
107.
21
108.
It also works
with strings:
109.
>>> multiply('s', 7)
110.
111.
112.
113.
def add(a, b):
114.
return a +
b
115.
if __name__ ==
“__main__”:
116.
import doctest
117.
118.
import utils
119.
if __name__ ==
“__main__”:
120.
import doctest
121.
doctest.testmod(utils)
122.
123.
import doctest
124.
if __name__ ==
“__main__”:
125.
126.
127.
import doctest
128.
import unittest
129.
import doctest_simple
130.
suite = unittest.TestSuite()
131.
suite.addTest(doctest.DocTestSuite(doctest_simple))
132.
suite.addTest(doctest.DocFileSuite('doctest_in_help.rst'))
133.
runner = unittest.TextTestRunner(verbosity=2)
134.
runner.run(suite)
135.
136.
my_function (doctest_simple)
137.
Doctest: doctest_simple.my_function ...
ok
138.
doctest_in_help.rst
139.
Doctest: doctest_in_help.rst ...
ok
140.
----------------------------------------------------------------------
141.
Ran 2 tests
in 0.006s
142.
OK
143.
144.
def one(self):
145.
"""
146.
>>> var =
'value'
147.
>>> 'var' in
globals()
148.
True
149.
"""
150.
def two(self):
151.
"""
152.
>>> 'var' in
globals()
153.
False
154.
155.
156.
Trying:
157.
var = 'value'
158.
Expecting nothing
159.
ok
160.
...
161.
2 items passed
all tests:
162.
2 tests in
doctest_test_globals.TestGlobals.one
163.
1 tests in
doctest_test_globals.TestGlobals.two
164.
3 tests in
4 items.
165.
3 passed and
0 failed.
166.
Test passed.
167.
168.
class TestGlobals(object):
169.
def one(self):
170.
"""
171.
>>> TestGlobals().one()
172.
>>> 'var' in
_module_data
173.
True
174.
"""
175.
_module_data['var'] = 'value'
176.
def two(self):
177.
"""
178.
>>> 'var' in
_module_data
179.
False
180.
"""
181.
182.
...
183.
Failed example:
184.
'var' in _module_data
185.
Expected:
186.
False
187.
Got:
188.
True
189.
...
190.
3 tests in
4 items.
191.
2 passed and
1 failed.
192.
***Test Failed*** 1
failures.
193.
Thanks!
Download now