37
38
"set-intervals", "unknown-id"]
40
class LandscapeTest(MockerTestCase, TestCase):
41
class HelperTestCase(unittest.TestCase):
45
super(LandscapeTest, self).setUp()
47
self._old_config_filenames = BaseConfiguration.default_config_filenames
48
BaseConfiguration.default_config_filenames = []
49
# make_path-related stuff
50
self.dirname = tempfile.mkdtemp()
53
46
self._helper_instances = []
54
47
if LogKeeperHelper not in self.helpers:
55
48
self.helpers.insert(0, LogKeeperHelper)
59
52
self._helper_instances.append(helper)
61
54
def tearDown(self):
62
BaseConfiguration.default_config_filenames = self._old_config_filenames
63
55
for helper in reversed(self._helper_instances):
64
56
helper.tear_down(self)
65
shutil.rmtree(self.dirname)
66
super(LandscapeTest, self).tearDown()
59
class MessageTestCase(unittest.TestCase):
68
61
def assertMessage(self, obtained, expected):
69
62
obtained = obtained.copy()
93
86
raise self.failureException("Got %d more messages than expected:\n"
94
87
"%s" % (diff, extra))
90
class LandscapeTest(MessageTestCase, MockerTestCase,
91
HelperTestCase, TestCase):
94
self._old_config_filenames = BaseConfiguration.default_config_filenames
95
BaseConfiguration.default_config_filenames = []
96
MockerTestCase.setUp(self)
97
HelperTestCase.setUp(self)
101
BaseConfiguration.default_config_filenames = self._old_config_filenames
102
TestCase.tearDown(self)
103
HelperTestCase.tearDown(self)
104
MockerTestCase.tearDown(self)
96
106
def assertDeferredSucceeded(self, deferred):
97
107
self.assertTrue(isinstance(deferred, Deferred))
101
111
deferred.addCallback(callback)
102
112
self.assertTrue(called)
105
path = self.make_path()
109
def make_path(self, content=None, path=None):
112
path = "%s/%03d" % (self.dirname, self.counter)
113
if content is not None:
114
file = open(path, "w")
114
def assertFileContent(self, filename, expected_content):
116
actual_content = fd.read()
118
self.assertEquals(expected_content, actual_content)
120
def makePersistFile(self, *args, **kwargs):
121
"""Return a temporary filename to be used by a L{Persist} object.
123
The possible .old persist file is cleaned up after the test.
125
@see: L{MockerTestCase.makeFile}
127
persist_filename = self.makeFile(*args, **kwargs)
129
def remove_saved_persist():
131
os.remove(persist_filename + ".old")
134
self.addCleanup(remove_saved_persist)
135
return persist_filename
122
138
class LandscapeIsolatedTest(LandscapeTest):
123
139
"""TestCase that also runs all test methods in a subprocess."""
125
141
def run(self, result):
142
if not getattr(LandscapeTest, "_cleanup_patch", False):
143
run_method = LandscapeTest.run
144
def run_wrapper(oself, *args, **kwargs):
146
return run_method(oself, *args, **kwargs)
148
MockerTestCase._MockerTestCase__cleanup(oself)
149
LandscapeTest.run = run_wrapper
150
LandscapeTest._cleanup_patch = True
126
151
run_isolated(LandscapeTest, self, result)
210
235
self.ignored_exception_types.append(type_or_regex)
213
class MakePathHelper(object):
215
def set_up(self, test_case):
218
def tear_down(self, test_case):
222
238
class EnvironSnapshot(object):
224
240
def __init__(self):
249
265
- data_path: The data path that the broker will use.
268
reactor_factory = FakeReactor
269
transport_factory = FakeTransport
270
needs_bpickle_dbus = True
252
272
def set_up(self, test_case):
254
bpickle_dbus.install()
256
test_case.config_filename = test_case.make_path(
273
if self.needs_bpickle_dbus:
274
bpickle_dbus.install()
276
test_case.config_filename = test_case.makeFile(
258
278
"url = http://localhost:91919\n"
259
279
"computer_title = Default Computer Title\n"
260
280
"account_name = default_account_name\n"
261
281
"ping_url = http://localhost:91910/\n")
263
test_case.data_path = test_case.make_dir()
264
test_case.log_dir = test_case.make_dir()
283
test_case.data_path = test_case.makeDir()
284
test_case.log_dir = test_case.makeDir()
266
286
bootstrap_list.bootstrap(data_path=test_case.data_path,
267
287
log_dir=test_case.log_dir)
270
290
default_config_filenames = [test_case.config_filename]
272
292
config = MyBrokerConfiguration()
273
config.load(["--bus", "session", "--data-path", test_case.data_path])
293
config.load(["--bus", "session",
294
"--data-path", test_case.data_path,
275
297
class FakeBrokerService(BrokerService):
276
298
"""A broker which uses a fake reactor and fake transport."""
277
reactor_factory = FakeReactor
278
transport_factory = FakeTransport
299
reactor_factory = self.reactor_factory
300
transport_factory = self.transport_factory
280
302
test_case.broker_service = service = FakeBrokerService(config)
281
303
test_case.remote = FakeRemoteBroker(service.exchanger,
282
304
service.message_store)
284
306
def tear_down(self, test_case):
285
bpickle_dbus.uninstall()
307
if self.needs_bpickle_dbus:
308
bpickle_dbus.uninstall()
288
311
class RemoteBrokerHelper(FakeRemoteBrokerHelper):
345
368
def set_up(self, test_case):
346
369
super(MonitorHelper, self).set_up(test_case)
347
370
persist = Persist()
348
persist_filename = test_case.make_path()
371
persist_filename = test_case.makePersistFile()
349
372
test_case.monitor = MonitorPluginRegistry(
350
373
test_case.remote, test_case.broker_service.reactor,
351
374
test_case.broker_service.config,
365
388
class MyManagerConfiguration(ManagerConfiguration):
366
389
default_config_filenames = [test_case.config_filename]
367
390
config = MyManagerConfiguration()
391
config.load(["--data-path", test_case.data_path])
368
392
test_case.manager = ManagerPluginRegistry(
369
393
test_case.remote, test_case.broker_service.reactor,