Skip to content

Instantly share code, notes, and snippets.

@Gautier
Created February 7, 2012 12:56
Show Gist options
  • Save Gautier/1759559 to your computer and use it in GitHub Desktop.
Save Gautier/1759559 to your computer and use it in GitHub Desktop.
DaltonTestCase
import os
import dalton
from django.test import TestCase
from django.conf import settings
class DaltonTestCase(TestCase):
ROOT_DIR = os.path.join(os.path.abspath(os.path.dirname(__file__)),
"replay")
@classmethod
def dalton_inject(cls):
if not hasattr(cls, "_dalton_injected"):
cls._dalton_injected = True
dalton.inject()
def setUp(self):
""" I put the dalton instance in a member variable as each test is run
one after the other. This means that they won't interfere between
them"""
DaltonTestCase.dalton_inject()
test_id = self.id().replace(".", "_")
self.test_replay_dir = os.path.join(DaltonTestCase.ROOT_DIR, test_id)
try:
if settings.DALTON_SETTING == "record":
self._dalton = dalton.Recorder(use_global=True)
self._dalton.start()
elif settings.DALTON_SETTING == "play":
self._dalton = dalton.Player(use_global=True,
playback_dir=self.test_replay_dir)
self._dalton.play()
except:
print "we've got a failure with", test_id
raise
def tearDown(self):
if settings.DALTON_SETTING == "record":
self._dalton.save(self.test_replay_dir)
self._dalton.stop()
elif settings.DALTON_SETTING == "play":
self._dalton.stop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment