Skip to Content
Python GUI Programming with Tkinter
book

Python GUI Programming with Tkinter

by Alan D. Moore
May 2018
Beginner to intermediate content levelBeginner to intermediate
452 pages
11h 26m
English
Packt Publishing
Content preview from Python GUI Programming with Tkinter

Testing file reading in get_all_records()

To see how we use these, let's start a test for the get_all_records() method as follows:

    @mock.patch('abq_data_entry.models.os.path.exists')
    def test_get_all_records(self, mock_exists):
        mock_exists.return_value = True

Since our filenames don't actually exist, we're using the decorator version of patch to patch os.path.exists with a mock function that always returns True. We can later change the return_value value if we want to test a scenario where the file doesn't exist.

To run the get_all_records() method, we'll use the context manager form of patch() as follows:

        with mock.patch('abq_data_entry.models.open', self.file1_open):
            records = self.model1.get_all_records()

Any call to open() inside the ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python GUI Programming with Tkinter - Second Edition

Python GUI Programming with Tkinter - Second Edition

Alan D. Moore

Publisher Resources

ISBN: 9781788835886Supplemental Content