Commits

jpellerin  committed bf78fa8

Added simple test for prof plugin

  • Participants
  • Parent commits 9dcf7f7

Comments (0)

Files changed (2)

File nose2/tests/_common.py

     def __init__(self, names):
         super(FakeLoadFromNamesEvent, self).__init__()
         self.names = names
+
+
+class FakeStartTestRunEvent(_FakeEventBase):
+    """Fake StartTestRunEvent"""
+    def __init__(self, runner=None, suite=None, result=None, startTime=None,
+                 executeTests=None):
+        super(FakeStartTestRunEvent, self).__init__()
+        self.suite = suite
+        self.runner = runner
+        self.result = result
+        self.startTime = startTime
+        self.executeTests = executeTests
+
+
+class Stub(object):
+    """Stub object for use in tests"""

File nose2/tests/test_prof_plugin.py

+import unittest2
+
+from ..plugins import prof
+from ._common import Stub, FakeStartTestRunEvent
+
+
+class TestProfPlugin(unittest2.TestCase):
+    tags = ['unit']
+
+    def setUp(self):
+        self.plugin = prof.Profiler()
+        self.hotshot = prof.hotshot
+        self.stats = prof.stats
+        prof.hotshot = Stub()
+        prof.stats = Stub()
+
+    def tearDown(self):
+        prof.hotshot = self.hotshot
+        prof.stats = self.stats
+
+    def test_start_test_run_sets_executeTests(self):
+        _prof = Stub()
+        _prof.runcall = object()
+        prof.hotshot.Profile = lambda filename: _prof
+        event = FakeStartTestRunEvent()
+        self.plugin.startTestRun(event)
+        assert event.executeTests is _prof.runcall, \
+            "executeTests was not replaced"
+