Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Python for Secret Agents

You're reading from   Python for Secret Agents Analyze, encrypt, and uncover intelligence data using Python, the essential tool for all aspiring secret agents

Arrow left icon
Product type Paperback
Published in Aug 2014
Publisher
ISBN-13 9781783980420
Length 216 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Steven F. Lott Steven F. Lott
Author Profile Icon Steven F. Lott
Steven F. Lott
Arrow right icon
View More author details
Toc

Writing high-quality software


How do we know these various statistical functions work? This is potentially very tricky programming, with lots of opportunities to have things go wrong.

The best tool to make sure that software works is unit testing. The idea behind unit testing is to break a module down into separate units—usually functions or classes—and test each unit in isolation. Python gives us two ways to perform unit testing:

  • Putting examples into docstrings for modules, functions, and classes

  • Writing separate unittest.TestCase classes

Most secret agents will be very happy with docstring test cases. They're easy to write. We put them in the docstring right in front of the rest of the code. They're visible when we use the help() function.

We create these docstring test cases by copying and pasting known correct results from interactive Python. The copy and paste will include the >>> prompt to make it easy to find the examples. Of course, we also include the output that's expected...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image