comparison test/test_packager.py @ 125:34e08d52956e

Make the import_packager_module function more flexible. The modules may now also define a RevisionPackager and a BinaryPackager. See the docstring for details of the new rules. Also add some more tests.
author Bernhard Herzog <bh@intevation.de>
date Thu, 22 May 2008 18:12:30 +0000
parents 4bb029560721
children 5155b4f9443d
comparison
equal deleted inserted replaced
124:e08b4b09d35f 125:34e08d52956e
352 files = [("treepkg_importtest", 352 files = [("treepkg_importtest",
353 [("__init__.py", ""), 353 [("__init__.py", ""),
354 ("withtrack.py", "\n".join(["class PackageTrack:", 354 ("withtrack.py", "\n".join(["class PackageTrack:",
355 " pass", 355 " pass",
356 ""])), 356 ""])),
357 ("notrack.py", "\n".join(["class SourcePackager:", 357 ("srconly.py", "\n".join(["class SourcePackager:",
358 " pass",
359 ""])),
360 ("srcandbin.py", "\n".join(["class SourcePackager:",
361 " pass",
362 "class BinaryPackager:",
363 " pass",
364 ""])),
365 ("revonly.py", "\n".join(["class RevisionPackager:",
358 " pass", 366 " pass",
359 ""]))])] 367 ""]))])]
360 368
361 def setUp(self): 369 def setUp(self):
362 self.directory = self.create_temp_dir(self.id()) 370 self.directory = self.create_temp_dir(self.id())
365 sys.path = [self.directory] + sys.path 373 sys.path = [self.directory] + sys.path
366 374
367 def tearDown(self): 375 def tearDown(self):
368 sys.path = self.old_path 376 sys.path = self.old_path
369 377
378 def check_class_modules(self, module, classmodules):
379 self.assertEquals(classmodules,
380 [(item[0],
381 sys.modules[getattr(module, item[0]).__module__])
382 for item in classmodules])
383
370 def test_import_with_track(self): 384 def test_import_with_track(self):
371 module = import_packager_module("treepkg_importtest.withtrack") 385 module = import_packager_module("treepkg_importtest.withtrack")
372 self.failUnless(hasattr(module, "PackageTrack")) 386 self.check_class_modules(module, [("PackageTrack", module)])
373 387
374 def test_import_without_track(self): 388 def test_import_with_source_packager(self):
375 module = import_packager_module("treepkg_importtest.notrack") 389 module = import_packager_module("treepkg_importtest.srconly")
376 self.failUnless(hasattr(module, "PackageTrack")) 390 self.check_class_modules(module, [("PackageTrack", treepkg.packager),
391 ("SourcePackager", module),])
392
393 def test_import_with_source_and_binary_packager(self):
394 module = import_packager_module("treepkg_importtest.srcandbin")
395 self.check_class_modules(module, [("PackageTrack", treepkg.packager),
396 ("RevisionPackager",
397 treepkg.packager),
398 ("SourcePackager", module),
399 ("BinaryPackager", module),])
400 self.assertEquals(module.PackageTrack.revision_packager_cls,
401 module.RevisionPackager)
402 self.assertEquals(module.RevisionPackager.source_packager_cls,
403 module.SourcePackager)
404 self.assertEquals(module.RevisionPackager.binary_packager_cls,
405 module.BinaryPackager)
406
407 def test_import_with_revision_packager(self):
408 module = import_packager_module("treepkg_importtest.revonly")
409 self.check_class_modules(module, [("PackageTrack", treepkg.packager),
410 ("RevisionPackager", module)])
411
412 self.assertEquals(module.PackageTrack.revision_packager_cls,
413 module.RevisionPackager)
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)