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
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Python GUI Programming with Tkinter

You're reading from   Python GUI Programming with Tkinter Develop responsive and powerful GUI applications with Tkinter

Arrow left icon
Product type Paperback
Published in May 2018
Publisher Packt
ISBN-13 9781788835886
Length 452 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Alan D. Moore Alan D. Moore
Author Profile Icon Alan D. Moore
Alan D. Moore
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Preface 1. Introduction to Tkinter FREE CHAPTER 2. Designing GUI Applications with Tkinter 3. Creating Basic Forms with Tkinter and ttk Widgets 4. Reducing User Error with Validation and Automation 5. Planning for the Expansion of Our Application 6. Creating Menus with Menu and Tkinter Dialogs 7. Navigating Records with Treeview 8. Improving the Look with Styles and Themes 9. Maintaining Cross-Platform Compatibility 10. Creating Automated Tests with unittest 11. Improving Data Storage with SQL 12. Connecting to the Cloud 13. Asynchronous Programming with Thread and Queue 14. Visualizing Data Using the Canvas Widget 15. Packaging with setuptools and cx_Freeze 16. Other Books You May Enjoy

Writing tests for our application


Let's put our knowledge of unittest to work and write some tests for our application. To get started, we need to create a test module for our application. Make a directory called test inside the abq_data_entry package, and create the customary empty __init__.py file inside. We'll create all of our test modules inside this directory.

Testing our model

Our CSVModel code is fairly self-contained apart from its need to read and write files. Since file operations are one of the more common things that need to be mocked out in a test, the mock module provides mock_open, a Mock subclass ready-made to replace Python's open method. When called, a mock_open object returns a mock file handle object, complete with support for the read(), write(), and readlines() methods.

Let's begin creating our test case class in test/test_models.py as follows:

from .. import models
from unittest import TestCase
from unittest import mock

class TestCSVModel(TestCase):
    def setUp(self...
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