CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/PKGTOOLS/tests/test_Package01.py

Go to the documentation of this file.
00001 from tests import cmsBuild
00002 from cmsBuild import PackageFactory, TagCacheAptImpl
00003 from os import makedirs, rmdir
00004 from os.path import exists, basename
00005 from cmsBuild import logLevel
00006 from cmsBuild import FileNotFound
00007 
00008 cmsBuild.logLevel = 3
00009 
00010 if exists ("tmptest"):
00011     rmdir ("tmptest")
00012 makedirs ("tmptest")
00013 
00014 class Options (object):
00015     def __init__ (self):
00016         self.architecture = "sltest_ia32_gcc345"
00017         self.workDir = "tmptest"
00018         self.cmsdist = "CMSDISTXXX"
00019         self.compilerVersion = "3.4.5"
00020         self.compilerName = "gcc"
00021         self.systemCompiler = True
00022         self.buildCommandPrefix = ""
00023         self.use32BitOn64 = False
00024         self.unsafeMode = False
00025         self.doNotBootstrap = True
00026         self.bootstrap = False
00027         self.tag = "test"
00028         self.testTag = True
00029 
00030 class FakeCMSOSDumper (object):
00031     def __init__ (self, opts):
00032         pass
00033         
00034     def dump (self, args):
00035         pass
00036 
00037 class TestPackageFactory (PackageFactory):
00038     def __init__ (self, options):
00039         def dummyPreamble (*anything):
00040             return """%define cmsplatf sltest_ia32_gcc345
00041 """
00042         PackageFactory._PackageFactory__getPreamble = dummyPreamble
00043         PackageFactory.__init__ (self, options, FakeCMSOSDumper)
00044 
00045 cmsBuild.tags_cache = TagCacheAptImpl (Options ())
00046 
00047 factory = TestPackageFactory (Options ())
00048 pkg1 = factory.create ()
00049 spec = ["""### RPM test test 1.0
00050 Source: foo
00051 Source1: bar
00052 Patch0: https://www.google.com
00053 Patch1: https://www.google.com
00054 """]
00055 pkg2 = factory.create ()
00056 pkg2.initWithSpec (spec)
00057 print [basename (source) for source in pkg2.sources]
00058 assert ([basename (source) for source in pkg2.sources] == ["foo.file", "bar.file"])
00059 assert (pkg2.patches == ["https://www.google.com", "https://www.google.com"])
00060 assert (pkg2.requires == [])
00061 assert (pkg2.cmsplatf == "sltest_ia32_gcc345")
00062 assert (pkg2.pkgName () == "test+test+1.0-test")
00063 assert (pkg2.sectionPostambles["%install"] == cmsBuild.DEFAULT_INSTALL_POSTAMBLE + "\n".join ([pkg2._Package__createProfileDScript, 
00064                                                                                                pkg2.initSh, 
00065                                                                                                pkg2.initCsh]))
00066 assert (pkg2.sectionPreambles["%post"] == cmsBuild.DEFAULT_POST_PREAMBLE)
00067 try:
00068     pkg2.sectionPreambles["%post"] = "Foo"
00069     assert (False)
00070 except cmsBuild.ReadOnlyDict.PermissionError, e:
00071     pass
00072 assert (pkg2.compiler.name == "system-compiler")
00073 rmdir ("tmptest")
00074 
00075 spec = """### RPM test test 1.0
00076 ## IMPORT foo
00077 ## IMPORT bar"""
00078 pkg3 = factory.create ()
00079 try:
00080     pkg3.initWithSpec (spec.split ("\n"))
00081     assert (False)
00082 except FileNotFound, e:
00083     assert (True)