moved test_memento from structural tests to behavioral tests.

This commit is contained in:
tylerlaberge
2016-08-28 21:16:12 -04:00
parent 3a5bfc03b1
commit 7d0c1b9cf3

View File

@@ -0,0 +1,65 @@
from unittest import TestCase
from pypatterns.behavioral.memento import Memento, Originator
class MementoTestCase(TestCase):
"""
Unit testing class for the Memento Class.
"""
def setUp(self):
"""
Initialize testing data.
"""
self.state = {'foo': 'bar'}
def test_init(self):
"""
Test the __init__ method.
@raise AssertionError: If the test fails.
"""
memento = Memento(self.state)
self.assertEqual(memento.state, self.state)
class OriginatorTestCase(TestCase):
"""
Unit testing class for the Originator class.
"""
def setUp(self):
"""
Initialize testing data.
"""
class Cat(Originator):
def __init__(self, name):
self.name = name
self.cat_class = Cat
def test_commit(self):
"""
Test the commit method.
@raise AssertionError: If the test fails.
"""
cat = self.cat_class('Tom')
cat_memento = cat.commit()
self.assertDictEqual(cat.__dict__, cat_memento.state)
def test_rollback(self):
"""
Test the rollback method.
@raise AssertionError: If the test fails.
"""
cat = self.cat_class('Tom')
cat_memento = cat.commit()
cat.name = 'jerry'
cat.rollback(cat_memento)
self.assertEqual('Tom', cat.name)