~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/services/features/__init__.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-08-02 23:44:26 UTC
  • mfrom: (13589.1.1 revert-r13574)
  • Revision ID: launchpad@pqm.canonical.com-20110802234426-z03j07sj334l9ay0
[r=wgrant][rollback=13574] Revert r13574. It crashes when the flag is
 enabled, see bug #810290.

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
"""Dynamic feature configuration.
133
133
page.
134
134
 
135
135
 
136
 
Installing a feature controller
137
 
===============================
138
 
 
139
 
To use a particular feature controller, you should typicall go through a
140
 
UseFeatureController fixture.
141
 
 
142
 
 
143
136
Setting flags in your tests
144
137
===========================
145
138
 
176
169
 
177
170
import threading
178
171
 
179
 
from fixtures import Fixture
180
 
 
181
172
 
182
173
__all__ = [
183
 
    'UseFeatureController',
184
174
    'get_relevant_feature_controller',
185
175
    'getFeatureFlag',
186
176
    'install_feature_controller',
196
186
"""
197
187
 
198
188
 
199
 
class UseFeatureController(Fixture):
200
 
    """Install a feature controller for the duration of this context.
201
 
 
202
 
    Intended for use with the `with` statement.
203
 
    """
204
 
 
205
 
    def __init__(self, controller):
206
 
        super(UseFeatureController, self).__init__()
207
 
        self.controller = controller
208
 
 
209
 
    def setUp(self):
210
 
        super(UseFeatureController, self).setUp()
211
 
        self.addCleanup(
212
 
            install_feature_controller, get_relevant_feature_controller())
213
 
        install_feature_controller(self.controller)
214
 
 
215
 
 
216
189
def install_feature_controller(controller):
217
190
    """Install a `FeatureController` on this thread."""
218
191
    per_thread.features = controller