def setUp(self): """Common set Up environment, available for all tests.""" pathname = os.path.dirname("/tmp/") self._logger = StdoutModuleLogger() self._logger.set_verbose(0) self._env = ModuleEnvironment(self._logger, pathname, pathname, pathname)
def setUp(self): """Common set Up environment, available for all tests.""" pathname = os.path.dirname("/tmp/source/") testStatus = commands.getoutput('rm -rf ' + pathname) self._logger = StdoutModuleLogger(); self._logger.set_verbose(1) self._env = ModuleEnvironment(self._logger, pathname, pathname, pathname+"/obj")
def setUp(self): """Common set Up environment, available for all tests.""" pathname = os.path.dirname(test.TestBake.compensate_third_runner()) if not pathname: pathname = "." logger = StdoutModuleLogger() self._env = ModuleEnvironment(logger, pathname, pathname, pathname)
def setUp(self): """Common set Up environment, available for all tests.""" pathname = os.path.dirname(test.TestBake.compensate_third_runner()) if not pathname: pathname="." logger = StdoutModuleLogger() self._env = ModuleEnvironment(logger, pathname, pathname, pathname)
def setUp(self): """Common set Up environment, available for all tests.""" pathname = os.path.dirname("/tmp/source/") self._logger = StdoutModuleLogger() self._logger.set_verbose(1) self._env = ModuleEnvironment(self._logger, pathname, pathname, pathname) # testStatus = subprocess.getoutput('cp ' + pathname + '/bakefile.xml /tmp/.') testStatus = subprocess.getoutput('chmod 755 /tmp/source') testStatus = subprocess.getoutput('rm -rf /tmp/source')
class TestModuleSource(unittest.TestCase): """Tests cases for the Module Environment Class.""" def setUp(self): """Common set Up environment, available for all tests.""" pathname = os.path.dirname("/tmp/") self._logger = StdoutModuleLogger() self._logger.set_verbose(0) self._env = ModuleEnvironment(self._logger, pathname, pathname, pathname) def tearDown(self): """Cleans the environment environment for the next tests.""" self._env = None def execute_command(self, command, dir): """Executes the given command, catching the exceptions.""" try: self._env.run(command, dir) except Exception as inst: print(inst) # the exception instance self.fail("Could not execute command %s over directory %s failed" % (command, dir)) def test_general_failures(self): """Tests Some general failures that could happen in the Module Source. """ #Verifies the return of the creation of a non existent module module = ModuleSource.create("NonExistentModule") self.assertEqual(module, None) def test_archive_module_source(self): """Tests the ArchiveModuleSource class. """ # it first needs to be able to create the class otherwise will not be # able to do anything else archive = ModuleSource.create("archive") self.assertNotEqual(archive, None) self.assertEqual(archive.name(), "archive") # Verifies if the system has the right tools installed, if not does not # even worth continuing # no file was declared yet, so the issue should be False testResult = archive.check_version(self._env) self.assertFalse(testResult) # Unknown file type archive.attribute( "url").value = "http://JustATest.com/File.unknownFileType" testResult = archive.check_version(self._env) self.assertFalse( testResult, "There is no tool to handle the target extension, the result should be false" ) # zip archive.attribute("url").value = "http://JustATest.com/File.zip" testResult = archive.check_version(self._env) self.assertTrue(testResult, "unzip is not present on the system") # rar archive.attribute("url").value = "http://JustATest.com/File.rar" testResult = archive.check_version(self._env) self.assertTrue(testResult, "unrar is not present on the system") # tar archive.attribute("url").value = "http://JustATest.com/File.tar" testResult = archive.check_version(self._env) self.assertTrue(testResult, "tar is not present on the system") # tar.Z archive.attribute("url").value = "http://JustATest.com/File.tar.Z" testResult = archive.check_version(self._env) self.assertTrue(testResult, "tar is not present on the system") # tar.bz2 archive.attribute("url").value = "http://JustATest.com/File.tar.bz2" testResult = archive.check_version(self._env) self.assertTrue(testResult, "tar is not present on the system") # tar.gz archive.attribute( "url").value = "http://read.cs.ucla.edu/click/click-1.8.0.tar.gz" # archive.attribute("url").value = "http://read.cs.ucla.edu/click/click-1.8.0.tar.gz" testResult = archive.check_version(self._env) self.assertTrue(testResult, "tar is not present on the system") self._env._module_name = "click-1.8.0" self._logger.set_current_module(self._env._module_name) #clean up the environment, just to be safe self.execute_command(["/bin/rm", "-rf", "click-1.8.0.tar.gz"], "/tmp") self.execute_command(["/bin/rm", "-rf", "click-1.8.0"], "/tmp") testResult = archive.download(self._env) # if something goes wrong it should rise an exception so, None means # everything is OK self.assertEqual(testResult, None) # verifies that files are really there after the download testStatus = commands.getoutput('ls /tmp/click-1.8.0.tar.gz') self.assertEqual("/tmp/click-1.8.0.tar.gz", testStatus) testStatus = commands.getoutput('ls -d /tmp/click-1.8.0') self.assertEqual("/tmp/click-1.8.0", testStatus) #after the test, clean the environment self.execute_command(["/bin/rm", "-rf", "click-1.8.0.tar.gz"], "/tmp") self.execute_command(["/bin/rm", "-rf", "click-1.8.0"], "/tmp") # Searches for a valid file into an inexistent repository archive.attribute( "url").value = "http://non.existent.host.com/click-1.8.0.tar.gz" testResult = None try: testResult = archive.download(self._env) self.fail("There was no problem, and the server does not exist. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # Try to download to a directory that the user has no permission archive.attribute( "url").value = "http://read.cs.ucla.edu/click/click-1.8.0.tar.gz" testStatus = commands.getoutput( 'touch /tmp/click-1.8.0;chmod 000 /tmp/click-1.8.0') testResult = None try: testResult = archive.download(self._env) self.fail( "There was no problem, the user has no permission over the target directory. " ) except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) testStatus = commands.getoutput("chmod 755 /tmp/click-1.8.0; rm -f " "/tmp/click-1.8.0") # try to download to a non existent directory testStatus = commands.getoutput('rm -rf /tmp/testDir') self._env._sourcedir = "/tmp/testDir" testResult = None try: testResult = archive.download(self._env) self.fail("There was no problem, target directory does not exist " "and it managed to finish the operation. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) testStatus = commands.getoutput( 'mkdir /tmp/testDir;chmod 000 /tmp/testDir') testResult = None try: testResult = archive.download(self._env) self.fail( "There was no problem, user has no permission on the " "target directory and it managed to finish the operation.") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) testStatus = commands.getoutput( 'chmod 755 /tmp/testDir; rm -rf /tmp/testDir') # no protocol download url gives you an error archive.attribute( "url").value = "read.cs.ucla.edu/click/click-1.8.0.tar.gz" testResult = None try: testResult = archive.download(self._env) self.fail("There was no problem, the user didn't add the protocol" " for the url. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # just to be sure that the update does nothing testResult = archive.update(self._env) self.assertEqual(testResult, None) # Oddly enough, when the user has no permission in the target # directory the system returns no error Right now I have no idea how # to fix it, or IF we should try to fix anyway. # self._env._sourcedir = "/tmp" # testStatus = commands.getoutput('mkdir /tmp/click-1.8.0;chmod 000 /tmp/click-1.8.0') # try: # testResult = archive.download(self._env) # self.fail("There was not problem, the user has no permission over the target directory. ") # except TaskError as e: # self.assertNotEqual(e._reason, None) # self.assertEqual(testResult, None) # # testStatus = commands.getoutput('chmod 755 /tmp/click-1.8.0; rm -rf /tmp/click-1.8.0') def test_check_dependency_expression(self): """ Tests the _check_dependency_expression method. """ # it first needs to be able to create the class otherwise will not be # able to do anything else installer = ModuleSource.create("system_dependency") self.assertNotEqual(installer, None) self.assertEqual(installer.name(), "system_dependency") self._env._module_name = "testModule" self._logger.set_current_module(self._env._module_name) # Unknown file type installer.attribute('more_information').value = "Just a test" installer.attribute('sudoer_install').value = 'False' installer.attribute("try_to_install").value = 'True' installer.attribute("dependency_test").value = "NonExistentSoftForTest" testResult = None testResult = installer._check_dependency_expression( self._env, "NonExistentSoft") self.assertFalse(testResult, "Non existent software, should be false") testResult = None testResult = installer._check_dependency_expression(self._env, "bash") self.assertTrue(testResult, "Existent software, should be true") testResult = None testResult = installer._check_dependency_expression( self._env, "nthing or bash") self.assertTrue(testResult, "Existent software, should be true") testResult = None testResult = installer._check_dependency_expression( self._env, "nthinag and bash") self.assertFalse( testResult, "Inexistent software AND existent one, " "should be false") testResult = None testResult = installer._check_dependency_expression( self._env, "not bash") self.assertFalse(testResult, "The software should exist so it, " "should be false") testResult = None testResult = installer._check_dependency_expression( self._env, "not nthing") self.assertTrue(testResult, "The software does not exist so it, " "should be true") testResult = None testResult = installer._check_dependency_expression( self._env, "/bin/ls") self.assertTrue(testResult, "The software exist so it, " "should be true") testResult = None testResult = installer._check_dependency_expression(self._env, "/lib") self.assertTrue(testResult, "The repository exist so it, " "should be true") testResult = None testResult = installer._check_dependency_expression( self._env, "/tt/NoDirDir") self.assertFalse( testResult, "The repository does not exist so it, " "should be False") testResult = None testResult = installer._check_dependency_expression( self._env, "libc.so") self.assertTrue(testResult, "The library should exist so it, " "should be True") testResult = None testResult = installer._check_dependency_expression( self._env, "notValidLibNot.so") self.assertFalse( testResult, "The library should not exist so it, " "should be False") def test_SystemDependencySource(self): """Tests the SelfInstallerModule class. """ # it first needs to be able to create the class otherwise will not be # able to do anything else installer = ModuleSource.create("system_dependency") self.assertNotEqual(installer, None) self.assertEqual(installer.name(), "system_dependency") # Verifies if the system has the right tools installed, if not does not # even worth continuing # Verify if the installer, for this architecture exists testResult = installer.check_version(self._env) self.assertTrue(testResult) self._env._module_name = "testModule" self._logger.set_current_module(self._env._module_name) # Unknown file type installer.attribute("dependency_test").value = "NonExistentSoftForTest" installer.attribute( 'more_information').value = "Message test for inexistent module" installer.attribute("try_to_install").value = 'True' installer.attribute("sudoer_install").value = 'True' testResult = None try: testResult = installer.download(self._env) except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # print(e._reason) installer.attribute("dependency_test").value = "gcc" installer.attribute('more_information').value = "You miss gcc download" " it from your linux distribution website" testResult = None try: testResult = installer.download(self._env) except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # print(e._reason) self.assertTrue(testResult) #try to install a non existent module installer.attribute("dependency_test").value = "erlang" installer.attribute('more_information').value = "You miss erlang, " "download it from your linux distribution website" installer.attribute('sudoer_install').value = 'True' testResult = None try: testResult = installer.download(self._env) except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # print(e._reason) self.assertTrue(testResult == None) # remove the NOT installed module testResult = None reason = None try: testResult = installer.remove(self._env) except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) reason = e._reason # print(e._reason) self.assertTrue(testResult == None) self.assertFalse(not reason) installer.attribute('name_yum').value = "erlang" installer.attribute('name_apt-get').value = "erlang" testResult = None reason = None try: testResult = installer.download(self._env) except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) reason = e._reason # print(e._reason) self.assertTrue(testResult == None) self.assertFalse(not reason) # Adds the sudo tag... now the modules should be able to be installed self._env._sudoEnabled = True # Just to be sure the erlang module is not installed on the machine testResult = None try: testResult = installer.remove(self._env) except TaskError as e: print(e._reason) # this installation should work for sure now! # remove the just installed module testResult = None reason = None try: testResult = installer.download(self._env) except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) reason = e._reason print(e._reason) self.assertTrue(testResult) self.assertTrue(not reason) # Just to be sure the erlang module is not installed on the machine testResult = None try: testResult = installer.remove(self._env) except TaskError as e: print(e._reason) def test_systemPrecondition(self): """Tests the SelfInstallerModule class. """ # it first needs to be able to create the class otherwise will not be # able to do anything else installer = ModuleSource.create("system_dependency") self.assertNotEqual(installer, None) testResult = installer._check_dependency_expression(self._env, "") self.assertTrue(testResult) testResult = installer._check_dependency_expression(self._env, "ls") self.assertTrue(testResult) testResult = installer._check_dependency_expression( self._env, "(ls and bash)") self.assertTrue(testResult) testResult = installer._check_dependency_expression( self._env, "(ls or us9245l25k)") self.assertTrue(testResult) testResult = installer._check_dependency_expression( self._env, "(ls and not us9245l25k)") self.assertTrue(testResult) testResult = installer._check_dependency_expression( self._env, "(ls and us9245l25k)") self.assertFalse(testResult) testResult = installer._check_dependency_expression( self._env, "(ls and bash) and rm") self.assertTrue(testResult) testResult = installer._check_dependency_expression( self._env, "(ls and bash) and us9245l25k") self.assertFalse(testResult) testResult = installer._check_dependency_expression( self._env, "(ls and bash) or us9245l25k") self.assertTrue(testResult) testResult = installer._check_dependency_expression( self._env, "((ls and bash) or us9245l25k)") self.assertTrue(testResult) def test_mercurial(self): """Tests the MercurialModuleSource class. """ # it first needs to be able to create the class otherwise will not be # able to do anything else mercurial = ModuleSource.create("mercurial") self.assertNotEqual(mercurial, None) self.assertEqual(mercurial.name(), "mercurial") # Verifies if the system has the mercurial installed, if not does not # even worth continuing testResult = mercurial.check_version(self._env) self.assertTrue(testResult) mercurial.attribute("url").value = "http://code.nsnam.org/daniel/bake" self._env._module_name = "bake" self._logger.set_current_module(self._env._module_name) #clean up the environment, just to be safe self.execute_command(["/bin/rm", "-rf", "bake"], "/tmp") testResult = mercurial.download(self._env) # if something goes wrong it should rise an exception so, None means # everything is OK self.assertEqual(testResult, None) #after the test, clean the environment self.execute_command(["rm", "-rf", "bake"], "/tmp") # download a specific version mercurial.attribute("revision").value = "63" testResult = mercurial.download(self._env) self.assertEqual(testResult, None) # verify that the version is the correct one testStatus = commands.getoutput('cd /tmp/bake;hg summary') version = re.compile('\d+').search(testStatus).group() self.assertEqual(version, "63") # makes an update of the version to the last version mercurial.attribute("revision").value = "64" testResult = mercurial.update(self._env) self.assertEqual(testResult, None) # verify that the version is the correct one testStatus = commands.getoutput('cd /tmp/bake;hg summary') version = re.compile('\d+').search(testStatus).group() self.assertEqual(version, "64") # Verifies the update to the tip mercurial.attribute("revision").value = "tip" testResult = mercurial.update(self._env) self.assertEqual(testResult, None) # verify that the version is the correct one testStatus = commands.getoutput('cd /tmp/bake;hg log') versionRepository = re.compile('\d+').search(testStatus).group() testStatus = commands.getoutput('cd /tmp/bake;hg summary') versionDownloaded = re.compile('\d+').search(testStatus).group() self.assertEqual(versionRepository, versionDownloaded) self.execute_command(["rm", "-rf", "bake"], "/tmp") # Not http should give you a TaskError exception mercurial.attribute("url").value = "code.nsnam.org/daniel/bake" self._env._module_name = "bake" self._logger.set_current_module(self._env._module_name) testResult = None try: testResult = mercurial.download(self._env) self.fail("There was no problem not passing the protocol. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) self.execute_command(["rm", "-rf", "bake"], "/tmp") testStatus = commands.getoutput('mkdir /tmp/bake;chmod 000 /tmp/bake') mercurial.attribute("url").value = "http://code.nsnam.org/daniel/bake" testResult = None try: testResult = mercurial.download(self._env) self.fail("There was no problem and the user has no permission" " over the directory. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) testStatus = commands.getoutput('chmod 755 /tmp/bake') self.execute_command(["rm", "-rf", "bake"], "/tmp") # try to download to a non existent directory # mercurial cretes the directory testStatus = commands.getoutput('rm -rf /tmp/testDir') self._env._sourcedir = "/tmp/testDir" testResult = mercurial.download(self._env) self.assertEqual(testResult, None) testStatus = commands.getoutput('rm -rf /tmp/testDir') testStatus = commands.getoutput( 'mkdir /tmp/testDir;chmod 000 /tmp/testDir') testResult = None try: testResult = mercurial.download(self._env) self.fail( "There was no problem, user has no permission on the" " target directory and it managed to finish the operation. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) testStatus = commands.getoutput( 'chmod 755 /tmp/testDir; rm -rf /tmp/testDir') # Try to get a wrong version, there is a but in the mercurial # that permits negative revisions, such as -34, for example, # however bigger than the tip version gives an error mercurial.attribute("revision").value = "9999999" testResult = None try: testResult = mercurial.download(self._env) self.fail("The version is inexistent, but there is no error. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # last clean up self.execute_command(["rm", "-rf", "bake"], "/tmp") def test_bazaar(self): """Tests the BazaarModuleSource class. """ # checks if can create the class bazaar = ModuleSource.create("bazaar") self.assertNotEqual(bazaar, None) self.assertEqual(bazaar.name(), "bazaar") # Verifies if Bazaar is installed testResult = bazaar.check_version(self._env) self.assertTrue(testResult) bazaar.attribute("url").value = "https://launchpad.net/pybindgen" self._env._module_name = "pybindgen" self._logger.set_current_module(self._env._module_name) ##### Normal Flow test #clean up the environment, just to be safe self.execute_command(["/bin/rm", "-rf", "pybindgen"], "/tmp") testResult = bazaar.download(self._env) # None means everything was OK, since there were no exceptions self.assertEqual(testResult, None) testStatus = commands.getoutput('cd /tmp/pybindgen; bzr log') lastVersion = re.compile('\d+').search(testStatus).group() #after the test, clean the environment self.execute_command(["rm", "-rf", "pybindgen"], "/tmp") # download a specific version bazaar.attribute("revision").value = "794" testResult = bazaar.download(self._env) self.assertEqual(testResult, None) # verify that the version is the correct one testStatus = commands.getoutput('cd /tmp/pybindgen; bzr log') version = re.compile('\d+').search(testStatus).group() self.assertEqual(version, "794") # makes an update of the version to a latter version bazaar.attribute("revision").value = "795" testResult = bazaar.update(self._env) self.assertEqual(testResult, None) # verify that the version is the correct one testStatus = commands.getoutput('cd /tmp/pybindgen; bzr log') version = re.compile('\d+').search(testStatus).group() self.assertEqual(version, "795") self.execute_command(["rm", "-rf", "pybindgen"], "/tmp") # Wrong repository bazaar.attribute("url").value = "http://code.nsnam.org/daniel/bake" self._logger.set_current_module(self._env._module_name) testResult = None try: testResult = bazaar.download(self._env) self.fail("There was no problem not passing the protocol. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # No protocol http/https bazaar.attribute("url").value = "launchpad.net/pybindgen" bazaar.attribute("revision").value = None self._logger.set_current_module(self._env._module_name) testResult = None try: testResult = bazaar.download(self._env) self.fail("There was no problem not passing the protocol. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) self.execute_command(["rm", "-rf", "pybindgen"], "/tmp") testStatus = commands.getoutput( 'mkdir /tmp/pybindgen;chmod 000 /tmp/pybindgen') bazaar.attribute("url").value = "https://launchpad.net/pybindgen" testResult = None try: testResult = bazaar.download(self._env) self.fail("There was no problem and the user has no permission" " over the directory. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) testStatus = commands.getoutput('chmod 755 /tmp/pybindgen') self.execute_command(["rm", "-rf", "pybindgen"], "/tmp") # try to download to a non existent directory testStatus = commands.getoutput('rm -rf /tmp/testDir') self._env._sourcedir = "/tmp/testDir" testResult = None try: testResult = bazaar.download(self._env) self.fail("There was no problem, target directory does not exist" " and it managed to finish the operation. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # try to download to a directory where the user has no permission testStatus = commands.getoutput( 'mkdir /tmp/testDir;chmod 000 /tmp/testDir') testResult = None try: testResult = bazaar.download(self._env) self.fail( "There was no problem, user has no permission on the" " target directory and it managed to finish the operation. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) testStatus = commands.getoutput( 'chmod 755 /tmp/testDir; rm -rf /tmp/testDir') # returns to the original state bazaar.attribute("url").value = "https://launchpad.net/pybindgen" self._env._sourcedir = "/tmp" # Try to get an unavailable version bazaar.attribute("revision").value = str(int(lastVersion) + 1) testResult = None try: testResult = bazaar.download(self._env) self.fail("The version is inexistent, but there is no error. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # verifies the update to a inexistent version bazaar.attribute("revision").value = None testResult = bazaar.download(self._env) self.assertEqual(testResult, None) # Invalid argument, it is int and should be string bazaar.attribute("revision").value = -60 testResult = None try: testResult = bazaar.download(self._env) self.fail("The version is inexistent, but there is no error. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # can not go for a negative version bazaar.attribute("revision").value = str(-60) testResult = None try: testResult = bazaar.download(self._env) self.fail("The version is inexistent, but there is no error. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # last clean up self.execute_command(["rm", "-rf", "pybindgen"], "/tmp") def test_cvs(self): """Tests the CvsModuleSourceclass. """ # checks if can create the class cvs = ModuleSource.create("cvs") self.assertNotEqual(cvs, None) self.assertEqual(cvs.name(), "cvs") # Verifies if cvs is installed testResult = cvs.check_version(self._env) self.assertTrue(testResult) cvs.attribute( "root").value = ":pserver:anoncvs:@www.gccxml.org:/cvsroot/GCC_XML" cvs.attribute("module").value = "gccxml" cvs.attribute("date").value = "2009-09-21" self._env._module_name = "gccxml" self._logger.set_current_module(self._env._module_name) ##### Normal Flow test #clean up the environment, just to be safe self.execute_command(["/bin/rm", "-rf", "gccxml"], "/tmp") testResult = cvs.download(self._env) # None means everything was OK, since there were no exceptions self.assertEqual(testResult, None) # will use the README file to see if the update works testStatus = commands.getoutput( 'cd /tmp/gccxml; cvs status CMakeLists.txt') lastVersion = re.compile('\d+.\d+').search(testStatus).group().replace( ".", "") #after the test, clean the environment self.execute_command(["rm", "-rf", "gccxml"], "/tmp") # download a specific version cvs.attribute("date").value = "2007-09-21" testResult = cvs.download(self._env) self.assertEqual(testResult, None) # verify that the version is the correct one testStatus = commands.getoutput( 'cd /tmp/gccxml; cvs status CMakeLists.txt') version = re.compile('\d+.\d+').search(testStatus).group().replace( ".", "") self.assertEqual(version, "18") # makes an update of the version to a latter version cvs.attribute("date").value = "2008-09-21" testResult = cvs.update(self._env) self.assertEqual(testResult, None) # verify that the version is bigger than the previous one testStatus = commands.getoutput( 'cd /tmp/gccxml; cvs status CMakeLists.txt') version2 = re.compile('\d+.\d+').search(testStatus).group().replace( ".", "") self.assertTrue((float(version) < float(version2))) # Verify if it updates to today's version cvs.attribute("date").value = None testResult = cvs.update(self._env) self.assertEqual(testResult, None) testStatus = commands.getoutput( 'cd /tmp/gccxml; cvs status CMakeLists.txt') version3 = re.compile('\d+.\d+').search(testStatus).group().replace( ".", "") self.assertTrue(float(version2) < float(version3)) self.execute_command(["rm", "-rf", "gccxml"], "/tmp") # Wrong repository cvs.attribute( "root" ).value = ":pserver:anoncvs:@non.Existent.server.com:/cvsroot/GCC_XML" cvs.attribute("date").value = "2008-09-21" self._logger.set_current_module(self._env._module_name) testResult = None try: testResult = cvs.download(self._env) self.fail("There was no problem with a non existent repository. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) self.execute_command(["rm", "-rf", "gccxml"], "/tmp") # try to download to a non existent directory testStatus = commands.getoutput('rm -rf /tmp/testDir') self._env._sourcedir = "/tmp/testDir" testResult = None try: testResult = cvs.download(self._env) self.fail("There was no problem, target directory does not exist" " and it managed to finish the operation. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # try to download to a directory where the user has no permission testStatus = commands.getoutput( 'mkdir /tmp/testDir;chmod 000 /tmp/testDir') testResult = None try: testResult = cvs.download(self._env) self.fail( "There was no problem, user has no permission on the" " target directory and it managed to finish the operation. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) testStatus = commands.getoutput( 'chmod 755 /tmp/testDir; rm -rf /tmp/testDir') # returns to the original state cvs.attribute( "root").value = ":pserver:anoncvs:@www.gccxml.org:/cvsroot/GCC_XML" self._env._sourcedir = "/tmp" # Invalid argument, it is int and should be string cvs.attribute("checkout_directory").value = -60 testResult = None try: testResult = cvs.download(self._env) self.fail("The version is inexistent, but there is no error. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # can't go for an inexistent version cvs.attribute("checkout_directory").value = "/tmp" cvs.attribute("date").value = "5000-09-21" testResult = None try: testResult = cvs.download(self._env) self.fail("The version is inexistent, but there is no error. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # last clean up self.execute_command(["rm", "-rf", "gccxml"], "/tmp") def test_git(self): """Tests the GitModuleSource. """ # checks if can create the class git = ModuleSource.create("git") self.assertNotEqual(git, None) self.assertEqual(git.name(), "git") # Verifies if git is installed testResult = git.check_version(self._env) self.assertTrue(testResult) git.attribute("url").value = "git://github.com/git/hello-world.git" git.attribute( "revision").value = "78cfc43c2827b9e48e6586a3523ff845a6378889" self._env._module_name = "hello-world" self._logger.set_current_module(self._env._module_name) ##### Normal Flow test #clean up the environment, just to be safe self.execute_command(["/bin/rm", "-rf", "hello-world"], "/tmp") testResult = git.download(self._env) # None means everything was OK, since there were no exceptions self.assertEqual(testResult, None) # will use the README file to see if the update works testStatus = commands.getoutput('cd /tmp/hello-world; git log') lastVersion = re.compile(' +\w+').search(testStatus).group().replace( " ", "") self.assertEqual(lastVersion, "78cfc43c2827b9e48e6586a3523ff845a6378889") testResult = git.update(self._env) self.assertEqual(testResult, None) git.attribute( "revision").value = "45021a874e090b765acc5e2696154c495686614b" testResult = git.update(self._env) self.assertEqual(testResult, None) commands.getoutput( "cat /tmp/hello-world/c.c >> /tmp/hello-world/dos.bat") testResult = git.update(self._env) self.assertEqual(testResult, None) #after the test, clean the environment self.execute_command(["rm", "-rf", "hello-world"], "/tmp") # download a specific version git.attribute( "revision").value = "3fa7c46d11b11d61f1cbadc6888be5d0eae21969" testResult = git.download(self._env) self.assertEqual(testResult, None) # verify that the version is the correct one testStatus = commands.getoutput('cd /tmp/hello-world; git log') version = re.compile(' +\w+').search(testStatus).group().replace( " ", "") self.assertEqual(version, "3fa7c46d11b11d61f1cbadc6888be5d0eae21969") self.execute_command(["rm", "-rf", "gccxml"], "/tmp") #Wrong repository git.attribute( "url").value = "git://inexistant.server.com/git/hello-world.git" git.attribute( "revision").value = "78cfc43c2827b9e48e6586a3523ff845a6378889" self._logger.set_current_module(self._env._module_name) testResult = None try: testResult = git.download(self._env) self.fail("There was no problem with a non existent repository. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) self.execute_command(["rm", "-rf", "gccxml"], "/tmp") # no protocol git.attribute("url").value = "github.com/git/hello-world.git" self._logger.set_current_module(self._env._module_name) testResult = None try: testResult = git.download(self._env) self.fail("There was no problem without protocol. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) git.attribute("url").value = "git://github.com/git/hello-world.git" self.execute_command(["rm", "-rf", "gccxml"], "/tmp") # try to download to a non existent directory testStatus = commands.getoutput('rm -rf /tmp/testDir') self._env._sourcedir = "/tmp/testDir" testResult = None try: testResult = git.download(self._env) self.fail("There was no problem, target directory does not" " exist and it managed to finish the operation. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # try to download to a directory where the user has no permission testStatus = commands.getoutput( 'mkdir /tmp/testDir;chmod 000 /tmp/testDir') testResult = None try: testResult = git.download(self._env) self.fail( "There was no problem, user has no permission on the" " target directory and it managed to finish the operation. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) testStatus = commands.getoutput( 'chmod 755 /tmp/testDir; rm -rf /tmp/testDir') # Invalid argument, it is int and should be string self._env._sourcedir = -60 testResult = None try: testResult = git.download(self._env) self.fail("The version is inexistent, but there is no error. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # returns to the original state self._env._sourcedir = "/tmp" # can't go for an inexistent version git.attribute( "revision").value = "1000000000000000000000000000000000000000" testResult = None try: testResult = git.download(self._env) self.fail("The version is inexistent, but there is no error. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None)
class TestModuleBuild (unittest.TestCase): """Tests cases for the build process, mainly the ModuleBuild Class and subclasses.""" def setUp(self): """Common set Up environment, available for all tests.""" pathname = os.path.dirname("/tmp/source/") testStatus = commands.getoutput('rm -rf ' + pathname) self._logger = StdoutModuleLogger(); self._logger.set_verbose(1) self._env = ModuleEnvironment(self._logger, pathname, pathname, pathname+"/obj") def tearDown(self): """Cleans the environment environment for the next tests.""" self._env = None pathname = os.path.dirname("/tmp/source") # pathname = os.path.dirname(test.TestBake.compensate_third_runner()) testStatus = commands.getoutput('rm -f ' + pathname +'/bakefile.xml') testStatus = commands.getoutput('rm -rf /tmp/source') def test_PythonModuleBuild(self): """Tests the WafModuleBuild Class from ModuleBuild. """ # creating python build module test python = ModuleBuild.create("python") self.assertNotEqual(python, None) self.assertEqual(python.name(), "python") self._env.start_build("python", "/tmp", python.supports_objdir) #checks that the machine has python installed self._logger.set_current_module(self._env._module_name) testResult = python.check_version(self._env) self.assertTrue(testResult) # set up the environment: create directories and download the target code archive = ModuleSource.create("archive") archive.attribute("url").value = "http://switch.dl.sourceforge.net/project/pygccxml/pygccxml/pygccxml-1.0/pygccxml-1.0.0.zip" self._env._module_name="pygccxml" self._env._module_dir="pygccxml" testStatus = commands.getoutput('rm -rf /tmp/source/pygccxml') testStatus = commands.getoutput('mkdir /tmp/source') self._logger.set_current_module(self._env._module_name) testResult = archive.download(self._env) self.assertEqual(testResult, None) testStatus = commands.getoutput('ls /tmp/source/pygccxml|wc') created = re.compile(' +\d+').search(testStatus).group().strip() self.assertNotEqual(created, "0") # Expected case test self._env.objdir = self._env.srcdir+"/object_bake" self._env._installdir = self._env.srcdir+"/install_bake" # test patch self.assertEqual(python.attribute('patch').value, '') python.attribute('patch').value = self._env.srcdir + '/test.patch' self.assertEqual(python.attribute('patch').value, self._env.srcdir + '/test.patch') testResult = None try: testResult = python.add_attribute('patch', 'ERRROR', 'SHOULD NOT HAVE BEEN ADDED') self.fail("The attribute patch exists already, " + "should not be able to add it. ") except AssertionError as e: self.assertNotEqual(e, None) self.assertEqual(testResult, None) try: testResult = python.build(self._env, "1") self.fail("The patch does not exist, should not have being able" + " to find the path file and give an error. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # creates the file, empty, but created testStatus = commands.getoutput('touch ' + self._env.srcdir + '/test.patch') testResult = python.build(self._env, "1") self.assertEqual(testResult, None) # TODO: find a python module that accepts the distclean # testResult = python.distclean(self._env) # self.assertEqual(testResult, None) python.attribute('patch').value = '' testStatus = commands.getoutput('rm -rf ' + self._env.objdir) testStatus = commands.getoutput('rm -rf ' + self._env._installdir) testResult = python.build(self._env, "1") self.assertEqual(testResult, None) testStatus = commands.getoutput('ls /tmp/source/pygccxml/object_bake|wc') created = re.compile(' +\d+').search(testStatus).group().strip() self.assertNotEqual(created, "0") testStatus = commands.getoutput('ls /tmp/source/pygccxml/install_bake|wc') created = re.compile(' +\d+').search(testStatus).group().strip() self.assertNotEqual(created, "0") # No permission in the target directories self._env.objdir = "/tmp/source/test1/testobj" self._env._installdir = "/tmp/source/test1/testinst" testStatus = commands.getoutput('rm -rf ' + "/tmp/source/test1") testStatus = commands.getoutput('mkdir ' + "/tmp/source/test1") testStatus = commands.getoutput('chmod 000 ' +"/tmp/source/test1") testResult = None try: testResult = python.build(self._env, "1") self.fail("Has no permission in the target directory, and " + "passed any way. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) testStatus = commands.getoutput('chmod 755 ' + "/tmp/source/test1") testStatus = commands.getoutput('rm -rf ' + "/tmp/source/test1") # call the clean to remove the build # TODO: The clean does not work, the call is correct but I guess it is a # problem with the pygccxml clean that does nothing. # self._env.objdir = self._env.srcdir+"/object_bake" # self._env._installdir = self._env.srcdir+"/install_bake" # testResult = python.clean(self._env) # self.assertEqual(testResult, None) # testStatus = commands.getoutput('ls /tmp/source/pygccxml/object_bake|wc') # created = re.compile(' +\d+').search(testStatus).group().strip() # self.assertEqual(created, "0") # testStatus = commands.getoutput('ls /tmp/source/pygccxml/install_bake|wc') # created = re.compile(' +\d+').search(testStatus).group().strip() # self.assertEqual(created, "0") def test_WafModuleBuild(self): """Tests the WafModuleBuild Class from ModuleBuild. """ waf = ModuleBuild.create("waf") self.assertNotEqual(waf, None) self.assertEqual(waf.name(), "waf") testStatus = commands.getoutput('cp test.patch /tmp/source/' 'openflow-ns3/test.patch' ) self._env.start_build("waf", "/tmp", waf.supports_objdir) testResult = None testResult = waf.check_version(self._env) self.assertFalse(testResult) # try: # self.fail("There was a miss configuration problem and there was no error.") # except TaskError as e: # self.assertNotEqual(e._reason, None) # self.assertEqual(testResult, None) # Environment settings mercurial = ModuleSource.create("mercurial") testResult = mercurial.check_version(self._env) self.assertTrue(testResult) mercurial.attribute("url").value = "http://code.nsnam.org/bhurd/openflow" self._env._module_name="openflow-ns3" self._env._module_dir="openflow-ns3" testStatus = commands.getoutput('rm -rf /tmp/source') self._logger.set_current_module(self._env._module_name) testResult = mercurial.download(self._env) self.assertEqual(testResult, None) #check that has the waf version required installed in the machine testResult = waf.check_version(self._env) self.assertTrue(testResult) # Verirfies the path to the waf file testResult = waf._binary(self._env.srcdir) self.assertEqual(testResult, "/tmp/source/openflow-ns3/waf") # wrong path testResult = waf._binary("/tmp/source") self.assertEqual(testResult, "waf") # non existing path testResult = waf._binary("/NonExistant/Path") self.assertEqual(testResult, "waf") # Expected case test self._env.objdir = self._env.srcdir+"/object" # test patch self.assertEqual(waf.attribute('patch').value, '') waf.attribute('patch').value = self._env.srcdir + '/test.patch' self.assertEqual(waf.attribute('patch').value, self._env.srcdir + '/test.patch') testResult = None try: testResult = waf.add_attribute('patch', 'ERRROR', 'SHOULD NOT HAVE BEEN ADDED') self.fail("The attribute patch exists already, should not be" + " able to add it. ") except AssertionError as e: self.assertNotEqual(e, None) self.assertEqual(testResult, None) try: testResult = waf.build(self._env, "1") self.fail("The patch does not exist, should not have being able" + " to find the path file and give an error. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) testStatus = commands.getoutput('cp test.patch /tmp/source/' 'openflow-ns3/test.patch' ) # creates the file, empty, but created waf.attribute('patch').value = '/tmp/source/openflow-ns3/test.patch' self.assertEqual(waf.attribute('patch').value, '/tmp/source/' 'openflow-ns3/test.patch') waf.attribute('configure_arguments').value = 'configure' try: testResult = waf.build(self._env, "1") except TaskError as t: print(t.reason) self.assertEqual(testResult, None) testStatus = commands.getoutput('ls /tmp/source/openflow-ns3/build|wc') created = re.compile(' +\d+').search(testStatus).group().strip() self.assertNotEqual(created, "0") waf.attribute('patch').value = '' # call the distclean to remove the build testResult = waf.distclean(self._env) self.assertEqual(testResult, None) testStatus = commands.getoutput('ls /tmp/source/openflow-ns3/build|wc') created = re.compile(' +\d+').search(testStatus).group().strip() self.assertEqual(created, "0") # Call with extra options # TODO: find a solution either use another packet, like pybindgen, that # uses waf, or see to fix the openflow, because open flow does not accept # the configure arguments even though it is in the example of the # man page --enable-examples --enable-tests does not compile gives an error # flolowed the steps of http://www.nsnam.org/docs/models/html/openflow-switch.html waf.attribute("CFLAGS").value = "-g" # waf.attribute("configure_arguments").value = " " # waf.attribute("builarguments").value = "-O2" try: testResult = waf.build(self._env, "1") except TaskError as t: print(t.reason) self.assertEqual(testResult, None) testStatus = commands.getoutput('ls /tmp/source/openflow-ns3/build/default/lib|wc') created = re.compile(' +\d+').search(testStatus).group().strip() self.assertNotEqual(created, "0") # call the clean to remove the build testResult = waf.clean(self._env) self.assertEqual(testResult, None) testStatus = commands.getoutput('ls /tmp/source/openflow-ns3/build/default/lib|wc') created = re.compile(' +\d+').search(testStatus).group().strip() self.assertEqual(created, "0") # TODO: # test if the object dir is equal to the source dir, for the open flow # case it is not allowed but I am not sure for everyone else # self._env.objdir = self._env.srcdir # try: # testResult = waf.build(self._env, "1") # self.fail("The source and destination are the same but it " + # "passed without an exception. ") # except TaskError as e: # self.assertNotEqual(e._reason, None) # self.assertEqual(testResult, None) # TODO: # non existing path # need to find a good case of test for this # testResult = waf._is_1_6_x(self._env) # self.assertFalse(testResult) def test_WafModuleBuildPybind(self): """Tests the WafModuleBuild Class from ModuleBuild. """ waf = ModuleBuild.create("waf") self.assertNotEqual(waf, None) self.assertEqual(waf.name(), "waf") waf.attribute("configure_arguments").value = "configure" self._env.start_build("waf", "/tmp", waf.supports_objdir) testResult = None testResult = waf.check_version(self._env) self.assertFalse(testResult) # Environment settings bazaar = ModuleSource.create("bazaar") testResult = bazaar.check_version(self._env) self.assertTrue(testResult) bazaar.attribute("url").value = "https://launchpad.net/pybindgen" self._env._module_name="pybindgen" self._env._module_dir="pybindgen" self._logger.set_current_module(self._env._module_name) # bazaar.attribute("revision").value = "revno:795" self._env._module_name="pybindgen" self._env._module_dir="pybindgen" testStatus = commands.getoutput('mkdir /tmp/source') self._logger.set_current_module(self._env._module_name) testResult = bazaar.download(self._env) self.assertEqual(testResult, None) #check that has the waf version required installed in the machine testResult = waf.check_version(self._env) self.assertTrue(testResult) # Verirfies the path to the waf file testResult = waf._binary(self._env.srcdir) self.assertEqual(testResult, "/tmp/source/pybindgen/waf") # wrong path testResult = waf._binary("/tmp/source") self.assertEqual(testResult, "waf") # non existing path testResult = waf._binary("/NonExistant/Path") self.assertEqual(testResult, "waf") # Expected case test self._env.objdir = self._env.srcdir+"/object" # test patch self.assertEqual(waf.attribute('patch').value, '') waf.attribute('patch').value = self._env.srcdir + '/test.patch' self.assertEqual(waf.attribute('patch').value, self._env.srcdir + '/test.patch') testResult = None try: testResult = waf.add_attribute('patch', 'ERRROR', 'SHOULD NOT HAVE BEEN ADDED') self.fail("The attribute patch exists already, should not be" + " able to add it. ") except AssertionError as e: self.assertNotEqual(e, None) self.assertEqual(testResult, None) try: testResult = waf.build(self._env, "1") self.fail("The patch does not exist, should not have being able" + " to find the path file and give an error. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # creates the file, empty, but created testStatus = commands.getoutput('touch ' + self._env.srcdir + '/test.patch') testStatus = commands.getoutput('rm -rf /tmp/source/pybindgen/object') try: testResult = waf.build(self._env, "1") except TaskError as e: self.assertTrue(e._reason.startswith('Could not install') or e._reason.startswith('Subprocess failed')) self.assertEqual(testResult, None) testStatus = os.path.exists('/tmp/source/pybindgen/object') self.assertFalse(testStatus) # call the clean to remove the build # TODO: Find a solution for the remaining directories # - It is strange because the waf does not remove the directories, # just the object files.... Should this be like that??!?! testResult = waf.clean(self._env) self.assertEqual(testResult, None) testStatus = os.path.exists('/tmp/source/pybindgen/object/default/tests') self.assertFalse(testStatus) # TODO: neighter the --generate-version appears but I couldn't also # find a configuration argument for pybindgen :( # Call with extra options waf.attribute("CFLAGS").value = "-g" waf.attribute("configure_arguments").value = "configure" waf.attribute("build_arguments").value = "--generate-version" try: testResult = waf.build(self._env, "1") except TaskError as e: self.assertTrue(e._reason.startswith('Could not install') or e._reason.startswith('Subprocess failed')) self.assertEqual(testResult, None) testStatus = os.path.exists('/tmp/source/openflow-ns3/object') self.assertFalse(testStatus) # TODO: # non existing path # need to find a good case of test for this # testResult = waf._is_1_6_x(self._env) # self.assertFalse(testResult) def test_CmakeModule(self): """Tests the WafModuleBuild Class from ModuleBuild. """ cmake = ModuleBuild.create("cmake") self.assertNotEqual(cmake, None) self.assertEqual(cmake.name(), "cmake") self._env.start_build("cmake", "/tmp", cmake.supports_objdir) # Environment settings cvs = ModuleSource.create("cvs") testResult = cvs.check_version(self._env) self.assertTrue(testResult) cvs.attribute("root").value = ":pserver:anoncvs:@www.gccxml.org:/cvsroot/GCC_XML" cvs.attribute("module").value="gccxml" cvs.attribute("date").value="2009-09-21" self._env._module_name="gccxml" self._env._module_dir="gccxml" self._logger.set_current_module(self._env._module_name) # bazaar.attribute("revision").value = "revno:795" testStatus = commands.getoutput('mkdir /tmp/source') testResult = cvs.download(self._env) self.assertEqual(testResult, None) #check that has the cmake version required is installed in the machine testResult = cmake.check_version(self._env) self.assertTrue(testResult) # Expected case test self._env.objdir = self._env.srcdir+"/object" # test patch self.assertEqual(cmake.attribute('patch').value, '') cmake.attribute('patch').value = self._env.srcdir + '/test.patch' self.assertEqual(cmake.attribute('patch').value, self._env.srcdir + '/test.patch') testResult = None try: testResult = cmake.add_attribute('patch', 'ERRROR', 'SHOULD NOT HAVE BEEN ADDED') self.fail("The attribute patch exists already, should not be" + " able to add it. ") except AssertionError as e: self.assertNotEqual(e, None) self.assertEqual(testResult, None) try: testResult = cmake.build(self._env, "1") self.fail("The patch does not exist, should not have being able" + " to find the path file and give an error. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # creates the file, empty, but created testStatus = commands.getoutput('touch ' + self._env.srcdir + '/test.patch') testStatus = commands.getoutput('rm -rf /tmp/source/gccxml/object') try: testResult = cmake.build(self._env, "1") except TaskError as t: print("Error compiling the module, maybe gccxml is not compatible with this architecture") self.assertEqual(testResult, None) testStatus = commands.getoutput('ls /tmp/source/gccxml/object|wc') created = re.compile(' +\d+').search(testStatus).group().strip() self.assertNotEqual(created, "0") # call the distclean to remove the build #TODO: This module does not accepts distclean find another one to test # testResult = cmake.distclean(self._env) # self.assertEqual(testResult, None) # testStatus = commands.getoutput('ls /tmp/source/gccxml/object|wc') # created = re.compile(' +\d+').search(testStatus).group().strip() # self.assertEqual(created, "0") # call the clean to remove the build # TODO: Find a solution for the remaining directories # - It is strange because the waf does not remove the directories, # just the object files.... Should this be like that??!?! testResult = cmake.clean(self._env) self.assertEqual(testResult, None) testStatus = commands.getoutput('ls /tmp/source/gccxml/object/GCC/' 'gcc/CMakeFiles/backend.dir/*.o|wc') created = re.compile(' +\d+').search(testStatus).group().strip() self.assertEqual(created, "0") # TODO: neighter the --generate-version appears but I couldn't also # find a configuration argument for pybindgen :( # Call with extra options cmake.attribute("CFLAGS").value = "-g" # waf.attribute("configure_arguments").value = "--enable-examples --enable-tests" # cmake.attribute("builarguments").value = "--generate-version" try: testResult = cmake.build(self._env, "1") except TaskError as t: print("Error compiling the module, maybe gccxml is not compatible with this architecture") self.assertEqual(testResult, None) testStatus = commands.getoutput('ls -l /tmp/source/gccxml/object|wc') created = re.compile(' +\d+').search(testStatus).group().strip() self.assertNotEqual(created, "0") def test_makeModule(self): """Tests the WafModuleBuild Class from ModuleBuild. """ make = ModuleBuild.create("make") self.assertNotEqual(make, None) self.assertEqual(make.name(), "make") make.attribute('install_arguments').value = 'PREFIX=/tmp/source/readversiondef' self._env.start_build("make", "/tmp", make.supports_objdir) # Environment settings mercurial = ModuleSource.create("mercurial") testResult = mercurial.check_version(self._env) self.assertTrue(testResult) mercurial.attribute("url").value = "http://code.nsnam.org/mathieu/readversiondef" self._env._module_name="readversiondef" self._env._module_dir="readversiondef" testStatus = commands.getoutput('rm -rf /tmp/source') self._logger.set_current_module(self._env._module_name) testResult = mercurial.download(self._env) self.assertEqual(testResult, None) #check that has the make version required is installed in the machine testResult = make.check_version(self._env) self.assertTrue(testResult) # Expected case test self._env.objdir = self._env.srcdir+"/object" # test patch self.assertEqual(make.attribute('patch').value, '') make.attribute('patch').value = self._env.srcdir + '/test.patch' self.assertEqual(make.attribute('patch').value, self._env.srcdir + '/test.patch') testResult = None try: testResult = make.add_attribute('patch', 'ERRROR', 'SHOULD NOT HAVE BEEN ADDED') self.fail("The attribute patch exists already, should not be" + " able to add it. ") except AssertionError as e: self.assertNotEqual(e, None) self.assertEqual(testResult, None) try: testResult = make.build(self._env, "1") self.fail("The patch does not exist, should not have being able" + " to find the path file and give an error. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # creates the file, empty, but created testStatus = commands.getoutput('touch ' + self._env.srcdir + '/test.patch') testStatus = commands.getoutput('rm -rf /tmp/source/readversiondef/object') try: testResult = make.build(self._env, "1") except TaskError as t: print(t.reason) self.assertEqual(testResult, None) make.attribute('patch').value = '' testStatus = commands.getoutput('ls /tmp/source/readversiondef/bin|wc') created = re.compile(' +\d+').search(testStatus).group().strip() self.assertNotEqual(created, "0") #TODO: This module does not accepts distclean find another one to test # testResult = make.distclean(self._env) # self.assertEqual(testResult, None) # testStatus = commands.getoutput('ls /tmp/source/readversiondef/bin|wc') # created = re.compile(' +\d+').search(testStatus).group().strip() # self.assertEqual(created, "0") # call the clean to remove the build # TODO: This module does not support make clean find another one # testResult = make.clean(self._env) # self.assertEqual(testResult, None) # testStatus = commands.getoutput('ls /tmp/source/readversiondef/*.o|wc') # created = re.compile(' +\d+').search(testStatus).group().strip() # self.assertEqual(created, "0") # TODO: neither the --generate-version appears but I couldn't also # find a configuration argument for pybindgen :( # Call with extra options make.attribute("configure_arguments").value = "all" try: testResult = make.build(self._env, "1") except TaskError as t: print(t.reason) self.assertEqual(testResult, None) make.attribute('configure_arguments').value = '' make.attribute("post_installation").value = "rm -rf /tmp/source/readversiondef/readversiondef.o" try: testResult = make.build(self._env, "1") except TaskError as t: print(t.reason) self.assertEqual(testResult, None) make.perform_post_installation(self._env) testStatus = commands.getoutput('ls /tmp/source/readversiondef/*.o|wc') created = re.compile(' +\d+').search(testStatus).group().strip() self.assertEqual(created, "0") def test_genneral_build_arguments(self): """Tests the genneral arguments passed to the Build. """ waf = ModuleBuild.create("waf") self.assertNotEqual(waf, None) self.assertEqual(waf.name(), "waf") waf.attribute("configure_arguments").value = "configure" self._env._module_name="pybindgen" self._env.start_build("genneral", "/tmp", waf.supports_objdir) # # Environment settings # bazaar = ModuleSource.create("bazaar") # testResult = bazaar.check_version(self._env) # self.assertTrue(testResult) # # bazaar.attribute("url").value = "https://launchpad.net/pybindgen" # self._env._module_dir="pybindgen" # self._logger.set_current_module(self._env._module_name) # testResult = bazaar.download(self._env) # self.assertEqual(testResult, None) waf.attribute("v_PATH").value = "test_Path_added_value" waf.threat_variables(self._env) self.assertTrue(len(self._env._libpaths) == 1) self.assertTrue(len(self._env._binpaths) == 1) self.assertTrue(self._env._libpaths.__contains__("test_Path_added_value")) self.assertTrue(self._env._binpaths.__contains__("test_Path_added_value")) waf.attribute("v_PATH").value = "secondTest;thirdValue" waf.threat_variables(self._env) self.assertTrue(len(self._env._libpaths) == 3) self.assertTrue(len(self._env._binpaths) == 3) self.assertTrue(self._env._libpaths.__contains__("test_Path_added_value")) self.assertTrue(self._env._binpaths.__contains__("test_Path_added_value")) self.assertTrue(self._env._libpaths.__contains__("secondTest")) self.assertTrue(self._env._binpaths.__contains__("secondTest")) self.assertTrue(self._env._libpaths.__contains__("thirdValue")) self.assertTrue(self._env._binpaths.__contains__("thirdValue")) waf.attribute("v_PATH").value = "" waf.attribute("v_LD_LIBRARY").value = "test_ld_Path_added_value" waf.threat_variables(self._env) self.assertTrue(len(self._env._libpaths) == 4) self.assertTrue(len(self._env._binpaths) == 3) self.assertTrue(self._env._libpaths.__contains__("test_ld_Path_added_value")) waf.attribute("v_LD_LIBRARY").value = "secondTestLD;thirdValueLD" waf.threat_variables(self._env) self.assertTrue(len(self._env._libpaths) == 6) self.assertTrue(len(self._env._binpaths) == 3) self.assertTrue(self._env._libpaths.__contains__("test_Path_added_value")) self.assertTrue(self._env._libpaths.__contains__("secondTest")) self.assertTrue(self._env._libpaths.__contains__("thirdValue")) self.assertTrue(self._env._libpaths.__contains__("test_ld_Path_added_value")) self.assertTrue(self._env._libpaths.__contains__("secondTestLD")) self.assertTrue(self._env._libpaths.__contains__("thirdValueLD")) # try to add repeated values waf.attribute("v_LD_LIBRARY").value = "secondTestLD;thirdValueLD" waf.threat_variables(self._env) self.assertTrue(len(self._env._libpaths) == 6) self.assertTrue(len(self._env._binpaths) == 3) waf.attribute("v_PATH").value = "" waf.attribute("v_LD_LIBRARY").value = "" self.assertTrue(len(self._env._pkgpaths) == 0) waf.attribute("v_PKG_CONFIG").value = "test_pkg_added_value" waf.threat_variables(self._env) self.assertTrue(len(self._env._pkgpaths) == 1) self.assertTrue(len(self._env._binpaths) == 3) self.assertTrue(len(self._env._libpaths) == 6) self.assertTrue(self._env._pkgpaths.__contains__("test_pkg_added_value")) waf.attribute("v_PKG_CONFIG").value = "secondTestPkg;thirdValuePkg" waf.threat_variables(self._env) self.assertTrue(len(self._env._pkgpaths) == 3) self.assertTrue(len(self._env._libpaths) == 6) self.assertTrue(len(self._env._binpaths) == 3) self.assertTrue(self._env._pkgpaths.__contains__("test_pkg_added_value")) self.assertTrue(self._env._pkgpaths.__contains__("secondTestPkg")) self.assertTrue(self._env._pkgpaths.__contains__("thirdValuePkg")) # try to add repeated values waf.attribute("v_PKG_CONFIG").value = "secondTestPkg;thirdValuePkg" waf.threat_variables(self._env) self.assertTrue(len(self._env._pkgpaths) == 3) self.assertTrue(len(self._env._libpaths) == 6) self.assertTrue(len(self._env._binpaths) == 3) def test_pre_installation(self): """Tests pre instalation command call. """ waf = ModuleBuild.create("waf") self._env.start_build("testModule", "testModule", waf.supports_objdir) self.assertNotEqual(waf, None) self.assertEqual(waf.name(), "waf") waf.attribute("pre_installation").value = "ls" testResult = waf.perform_pre_installation(self._env) self.assertTrue(testResult) waf.attribute("pre_installation").value = "ls or mm567" testResult = waf.perform_pre_installation(self._env) self.assertTrue(testResult) waf.attribute("pre_installation").value = "mm567 or ls" testResult = waf.perform_pre_installation(self._env) self.assertTrue(testResult) waf.attribute("pre_installation").value = "mm567 or mm567" testResult = waf.perform_pre_installation(self._env) self.assertFalse(testResult) waf.attribute("pre_installation").value = "mm567 or mm567 or ls" testResult = waf.perform_pre_installation(self._env) self.assertTrue(testResult) waf.attribute("pre_installation").value = "mm576 or VARTT=/;ls $VARTT" testResult = waf.perform_pre_installation(self._env) self.assertTrue(testResult) def test_supported_os(self): """Tests pre instalation command call. """ waf = ModuleBuild.create("waf") self.assertNotEqual(waf, None) self.assertEqual(waf.name(), "waf") import platform osName = platform.system().lower() # self.assertTrue(osName.startswith('linux')) waf.attribute("supported_os").value = osName # "linux" testResult = waf.check_os(waf.attribute("supported_os").value) self.assertTrue(testResult) waf.attribute("supported_os").value = "xypto;linux;"+osName testResult = waf.check_os(waf.attribute("supported_os").value) self.assertTrue(testResult) waf.attribute("supported_os").value = "darwin;bsd;linux".replace(osName, "xypto") testResult = waf.check_os(waf.attribute("supported_os").value) self.assertFalse(testResult) waf.attribute("supported_os").value = "" testResult = waf.check_os(waf.attribute("supported_os").value) self.assertFalse(testResult) def test_fullclean(self): """Tests distclean command call. """ waf = ModuleBuild.create("waf") self.assertNotEqual(waf, None) self.assertEqual(waf.name(), "waf") # Environment settings mercurial = ModuleSource.create("mercurial") testResult = mercurial.check_version(self._env) self.assertTrue(testResult) mercurial.attribute("url").value = "http://code.nsnam.org/bhurd/openflow" self._env._module_name="openflow-ns3" self._env._module_dir="openflow-ns3" self._env._objdir = "/tmp/object_openflow" self._env._installdir = "/tmp/install_openflow" testStatus = commands.getoutput('rm -rf /tmp/source') self._logger.set_current_module(self._env._module_name) testResult = mercurial.download(self._env) self.assertEqual(testResult, None) self._env.start_build("openflow-ns3", "/tmp/source/openflow-ns3", True) waf.attribute('configure_arguments').value = 'configure --prefix='+ self._env.installdir + ' --destdir=' + self._env.installdir + ' --blddir=' + self._env.objdir try: testResult = waf.build(self._env, "1") except TaskError as t: print(t.reason) self.assertEqual(testResult, None) testStatus = os.path.isdir('/tmp/source/openflow-ns3') self.assertTrue(testStatus) testStatus = os.path.isdir('/tmp/object_openflow') self.assertTrue(testStatus) module = Module(self._env._module_name, mercurial, waf) module._module_supports_objdir = True self._env.end_build() try: testResult = module.fullclean(self._env) except TaskError as t: print(t.reason) self.assertTrue(testResult) testStatus = os.path.isdir('/tmp/source/openflow-ns3') self.assertFalse(testStatus) testStatus = os.path.isdir('/tmp/source/object_openflow') self.assertFalse(testStatus) testStatus = os.path.isdir('/tmp/source/install_openflow') self.assertFalse(testStatus)
def setUp(self): """Common set Up environment, available for all tests.""" pathname = os.path.dirname("/tmp/") self._logger = StdoutModuleLogger(); self._logger.set_verbose(0) self._env = ModuleEnvironment(self._logger, pathname, pathname, pathname)
class TestModuleSource(unittest.TestCase): """Tests cases for the Module Environment Class.""" def setUp(self): """Common set Up environment, available for all tests.""" pathname = os.path.dirname("/tmp/") self._logger = StdoutModuleLogger(); self._logger.set_verbose(0) self._env = ModuleEnvironment(self._logger, pathname, pathname, pathname) def tearDown(self): """Cleans the environment environment for the next tests.""" self._env = None def execute_command(self, command, dir): """Executes the given command, catching the exceptions.""" try: self._env.run(command, dir) except Exception as inst: print (inst) # the exception instance self.fail("Could not execute command %s over directory %s failed" % (command, dir)) def test_general_failures(self): """Tests Some general failures that could happen in the Module Source. """ #Verifies the return of the creation of a non existent module module = ModuleSource.create("NonExistentModule") self.assertEqual(module, None) def test_archive_module_source(self): """Tests the ArchiveModuleSource class. """ # it first needs to be able to create the class otherwise will not be # able to do anything else archive = ModuleSource.create("archive") self.assertNotEqual(archive, None) self.assertEqual(archive.name(), "archive") # Verifies if the system has the right tools installed, if not does not # even worth continuing # no file was declared yet, so the issue should be False testResult = archive.check_version(self._env) self.assertFalse(testResult) # Unknown file type archive.attribute("url").value = "http://JustATest.com/File.unknownFileType" testResult = archive.check_version(self._env) self.assertFalse(testResult, "There is no tool to handle the target extension, the result should be false") # zip archive.attribute("url").value = "http://JustATest.com/File.zip" testResult = archive.check_version(self._env) self.assertTrue(testResult, "unzip is not present on the system") # rar archive.attribute("url").value = "http://JustATest.com/File.rar" testResult = archive.check_version(self._env) self.assertTrue(testResult, "unrar is not present on the system") # tar archive.attribute("url").value = "http://JustATest.com/File.tar" testResult = archive.check_version(self._env) self.assertTrue(testResult, "tar is not present on the system") # tar.Z archive.attribute("url").value = "http://JustATest.com/File.tar.Z" testResult = archive.check_version(self._env) self.assertTrue(testResult, "tar is not present on the system") # tar.bz2 archive.attribute("url").value = "http://JustATest.com/File.tar.bz2" testResult = archive.check_version(self._env) self.assertTrue(testResult, "tar is not present on the system") # tar.gz archive.attribute("url").value = "http://read.cs.ucla.edu/click/click-1.8.0.tar.gz" # archive.attribute("url").value = "http://read.cs.ucla.edu/click/click-1.8.0.tar.gz" testResult = archive.check_version(self._env) self.assertTrue(testResult, "tar is not present on the system") self._env._module_name="click-1.8.0" self._logger.set_current_module(self._env._module_name) #clean up the environment, just to be safe self.execute_command(["/bin/rm", "-rf", "click-1.8.0.tar.gz"], "/tmp") self.execute_command(["/bin/rm", "-rf", "click-1.8.0"], "/tmp") testResult = archive.download(self._env) # if something goes wrong it should rise an exception so, None means # everything is OK self.assertEqual(testResult, None) # verifies that files are really there after the download testStatus = commands.getoutput('ls /tmp/click-1.8.0.tar.gz') self.assertEqual("/tmp/click-1.8.0.tar.gz", testStatus) testStatus = commands.getoutput('ls -d /tmp/click-1.8.0') self.assertEqual("/tmp/click-1.8.0", testStatus) #after the test, clean the environment self.execute_command(["/bin/rm", "-rf", "click-1.8.0.tar.gz"], "/tmp") self.execute_command(["/bin/rm", "-rf", "click-1.8.0"], "/tmp") # Searches for a valid file into an inexistent repository archive.attribute("url").value = "http://non.existent.host.com/click-1.8.0.tar.gz" testResult = None try: testResult = archive.download(self._env) self.fail("There was no problem, and the server does not exist. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # Try to download to a directory that the user has no permission archive.attribute("url").value = "http://read.cs.ucla.edu/click/click-1.8.0.tar.gz" testStatus = commands.getoutput('touch /tmp/click-1.8.0;chmod 000 /tmp/click-1.8.0') testResult = None try: testResult = archive.download(self._env) self.fail("There was no problem, the user has no permission over the target directory. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) testStatus = commands.getoutput("chmod 755 /tmp/click-1.8.0; rm -f " "/tmp/click-1.8.0") # try to download to a non existent directory testStatus = commands.getoutput('rm -rf /tmp/testDir') self._env._sourcedir = "/tmp/testDir" testResult = None try: testResult = archive.download(self._env) self.fail("There was no problem, target directory does not exist " "and it managed to finish the operation. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) testStatus = commands.getoutput('mkdir /tmp/testDir;chmod 000 /tmp/testDir') testResult = None try: testResult = archive.download(self._env) self.fail("There was no problem, user has no permission on the " "target directory and it managed to finish the operation.") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) testStatus = commands.getoutput('chmod 755 /tmp/testDir; rm -rf /tmp/testDir') # no protocol download url gives you an error archive.attribute("url").value = "read.cs.ucla.edu/click/click-1.8.0.tar.gz" testResult = None try: testResult = archive.download(self._env) self.fail("There was no problem, the user didn't add the protocol" " for the url. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # just to be sure that the update does nothing testResult = archive.update(self._env) self.assertEqual(testResult, None) # Oddly enough, when the user has no permission in the target # directory the system returns no error Right now I have no idea how # to fix it, or IF we should try to fix anyway. # self._env._sourcedir = "/tmp" # testStatus = commands.getoutput('mkdir /tmp/click-1.8.0;chmod 000 /tmp/click-1.8.0') # try: # testResult = archive.download(self._env) # self.fail("There was not problem, the user has no permission over the target directory. ") # except TaskError as e: # self.assertNotEqual(e._reason, None) # self.assertEqual(testResult, None) # # testStatus = commands.getoutput('chmod 755 /tmp/click-1.8.0; rm -rf /tmp/click-1.8.0') def test_check_dependency_expression(self): """ Tests the _check_dependency_expression method. """ # it first needs to be able to create the class otherwise will not be # able to do anything else installer = ModuleSource.create("system_dependency") self.assertNotEqual(installer, None) self.assertEqual(installer.name(), "system_dependency") self._env._module_name="testModule" self._logger.set_current_module(self._env._module_name) # Unknown file type installer.attribute('more_information').value = "Just a test" installer.attribute('sudoer_install').value = 'False' installer.attribute("try_to_install").value='True' installer.attribute("dependency_test").value = "NonExistentSoftForTest" testResult = None testResult = installer._check_dependency_expression(self._env, "NonExistentSoft") self.assertFalse(testResult, "Non existent software, should be false") testResult = None testResult = installer._check_dependency_expression(self._env, "bash") self.assertTrue(testResult, "Existent software, should be true") testResult = None testResult = installer._check_dependency_expression(self._env, "nthing or bash") self.assertTrue(testResult, "Existent software, should be true") testResult = None testResult = installer._check_dependency_expression(self._env, "nthinag and bash") self.assertFalse(testResult, "Inexistent software AND existent one, " "should be false") testResult = None testResult = installer._check_dependency_expression(self._env, "not bash") self.assertFalse(testResult, "The software should exist so it, " "should be false") testResult = None testResult = installer._check_dependency_expression(self._env, "not nthing") self.assertTrue(testResult, "The software does not exist so it, " "should be true") testResult = None testResult = installer._check_dependency_expression(self._env, "/bin/ls") self.assertTrue(testResult, "The software exist so it, " "should be true") testResult = None testResult = installer._check_dependency_expression(self._env, "/lib") self.assertTrue(testResult, "The repository exist so it, " "should be true") testResult = None testResult = installer._check_dependency_expression(self._env, "/tt/NoDirDir") self.assertFalse(testResult, "The repository does not exist so it, " "should be False") testResult = None testResult = installer._check_dependency_expression(self._env, "libc.so") self.assertTrue(testResult, "The library should exist so it, " "should be True") testResult = None testResult = installer._check_dependency_expression(self._env, "notValidLibNot.so") self.assertFalse(testResult, "The library should not exist so it, " "should be False") def test_SystemDependencySource(self): """Tests the SelfInstallerModule class. """ # it first needs to be able to create the class otherwise will not be # able to do anything else installer = ModuleSource.create("system_dependency") self.assertNotEqual(installer, None) self.assertEqual(installer.name(), "system_dependency") # Verifies if the system has the right tools installed, if not does not # even worth continuing # Verify if the installer, for this architecture exists testResult = installer.check_version(self._env) self.assertTrue(testResult) self._env._module_name="testModule" self._logger.set_current_module(self._env._module_name) # Unknown file type installer.attribute("dependency_test").value = "NonExistentSoftForTest" installer.attribute('more_information').value = "Message test for inexistent module" installer.attribute("try_to_install").value='True' installer.attribute("sudoer_install").value='True' testResult = None try : testResult = installer.download(self._env) except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # print(e._reason) installer.attribute("dependency_test").value = "gcc" installer.attribute('more_information').value = "You miss gcc download" " it from your linux distribution website" testResult = None try : testResult = installer.download(self._env) except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # print(e._reason) self.assertTrue(testResult) #try to install a non existent module installer.attribute("dependency_test").value = "erlang" installer.attribute('more_information').value = "You miss erlang, " "download it from your linux distribution website" installer.attribute('sudoer_install').value = 'True' testResult = None try : testResult = installer.download(self._env) except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # print(e._reason) self.assertTrue(testResult==None) # remove the NOT installed module testResult = None reason=None try : testResult = installer.remove(self._env) except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) reason=e._reason # print(e._reason) self.assertTrue(testResult==None) self.assertFalse(not reason) installer.attribute('name_yum').value = "erlang" installer.attribute('name_apt-get').value = "erlang" testResult = None reason=None try : testResult = installer.download(self._env) except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) reason=e._reason # print(e._reason) self.assertTrue(testResult==None) self.assertFalse(not reason) # Adds the sudo tag... now the modules should be able to be installed self._env._sudoEnabled=True # Just to be sure the erlang module is not installed on the machine testResult = None try : testResult = installer.remove(self._env) except TaskError as e: print(e._reason) # this installation should work for sure now! # remove the just installed module testResult = None reason=None try : testResult = installer.download(self._env) except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) reason=e._reason print(e._reason) self.assertTrue(testResult) self.assertTrue(not reason) # Just to be sure the erlang module is not installed on the machine testResult = None try : testResult = installer.remove(self._env) except TaskError as e: print(e._reason) def test_systemPrecondition(self): """Tests the SelfInstallerModule class. """ # it first needs to be able to create the class otherwise will not be # able to do anything else installer = ModuleSource.create("system_dependency") self.assertNotEqual(installer, None) testResult = installer._check_dependency_expression(self._env,"") self.assertTrue(testResult) testResult = installer._check_dependency_expression(self._env,"ls") self.assertTrue(testResult) testResult = installer._check_dependency_expression(self._env, "(ls and bash)") self.assertTrue(testResult) testResult = installer._check_dependency_expression(self._env, "(ls or us9245l25k)") self.assertTrue(testResult) testResult = installer._check_dependency_expression(self._env, "(ls and not us9245l25k)") self.assertTrue(testResult) testResult = installer._check_dependency_expression(self._env, "(ls and us9245l25k)") self.assertFalse(testResult) testResult = installer._check_dependency_expression(self._env, "(ls and bash) and rm") self.assertTrue(testResult) testResult = installer._check_dependency_expression(self._env, "(ls and bash) and us9245l25k") self.assertFalse(testResult) testResult = installer._check_dependency_expression(self._env, "(ls and bash) or us9245l25k") self.assertTrue(testResult) testResult = installer._check_dependency_expression(self._env, "((ls and bash) or us9245l25k)") self.assertTrue(testResult) def test_mercurial(self): """Tests the MercurialModuleSource class. """ # it first needs to be able to create the class otherwise will not be # able to do anything else mercurial = ModuleSource.create("mercurial") self.assertNotEqual(mercurial, None) self.assertEqual(mercurial.name(), "mercurial") # Verifies if the system has the mercurial installed, if not does not # even worth continuing testResult = mercurial.check_version(self._env) self.assertTrue(testResult) mercurial.attribute("url").value = "http://code.nsnam.org/daniel/bake" self._env._module_name="bake" self._logger.set_current_module(self._env._module_name) #clean up the environment, just to be safe self.execute_command(["/bin/rm", "-rf", "bake"], "/tmp") testResult = mercurial.download(self._env) # if something goes wrong it should rise an exception so, None means # everything is OK self.assertEqual(testResult, None) #after the test, clean the environment self.execute_command(["rm", "-rf", "bake"], "/tmp") # download a specific version mercurial.attribute("revision").value = "63" testResult = mercurial.download(self._env) self.assertEqual(testResult, None) # verify that the version is the correct one testStatus = commands.getoutput('cd /tmp/bake;hg summary') version = re.compile('\d+').search(testStatus).group() self.assertEqual(version, "63") # makes an update of the version to the last version mercurial.attribute("revision").value = "64" testResult = mercurial.update(self._env) self.assertEqual(testResult, None) # verify that the version is the correct one testStatus = commands.getoutput('cd /tmp/bake;hg summary') version = re.compile('\d+').search(testStatus).group() self.assertEqual(version, "64") # Verifies the update to the tip mercurial.attribute("revision").value = "tip" testResult = mercurial.update(self._env) self.assertEqual(testResult, None) # verify that the version is the correct one testStatus = commands.getoutput('cd /tmp/bake;hg log') versionRepository = re.compile('\d+').search(testStatus).group() testStatus = commands.getoutput('cd /tmp/bake;hg summary') versionDownloaded = re.compile('\d+').search(testStatus).group() self.assertEqual(versionRepository, versionDownloaded) self.execute_command(["rm", "-rf", "bake"], "/tmp") # Not http should give you a TaskError exception mercurial.attribute("url").value = "code.nsnam.org/daniel/bake" self._env._module_name="bake" self._logger.set_current_module(self._env._module_name) testResult = None try: testResult = mercurial.download(self._env) self.fail("There was no problem not passing the protocol. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) self.execute_command(["rm", "-rf", "bake"], "/tmp") testStatus = commands.getoutput('mkdir /tmp/bake;chmod 000 /tmp/bake') mercurial.attribute("url").value = "http://code.nsnam.org/daniel/bake" testResult = None try: testResult = mercurial.download(self._env) self.fail("There was no problem and the user has no permission" " over the directory. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) testStatus = commands.getoutput('chmod 755 /tmp/bake') self.execute_command(["rm", "-rf", "bake"], "/tmp") # try to download to a non existent directory # mercurial cretes the directory testStatus = commands.getoutput('rm -rf /tmp/testDir') self._env._sourcedir = "/tmp/testDir" testResult = mercurial.download(self._env) self.assertEqual(testResult, None) testStatus = commands.getoutput('rm -rf /tmp/testDir') testStatus = commands.getoutput('mkdir /tmp/testDir;chmod 000 /tmp/testDir') testResult = None try: testResult = mercurial.download(self._env) self.fail("There was no problem, user has no permission on the" " target directory and it managed to finish the operation. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) testStatus = commands.getoutput('chmod 755 /tmp/testDir; rm -rf /tmp/testDir') # Try to get a wrong version, there is a but in the mercurial # that permits negative revisions, such as -34, for example, # however bigger than the tip version gives an error mercurial.attribute("revision").value = "9999999" testResult = None try: testResult = mercurial.download(self._env) self.fail("The version is inexistent, but there is no error. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # last clean up self.execute_command(["rm", "-rf", "bake"], "/tmp") def test_bazaar(self): """Tests the BazaarModuleSource class. """ # checks if can create the class bazaar = ModuleSource.create("bazaar") self.assertNotEqual(bazaar, None) self.assertEqual(bazaar.name(), "bazaar") # Verifies if Bazaar is installed testResult = bazaar.check_version(self._env) self.assertTrue(testResult) bazaar.attribute("url").value = "https://launchpad.net/pybindgen" self._env._module_name="pybindgen" self._logger.set_current_module(self._env._module_name) ##### Normal Flow test #clean up the environment, just to be safe self.execute_command(["/bin/rm", "-rf", "pybindgen"], "/tmp") testResult = bazaar.download(self._env) # None means everything was OK, since there were no exceptions self.assertEqual(testResult, None) testStatus = commands.getoutput('cd /tmp/pybindgen; bzr log') lastVersion = re.compile('\d+').search(testStatus).group() #after the test, clean the environment self.execute_command(["rm", "-rf", "pybindgen"], "/tmp") # download a specific version bazaar.attribute("revision").value = "794" testResult = bazaar.download(self._env) self.assertEqual(testResult, None) # verify that the version is the correct one testStatus = commands.getoutput('cd /tmp/pybindgen; bzr log') version = re.compile('\d+').search(testStatus).group() self.assertEqual(version, "794") # makes an update of the version to a latter version bazaar.attribute("revision").value = "795" testResult = bazaar.update(self._env) self.assertEqual(testResult, None) # verify that the version is the correct one testStatus = commands.getoutput('cd /tmp/pybindgen; bzr log') version = re.compile('\d+').search(testStatus).group() self.assertEqual(version, "795") self.execute_command(["rm", "-rf", "pybindgen"], "/tmp") # Wrong repository bazaar.attribute("url").value = "http://code.nsnam.org/daniel/bake" self._logger.set_current_module(self._env._module_name) testResult = None try: testResult = bazaar.download(self._env) self.fail("There was no problem not passing the protocol. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # No protocol http/https bazaar.attribute("url").value = "launchpad.net/pybindgen" bazaar.attribute("revision").value = None self._logger.set_current_module(self._env._module_name) testResult = None try: testResult = bazaar.download(self._env) self.fail("There was no problem not passing the protocol. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) self.execute_command(["rm", "-rf", "pybindgen"], "/tmp") testStatus = commands.getoutput('mkdir /tmp/pybindgen;chmod 000 /tmp/pybindgen') bazaar.attribute("url").value = "https://launchpad.net/pybindgen" testResult = None try: testResult = bazaar.download(self._env) self.fail("There was no problem and the user has no permission" " over the directory. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) testStatus = commands.getoutput('chmod 755 /tmp/pybindgen') self.execute_command(["rm", "-rf", "pybindgen"], "/tmp") # try to download to a non existent directory testStatus = commands.getoutput('rm -rf /tmp/testDir') self._env._sourcedir = "/tmp/testDir" testResult = None try: testResult = bazaar.download(self._env) self.fail("There was no problem, target directory does not exist" " and it managed to finish the operation. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # try to download to a directory where the user has no permission testStatus = commands.getoutput('mkdir /tmp/testDir;chmod 000 /tmp/testDir') testResult = None try: testResult = bazaar.download(self._env) self.fail("There was no problem, user has no permission on the" " target directory and it managed to finish the operation. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) testStatus = commands.getoutput('chmod 755 /tmp/testDir; rm -rf /tmp/testDir') # returns to the original state bazaar.attribute("url").value = "https://launchpad.net/pybindgen" self._env._sourcedir = "/tmp" # Try to get an unavailable version bazaar.attribute("revision").value = str(int(lastVersion) + 1) testResult = None try: testResult = bazaar.download(self._env) self.fail("The version is inexistent, but there is no error. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # verifies the update to a inexistent version bazaar.attribute("revision").value = None testResult = bazaar.download(self._env) self.assertEqual(testResult, None) # Invalid argument, it is int and should be string bazaar.attribute("revision").value = -60 testResult = None try: testResult = bazaar.download(self._env) self.fail("The version is inexistent, but there is no error. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # can not go for a negative version bazaar.attribute("revision").value = str(-60) testResult = None try: testResult = bazaar.download(self._env) self.fail("The version is inexistent, but there is no error. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # last clean up self.execute_command(["rm", "-rf", "pybindgen"], "/tmp") def test_cvs(self): """Tests the CvsModuleSourceclass. """ # checks if can create the class cvs = ModuleSource.create("cvs") self.assertNotEqual(cvs, None) self.assertEqual(cvs.name(), "cvs") # Verifies if cvs is installed testResult = cvs.check_version(self._env) self.assertTrue(testResult) cvs.attribute("root").value = ":pserver:anoncvs:@www.gccxml.org:/cvsroot/GCC_XML" cvs.attribute("module").value="gccxml" cvs.attribute("date").value="2009-09-21" self._env._module_name="gccxml" self._logger.set_current_module(self._env._module_name) ##### Normal Flow test #clean up the environment, just to be safe self.execute_command(["/bin/rm", "-rf", "gccxml"], "/tmp") testResult = cvs.download(self._env) # None means everything was OK, since there were no exceptions self.assertEqual(testResult, None) # will use the README file to see if the update works testStatus = commands.getoutput('cd /tmp/gccxml; cvs status CMakeLists.txt') lastVersion = re.compile('\d+.\d+').search(testStatus).group().replace(".","") #after the test, clean the environment self.execute_command(["rm", "-rf", "gccxml"], "/tmp") # download a specific version cvs.attribute("date").value="2007-09-21" testResult = cvs.download(self._env) self.assertEqual(testResult, None) # verify that the version is the correct one testStatus = commands.getoutput('cd /tmp/gccxml; cvs status CMakeLists.txt') version = re.compile('\d+.\d+').search(testStatus).group().replace(".","") self.assertEqual(version, "18") # makes an update of the version to a latter version cvs.attribute("date").value="2008-09-21" testResult = cvs.update(self._env) self.assertEqual(testResult, None) # verify that the version is bigger than the previous one testStatus = commands.getoutput('cd /tmp/gccxml; cvs status CMakeLists.txt') version2 = re.compile('\d+.\d+').search(testStatus).group().replace(".","") self.assertTrue((float(version) < float(version2))) # Verify if it updates to today's version cvs.attribute("date").value=None testResult = cvs.update(self._env) self.assertEqual(testResult, None) testStatus = commands.getoutput('cd /tmp/gccxml; cvs status CMakeLists.txt') version3 = re.compile('\d+.\d+').search(testStatus).group().replace(".","") self.assertTrue(float(version2) < float(version3)) self.execute_command(["rm", "-rf", "gccxml"], "/tmp") # Wrong repository cvs.attribute("root").value = ":pserver:anoncvs:@non.Existent.server.com:/cvsroot/GCC_XML" cvs.attribute("date").value="2008-09-21" self._logger.set_current_module(self._env._module_name) testResult = None try: testResult = cvs.download(self._env) self.fail("There was no problem with a non existent repository. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) self.execute_command(["rm", "-rf", "gccxml"], "/tmp") # try to download to a non existent directory testStatus = commands.getoutput('rm -rf /tmp/testDir') self._env._sourcedir = "/tmp/testDir" testResult = None try: testResult = cvs.download(self._env) self.fail("There was no problem, target directory does not exist" " and it managed to finish the operation. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # try to download to a directory where the user has no permission testStatus = commands.getoutput('mkdir /tmp/testDir;chmod 000 /tmp/testDir') testResult = None try: testResult = cvs.download(self._env) self.fail("There was no problem, user has no permission on the" " target directory and it managed to finish the operation. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) testStatus = commands.getoutput('chmod 755 /tmp/testDir; rm -rf /tmp/testDir') # returns to the original state cvs.attribute("root").value = ":pserver:anoncvs:@www.gccxml.org:/cvsroot/GCC_XML" self._env._sourcedir = "/tmp" # Invalid argument, it is int and should be string cvs.attribute("checkout_directory").value = -60 testResult = None try: testResult = cvs.download(self._env) self.fail("The version is inexistent, but there is no error. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # can't go for an inexistent version cvs.attribute("checkout_directory").value = "/tmp" cvs.attribute("date").value="5000-09-21" testResult = None try: testResult = cvs.download(self._env) self.fail("The version is inexistent, but there is no error. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # last clean up self.execute_command(["rm", "-rf", "gccxml"], "/tmp") def test_git(self): """Tests the GitModuleSource. """ # checks if can create the class git = ModuleSource.create("git") self.assertNotEqual(git, None) self.assertEqual(git.name(), "git") # Verifies if git is installed testResult = git.check_version(self._env) self.assertTrue(testResult) git.attribute("url").value = "git://github.com/git/hello-world.git" git.attribute("revision").value = "78cfc43c2827b9e48e6586a3523ff845a6378889" self._env._module_name="hello-world" self._logger.set_current_module(self._env._module_name) ##### Normal Flow test #clean up the environment, just to be safe self.execute_command(["/bin/rm", "-rf", "hello-world"], "/tmp") testResult = git.download(self._env) # None means everything was OK, since there were no exceptions self.assertEqual(testResult, None) # will use the README file to see if the update works testStatus = commands.getoutput('cd /tmp/hello-world; git log') lastVersion = re.compile(' +\w+').search(testStatus).group().replace(" ","") self.assertEqual(lastVersion, "78cfc43c2827b9e48e6586a3523ff845a6378889") testResult = git.update(self._env) self.assertEqual(testResult, None) git.attribute("revision").value="45021a874e090b765acc5e2696154c495686614b" testResult = git.update(self._env) self.assertEqual(testResult, None) commands.getoutput("cat /tmp/hello-world/c.c >> /tmp/hello-world/dos.bat") testResult = git.update(self._env) self.assertEqual(testResult, None) #after the test, clean the environment self.execute_command(["rm", "-rf", "hello-world"], "/tmp") # download a specific version git.attribute("revision").value="3fa7c46d11b11d61f1cbadc6888be5d0eae21969" testResult = git.download(self._env) self.assertEqual(testResult, None) # verify that the version is the correct one testStatus = commands.getoutput('cd /tmp/hello-world; git log') version = re.compile(' +\w+').search(testStatus).group().replace(" ","") self.assertEqual(version, "3fa7c46d11b11d61f1cbadc6888be5d0eae21969") self.execute_command(["rm", "-rf", "gccxml"], "/tmp") #Wrong repository git.attribute("url").value = "git://inexistant.server.com/git/hello-world.git" git.attribute("revision").value = "78cfc43c2827b9e48e6586a3523ff845a6378889" self._logger.set_current_module(self._env._module_name) testResult = None try: testResult = git.download(self._env) self.fail("There was no problem with a non existent repository. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) self.execute_command(["rm", "-rf", "gccxml"], "/tmp") # no protocol git.attribute("url").value = "github.com/git/hello-world.git" self._logger.set_current_module(self._env._module_name) testResult = None try: testResult = git.download(self._env) self.fail("There was no problem without protocol. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) git.attribute("url").value = "git://github.com/git/hello-world.git" self.execute_command(["rm", "-rf", "gccxml"], "/tmp") # try to download to a non existent directory testStatus = commands.getoutput('rm -rf /tmp/testDir') self._env._sourcedir = "/tmp/testDir" testResult = None try: testResult = git.download(self._env) self.fail("There was no problem, target directory does not" " exist and it managed to finish the operation. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # try to download to a directory where the user has no permission testStatus = commands.getoutput('mkdir /tmp/testDir;chmod 000 /tmp/testDir') testResult = None try: testResult = git.download(self._env) self.fail("There was no problem, user has no permission on the" " target directory and it managed to finish the operation. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) testStatus = commands.getoutput('chmod 755 /tmp/testDir; rm -rf /tmp/testDir') # Invalid argument, it is int and should be string self._env._sourcedir = -60 testResult = None try: testResult = git.download(self._env) self.fail("The version is inexistent, but there is no error. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # returns to the original state self._env._sourcedir = "/tmp" # can't go for an inexistent version git.attribute("revision").value = "1000000000000000000000000000000000000000" testResult = None try: testResult = git.download(self._env) self.fail("The version is inexistent, but there is no error. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None)
class TestModuleEnvironment(unittest.TestCase): """Tests cases for the Module Environment Class.""" def setUp(self): """Common set Up environment, available for all tests.""" pathname = os.path.dirname(test.TestBake.compensate_third_runner()) if not pathname: pathname = "." logger = StdoutModuleLogger() self._env = ModuleEnvironment(logger, pathname, pathname, pathname) def tearDown(self): """Cleans the environment environment for the next tests.""" self._env = None # TODO: see if the tests work in other OS environments, I would guess not # to be honest I am not even sure bake would work on other OS either # TODO:2 Test the search on the current dir/bin def test___program_location(self): """Tests the _program_location method of Class ModuleEnvironment. """ testResult = self._env._program_location("string.h") self.assertNotEqual(testResult, None) testResult = self._env._program_location("complex.h") self.assertNotEqual(testResult, None) testResult = self._env._program_location("libc.so") self.assertNotEqual(testResult, None) testResult = self._env._program_location("NonExistent.so") self.assertEqual(testResult, None) testResult = self._env._program_location("NonExistent.h") self.assertEqual(testResult, None) # searches for link, on unix systems, normally java would be a soft link testResult = self._env._program_location("tar") self.assertNotEqual(testResult, None) # specific program flow, when the directory is passed as parameter knownPlacement = "/bin/sh" testResult = self._env._program_location(knownPlacement) self.assertEqual(testResult, knownPlacement) # searches for link, on unix systems, normally java would be a soft # link at least the first one in the /usr/bin, for example testResult = self._env._program_location("java") self.assertNotEqual(testResult, None) # Valid file, but not executable knownPlacement = "/etc/passwd" testResult = self._env._program_location(knownPlacement) self.assertEqual(testResult, None) # a program that do not exist should return None knownPlacement = "/bin/NotAProgramTestElement" testResult = self._env._program_location(knownPlacement) self.assertEqual(testResult, None) # a program that do not exist, in any directory, should return None knownPlacement = "NotAProgramTestElement" testResult = self._env._program_location(knownPlacement) self.assertEqual(testResult, None) # valid program in a valid directory, but a wrong one knownPlacement = "/tmp/sh" testResult = self._env._program_location(knownPlacement) self.assertEqual(testResult, None) def Dtest___newVariables(self): """Tests setting of variables. """ self._env.start_source("Test", "/tmp/source") self._env.add_libpaths(['v1']) self._env.add_binpaths(['v2']) self._env.add_pkgpaths(['v3']) self._env.add_variables(['v4=test']) string = self._env.create_environement_file("test.txt") self.assertTrue("v1" in string) self.assertTrue("v2" in string) self.assertTrue("v3" in string) self.assertTrue("v4" in string) import commands testStatus = commands.getoutput('rm -rf /tmp/source') self.assertTrue(not testStatus) def Dtest___create_environement_file(self): """Tests the create_environement_file method of Class ModuleEnvironment. """ testResult = self._env.create_environement_file('test.sh') self.assertTrue(os.path.exists('test.sh')) import commands testStatus = commands.getoutput('rm -rf test.sh') # def check_program(self, program, version_arg = None, # version_regexp = None, version_required = None, # match_type=HIGHER): # TODO: Test the version parameters of the executable def Dtest___check_program(self): """Tests the _check_program method of Class ModuleEnvironment. """ # specific existent program programToCheck = "java" testResult = self._env.check_program(programToCheck) self.assertTrue(testResult) # specific inexistent program programToCheck = "/notADirectory/NotAProgramTestElement" testResult = self._env.check_program(programToCheck) self.assertFalse(testResult) # specific existent program version programToCheck = "python" testResult = self._env.check_program(programToCheck, "--version", "(\d+)\.(\d+)\.?(\d+)?", (2, 7, 0)) self.assertTrue(testResult) def Dtest__check_version(self): """Tests the _check_program method of Class ModuleEnvironment. """ import re r = re.compile("(\d+)\.(\d+)\.?(\d+)?") found = r.search("Python 2.7.3").groups() testResult = self._env._check_version(found, (2, 7, 0), 0) self.assertTrue(testResult) testResult = self._env._check_version(found, (2, 7), 0) self.assertTrue(testResult) testResult = self._env._check_version(found, (2, 7), 1) self.assertFalse(testResult) testResult = self._env._check_version(found, (2, 7, 0), 1) self.assertFalse(testResult) testResult = self._env._check_version(found, (2, 7, 0), 2) self.assertFalse(testResult) testResult = self._env._check_version(found, (2, 7), 2) self.assertFalse(testResult) testResult = self._env._check_version(found, (2, 7, 3), 2) self.assertTrue(testResult) testResult = self._env._check_version(found, ([2]), 0) self.assertTrue(testResult) testResult = self._env._check_version(found, ([2]), 1) self.assertFalse(testResult) testResult = self._env._check_version(found, ([2]), 2) self.assertFalse(testResult)
class TestModuleEnvironment(unittest.TestCase): """Tests cases for the Module Environment Class.""" def setUp(self): """Common set Up environment, available for all tests.""" pathname = os.path.dirname(test.TestBake.compensate_third_runner()) if not pathname: pathname="." logger = StdoutModuleLogger() self._env = ModuleEnvironment(logger, pathname, pathname, pathname) def tearDown(self): """Cleans the environment environment for the next tests.""" self._env = None # TODO: see if the tests work in other OS environments, I would guess not # to be honest I am not even sure bake would work on other OS either # TODO:2 Test the search on the current dir/bin def test___program_location(self): """Tests the _program_location method of Class ModuleEnvironment. """ testResult = self._env._program_location("string.h"); self.assertNotEqual(testResult, None) testResult = self._env._program_location("complex.h"); self.assertNotEqual(testResult, None) testResult = self._env._program_location("libc.so"); self.assertNotEqual(testResult, None) testResult = self._env._program_location("NonExistent.so"); self.assertEqual(testResult, None) testResult = self._env._program_location("NonExistent.h"); self.assertEqual(testResult, None) # searches for link, on unix systems, normally java would be a soft link testResult = self._env._program_location("tar"); self.assertNotEqual(testResult, None) # specific program flow, when the directory is passed as parameter knownPlacement = "/bin/sh" testResult = self._env._program_location(knownPlacement); self.assertEqual(testResult, knownPlacement) # searches for link, on unix systems, normally java would be a soft # link at least the first one in the /usr/bin, for example testResult = self._env._program_location("java"); self.assertNotEqual(testResult, None) # Valid file, but not executable knownPlacement = "/etc/passwd" testResult = self._env._program_location(knownPlacement); self.assertEqual(testResult, None) # a program that do not exist should return None knownPlacement = "/bin/NotAProgramTestElement" testResult = self._env._program_location(knownPlacement); self.assertEqual(testResult, None) # a program that do not exist, in any directory, should return None knownPlacement = "NotAProgramTestElement" testResult = self._env._program_location(knownPlacement); self.assertEqual(testResult, None) # valid program in a valid directory, but a wrong one knownPlacement = "/tmp/sh" testResult = self._env._program_location(knownPlacement); self.assertEqual(testResult, None) def Dtest___newVariables(self): """Tests setting of variables. """ self._env.start_source("Test", "/tmp/source") self._env.add_libpaths(['v1']) self._env.add_binpaths(['v2']) self._env.add_pkgpaths(['v3']) self._env.add_variables(['v4=test']) string = self._env.create_environement_file("test.txt") self.assertTrue("v1" in string) self.assertTrue("v2" in string) self.assertTrue("v3" in string) self.assertTrue("v4" in string) import commands testStatus = commands.getoutput('rm -rf /tmp/source') self.assertTrue(not testStatus) def Dtest___create_environement_file(self): """Tests the create_environement_file method of Class ModuleEnvironment. """ testResult = self._env.create_environement_file('test.sh'); self.assertTrue(os.path.exists('test.sh')) import commands testStatus = commands.getoutput('rm -rf test.sh') # def check_program(self, program, version_arg = None, # version_regexp = None, version_required = None, # match_type=HIGHER): # TODO: Test the version parameters of the executable def Dtest___check_program(self): """Tests the _check_program method of Class ModuleEnvironment. """ # specific existent program programToCheck = "java" testResult = self._env.check_program(programToCheck); self.assertTrue(testResult) # specific inexistent program programToCheck = "/notADirectory/NotAProgramTestElement" testResult = self._env.check_program(programToCheck); self.assertFalse(testResult) # specific existent program version programToCheck = "python" testResult = self._env.check_program(programToCheck,"--version", "(\d+)\.(\d+)\.?(\d+)?", (2, 7, 0)); self.assertTrue(testResult) def Dtest__check_version(self): """Tests the _check_program method of Class ModuleEnvironment. """ import re r = re.compile("(\d+)\.(\d+)\.?(\d+)?") found = r.search("Python 2.7.3").groups() testResult = self._env._check_version(found, (2, 7, 0), 0) self.assertTrue(testResult) testResult = self._env._check_version(found, (2, 7), 0) self.assertTrue(testResult) testResult = self._env._check_version(found, (2, 7), 1) self.assertFalse(testResult) testResult = self._env._check_version(found, (2, 7, 0), 1) self.assertFalse(testResult) testResult = self._env._check_version(found, (2, 7, 0), 2) self.assertFalse(testResult) testResult = self._env._check_version(found, (2, 7), 2) self.assertFalse(testResult) testResult = self._env._check_version(found, (2, 7, 3), 2) self.assertTrue(testResult) testResult = self._env._check_version(found, ([2]), 0) self.assertTrue(testResult) testResult = self._env._check_version(found, ([2]), 1) self.assertFalse(testResult) testResult = self._env._check_version(found, ([2]), 2) self.assertFalse(testResult)