Book Image

Learning Python Application Development

By : Ninad Sathaye
Book Image

Learning Python Application Development

By: Ninad Sathaye

Overview of this book

Python is one of the most widely used dynamic programming languages, supported by a rich set of libraries and frameworks that enable rapid development. But fast paced development often comes with its own baggage that could bring down the quality, performance, and extensibility of an application. This book will show you ways to handle such problems and write better Python applications. From the basics of simple command-line applications, develop your skills all the way to designing efficient and advanced Python apps. Guided by a light-hearted fantasy learning theme, overcome the real-world problems of complex Python development with practical solutions. Beginning with a focus on robustness, packaging, and releasing application code, you’ll move on to focus on improving application lifetime by making code extensible, reusable, and readable. Get to grips with Python refactoring, design patterns and best practices. Techniques to identify the bottlenecks and improve performance are covered in a series of chapters devoted to performance, before closing with a look at developing Python GUIs.
Table of Contents (18 chapters)
Learning Python Application Development
Credits
Disclaimers
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Writing unit tests for the application


It is time to write some unit tests for the application. We will make a new subclass of unittest.TestCase to hold all the unit tests.

Setting up a test package

As a first step, let's create a new package for holding the test cases. Create a new directory called test at the same level where you have the rest of the code. Next, create two new files inside this test directory, as shown here:

The test_wargame.py module is where new unit tests will be created. To recognize the directory as a Python package, add an empty __init__.py file.

Tip

If you haven't already, read Chapter 3, Modularize, Package, Deploy! for details on creating a Python package.

Creating a new class for unit testing

The test_wargame.py file can also be found in the supporting code. It has all the code to be discussed next. In the following discussion, it is assumed that you will code from scratch to an empty file.

Create a new subclass of unittest.TestCase, and call it TestWarGame or any name...