O'Reilly logo

Python Testing Beginner's Guide by Daniel Arbuckle

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Writing persistence tests

Since I don't have any actual unit tests for the persistence code yet, I'll start off by making some. In the process, I have to figure how persistence will actually work. The following code goes in tests/test_persistence.py:

from unittest import TestCase from mocker import MockerTestCase from planner.persistence import file class test_file(TestCase): def test_basic(self): storage = file(':memory:') storage.store_object('tag1', ('some object',)) self.assertEqual(tuple(storage.load_objects('tag1')), (('some object',),)) def test_multiple_tags(self): storage = file(':memory:') storage.store_object('tag1', 'A') storage.store_object('tag2', 'B') storage.store_object('tag1', 'C') storage.store_object('tag1', 'D') storage.store_object('tag3', ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required