~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/services/profile/tests.py

  • Committer: Curtis Hovey
  • Date: 2011-12-18 15:13:07 UTC
  • mto: This revision was merged to the branch mainline in revision 14547.
  • Revision ID: curtis.hovey@canonical.com-20111218151307-sdm2gzobt5tplbe0
Moved badges to lp.app.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2010-2011 Canonical Ltd.  This software is licensed under the
 
1
# Copyright 2010 Canonical Ltd.  This software is licensed under the
2
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
3
 
4
4
"""Tests for lp.services.profile.
5
5
 
6
 
See doc.txt for an end-user description of the functionality.
 
6
See lib/canonical/doc/profiling.txt for an end-user description of
 
7
the functionality.
7
8
"""
8
9
 
9
10
__metaclass__ = type
10
11
 
11
12
import glob
12
 
import logging
13
13
import os
14
14
import random
15
 
import unittest
16
15
 
17
16
from zope.app.publication.interfaces import (
18
17
    BeforeTraverseEvent,
19
18
    EndRequestEvent,
20
19
    )
21
 
from zope.component import (
22
 
    getSiteManager,
23
 
    queryUtility,
24
 
    )
25
 
from zope.error.interfaces import IErrorReportingUtility
 
20
from zope.component import getSiteManager
26
21
 
 
22
import canonical.launchpad.webapp.adapter as da
 
23
from canonical.launchpad.webapp.errorlog import ErrorReportingUtility
 
24
from canonical.launchpad.webapp.servers import LaunchpadTestRequest
 
25
from canonical.launchpad.webapp.interfaces import StartRequestEvent
 
26
from canonical.testing import layers
27
27
from lp.services.features.testing import FeatureFixture
28
28
from lp.services.profile import profile
29
 
import lp.services.webapp.adapter as da
30
 
from lp.services.webapp.errorlog import ErrorReportingUtility
31
 
from lp.services.webapp.interfaces import StartRequestEvent
32
 
from lp.services.webapp.servers import LaunchpadTestRequest
33
29
from lp.testing import (
34
 
    layers,
35
30
    TestCase,
36
 
    TestCaseWithFactory,
37
 
    )
38
 
from lp.testing.layers import LaunchpadFunctionalLayer
39
 
from lp.testing.systemdocs import (
40
 
    LayeredDocFileSuite,
41
 
    setUp,
42
 
    tearDown,
43
 
    )
44
 
 
 
31
    TestCaseWithFactory)
45
32
 
46
33
EXAMPLE_HTML_START = '''\
47
34
<html><head><title>Random!</title></head>
364
351
        self.profile_dir = self.makeTemporaryDirectory()
365
352
        self.memory_profile_log = os.path.join(self.profile_dir, 'memory_log')
366
353
        self.pushConfig('profiling', profile_dir=self.profile_dir)
367
 
        eru = queryUtility(IErrorReportingUtility)
368
 
        if eru is None:
369
 
            # Register an Error reporting utility for this layer.
370
 
            # This will break tests when run with an ERU already registered.
371
 
            self.eru = ErrorReportingUtility()
372
 
            sm = getSiteManager()
373
 
            sm.registerUtility(self.eru)
374
 
            self.addCleanup(sm.unregisterUtility, self.eru)
 
354
        self.eru = ErrorReportingUtility()
 
355
        sm = getSiteManager()
 
356
        sm.registerUtility(self.eru)
 
357
        self.addCleanup(sm.unregisterUtility, self.eru)
375
358
 
376
359
    def endRequest(self, path='/', exception=None, pageid=None, work=None):
377
360
        start_event = self._get_start_event(path)
790
773
            response)
791
774
        # This file should be part of several of the tracebacks.
792
775
        self.assertIn(__file__.replace('.pyc', '.py'), response)
793
 
 
794
 
 
795
 
def test_suite():
796
 
    """Return the `IBugTarget` TestSuite."""
797
 
    suite = unittest.TestSuite()
798
 
 
799
 
    doctest = LayeredDocFileSuite(
800
 
        './profiling.txt', setUp=setUp, tearDown=tearDown,
801
 
        layer=LaunchpadFunctionalLayer, stdout_logging_level=logging.WARNING)
802
 
    suite.addTest(doctest)
803
 
    suite.addTest(unittest.TestLoader().loadTestsFromName(__name__))
804
 
    return suite