示例#1
0
class TestModuleAppStore(unittest.TestCase):
    """Tests cases for the Module AppStore Class."""
    def setUp(self):
        self._logger = StdoutModuleLogger()
        self._logger.set_verbose(1)

    def test_search_api(self):
        # first setup the baseclient class otherwise will not be
        # able to make requests
        webclient = BaseClient(self._logger,
                               SEARCH_API,
                               baseurl='http://localhost:8000')
        self.assertNotEqual(webclient, None)

        # Test for when substring is not present
        testResult = None
        try:
            testResult = webclient.search_api('random')
            self.fail('There was no problem as the app was not found')
        except:
            self.assertEqual(testResult, None)

        # Test for when substring is present
        testResult = webclient.search_api('wave')
        self.assertEqual(testResult[0]['app']['name'], 'mmwave')

        # Test for when substring is present
        testResult = webclient.search_api('wave')
        self.assertNotEqual(testResult, None)

        # Test for when no substring is passed
        testResult = webclient.search_api()
        self.assertNotEqual(testResult, None)

    def test_install_api(self):

        # first setup the baseclient class otherwise will not be
        # able to make requests
        webclient = BaseClient(self._logger,
                               INSTALL_API,
                               baseurl='http://localhost:8000')
        self.assertNotEqual(webclient, None)

        # Test for when app is not present
        testResult = None
        try:
            testResult = webclient.install_api('random-app')
            self.fail('There was no problem as the app was not found')
        except:
            self.assertEqual(testResult, None)

        # Test for when app is present on the AppStore
        testResult = webclient.install_api('epidemic-routing')
        self.assertEqual(testResult[0]['name'], 'epidemic-routing')
        self.assertEqual(testResult[1].status_code, 200)

        # Test for when app is present on the AppStore with specific version
        testResult = webclient.install_api('ns3-gym', '0.1')
        self.assertEqual(testResult[0]['name'], 'ns3-gym')
        self.assertEqual(testResult[1].status_code, 200)
 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)
示例#3
0
 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")
示例#4
0
 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')
示例#5
0
 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 = commands.getoutput('cp ' + pathname + '/bakefile.xml /tmp/.')
        testStatus = commands.getoutput('chmod 755 /tmp/source')
        testStatus = commands.getoutput('rm -rf /tmp/source')
示例#7
0
class TestBake(unittest.TestCase):
    """Tests cases for the main Bake Class."""
    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')

    def tearDown(self):
        """Cleans the environment environment for the next tests."""
        self._env = None
        pathname = os.path.dirname("/tmp/source")
        #        pathname = os.path.dirname(compensate_third_runner())
        testStatus = subprocess.getoutput('rm -f ' + pathname +
                                          '/bakefile.xml')
        testStatus = subprocess.getoutput('chmod 755 /tmp/source')
        testStatus = subprocess.getoutput('rm -rf /tmp/source')
        testStatus = subprocess.getoutput('mv bc.xml bakeconf.xml ')
        testStatus = subprocess.getoutput('mv bf.xml bakefile.xml ')
        testStatus = subprocess.getoutput('mv ~/.bakerc_saved ~/.bakerc')

    def test_simple_proceedings(self):
        """Tests a simple download and build of Bake. """

        mercurial = ModuleSource.create("mercurial")
        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._env._module_dir = "bake"
        testStatus = subprocess.getoutput('rm -rf /tmp/source')
        self._logger.set_current_module(self._env._module_name)
        testResult = mercurial.download(self._env)
        self.assertFalse(testResult)

        testStatus = subprocess.getoutput(
            'cd /tmp/source/bake;./bake.py configure -p ns3-min')
        self.assertEquals(testStatus, "",
                          "Should have worked the download of the code")
        testStatus = subprocess.getoutput(
            'cd /tmp/source/bake;./bake.py download')
        self.assertFalse("Problem" in testStatus,
                         "Should have worked the download of the code")
        testStatus = subprocess.getoutput(
            'cd /tmp/source/bake;./bake.py build')
        self.assertFalse("Problem" in testStatus,
                         "Should have worked the build of the code")

    def test_read_resource_file(self):
        """Tests the _read_resource_file method of Class Bake."""

        configuration = Configuration("bakefile.xml")
        testStatus, testMessage = subprocess.getstatusoutput(
            'mv ~/.bakerc ~/.bakerc_saved')
        self.assertTrue(testStatus == 0 or testStatus == 256,
                        "Couldn't move the ressource file!")
        bake = Bake()

        testResult = bake._read_resource_file(configuration)
        self.assertFalse(testResult, "Shouldn't find a configuration!")

        testStatus = subprocess.getoutput('touch ~/.bakerc')
        testResult = bake._read_resource_file(configuration)
        self.assertFalse(testResult, "Configuration should be empty!")

        testStatus = subprocess.getoutput('cp ./bakeTest.rc ~/.bakerc')
        testResult = bake._read_resource_file(configuration)
        self.assertTrue(testResult[0].name == "my-ns3",
                        "Shouldn't find a configuration!")

        testStatus, testMessage = subprocess.getstatusoutput(
            'mv ~/.bakerc_saved ~/.bakerc')

    def test_save_resource_configuration(self):
        """Tests the _save_resource_configuration method of Class Bake."""

        pathname = os.path.dirname(compensate_third_runner())
        if not pathname:
            pathname = "."
        testStatus = subprocess.getoutput('python ' + pathname +
                                          '/../bake.py -f ./ttt.xml configure '
                                          '--enable=openflow-ns3 '
                                          '--sourcedir=/tmp/source '
                                          '--installdir=/tmp/source')

        configuration = Configuration("./ttt.xml")
        configuration.read()
        testStatus, testMessage = subprocess.getstatusoutput(
            'mv ~/.bakerc ~/.bakerc_saved')
        self.assertTrue(testStatus == 0 or testStatus == 256,
                        "Couldn't move the resource file!")
        fileName = os.path.join(os.path.expanduser("~"), ".bakerc")
        testStatus, testMessage = subprocess.getstatusoutput(
            'rm -rf ./ttt.xml')
        bake = Bake()

        testResult = bake._save_resource_configuration(configuration)
        self.assertFalse(testResult, "Should have write configuration!")
        self.assertTrue(os.path.isfile(fileName),
                        "Didn't create the .bakerc file")
        fin = open(fileName, "r")
        string = fin.read()
        fin.close()
        self.assertTrue("last" in string, "Didn't save the last configuration")
        self.assertTrue("openflow-ns3" in string,
                        "Didn't save the last configuration")

        testStatus = subprocess.getoutput('cp ./bakeTest.rc ~/.bakerc')
        fin = open(fileName, "r")
        string = fin.read()
        fin.close()
        self.assertFalse("last" in string,
                         "Did find last in the configuration")

        testResult = bake._save_resource_configuration(configuration)
        self.assertFalse(testResult, "Should have write configuration!")
        self.assertTrue(os.path.isfile(fileName),
                        "Didn't create the .bakerc file")
        fin = open(fileName, "r")
        string = fin.read()
        fin.close()
        self.assertTrue("<predefined name=\"last\">" in string,
                        "Didn't save the last configuration")
        self.assertTrue("<enable name=\"openflow-ns3\"/>" in string,
                        "Didn't save the last configuration")

        testStatus, testMessage = subprocess.getstatusoutput(
            'mv ~/.bakerc_saved ~/.bakerc')

    def test_check_source_code(self):
        """Tests the _check_source_code method of Class Bake. """

        # Environment settings
        mercurial = ModuleSource.create("mercurial")
        testResult = mercurial.check_version(self._env)
        self.assertTrue(testResult)

        pathname = os.path.dirname(compensate_third_runner())
        if not pathname:
            pathname = "."
        testStatus = subprocess.getoutput('python ' + pathname +
                                          '/../bake.py configure '
                                          '--enable=openflow-ns3 '
                                          '--sourcedir=/tmp/source '
                                          '--installdir=/tmp/source')

        mercurial.attribute(
            "url").value = "http://code.nsnam.org/bhurd/openflow"
        self._env._module_name = "openflow-ns3"
        self._env._module_dir = "openflow-ns3"
        testStatus = subprocess.getoutput('rm -rf /tmp/source')
        self._logger.set_current_module(self._env._module_name)
        testResult = mercurial.download(self._env)

        bake = Bake()
        config = "bakefile.xml"  #bakefile.xml"
        args = []
        parser = bake._option_parser('build')
        parser.add_option('-j',
                          '--jobs',
                          help='Allow N jobs at once. Default is 1.',
                          type='int',
                          action='store',
                          dest='jobs',
                          default=1)
        parser.add_option(
            "--debug",
            action="store_true",
            dest="debug",
            default=True,
            help="Should we enable extra Bake debugging output ?")
        (options, args_left) = parser.parse_args(args)
        #        bake.setMainOptions(options)
        Bake.main_options = options

        # Tests typical case, the module is there
        testResult = bake._check_source_code(config, options)
        self.assertEqual(testResult, None)

        # if the user has no permission to see the file
        testStatus = subprocess.getoutput('chmod 000 /tmp/source')
        testResult = None
        try:
            testResult = bake._check_source_code(config, options)
        except SystemExit as e:
            self.assertTrue(e.code == 1, "Wrong error code received")

        self.assertFalse(testResult, None)

        testStatus = subprocess.getoutput('chmod 755 /tmp/source')

        # if the folder is not where it should be
        testStatus = subprocess.getoutput('rm -rf /tmp/source')
        testResult = None
        try:
            testResult = bake._check_source_code(config, options)
        except SystemExit as e:
            self.assertTrue(e.code == 1, "Wrong error code received")

        self.assertFalse(testResult, None)

    def test_check_build_version(self):
        """Tests the _check_source_code method of Class Bake. """

        # Environment settings
        # Environment settings
        mercurial = ModuleSource.create("mercurial")
        testResult = mercurial.check_version(self._env)
        self.assertTrue(testResult)

        self._env._debug = True
        pathname = os.path.dirname(compensate_third_runner())
        if not pathname:
            pathname = "."

        testStatus = subprocess.getoutput('python ' + pathname +
                                          '/../bake.py configure'
                                          ' --enable=openflow-ns3'
                                          ' --sourcedir=/tmp/source'
                                          ' --installdir=/tmp/source')

        mercurial.attribute(
            "url").value = "http://code.nsnam.org/bhurd/openflow"
        self._env._module_name = "openflow-ns3"
        self._env._module_dir = "openflow-ns3"
        testStatus = subprocess.getoutput('rm -rf /tmp/source')
        self._logger.set_current_module(self._env._module_name)
        testResult = mercurial.download(self._env)
        #        try:
        #            testResult = mercurial.download(self._env)
        #            self.fail("The directory does not exist, this shouldn't work")
        #        except TaskError as e:
        #            self.assertNotEqual(e._reason, None)
        #            self.assertEqual(testResult, None)

        bake = Bake()
        config = "bakefile.xml"  #bakefile.xml"
        args = []
        parser = bake._option_parser('build')
        parser.add_option('-j',
                          '--jobs',
                          help='Allow N jobs at once. Default is 1.',
                          type='int',
                          action='store',
                          dest='jobs',
                          default=1)
        parser.add_option(
            "--debug",
            action="store_true",
            dest="debug",
            default=False,
            help="Should we enable extra Bake debugging output ?")
        (options, args_left) = parser.parse_args(args)
        #        bake.setMainOptions(options)
        Bake.main_options = options

        # Tests typical case, the module is there and the object directory is not
        self._env._installdir = self._env.srcdir + "/install_bake"
        testResult = bake._check_build_version(config, options)
        self.assertEqual(testResult, None)

        # if the user has no permission to see the file
        testStatus = subprocess.getoutput('chmod 000 /tmp/source')

        testResult = None
        try:
            testResult = bake._check_source_code(config, options)
        except SystemExit as e:
            self.assertTrue(e.code == 1, "Wrong error code received")

        self.assertFalse(testResult, None)

        testStatus = subprocess.getoutput('chmod 755 /tmp/source')

        # if the folder is not where it should be
        testStatus = subprocess.getoutput('rm -rf /tmp/source')
        testResult = None
        testResult = None
        try:
            testResult = bake._check_source_code(config, options)
        except SystemExit as e:
            self.assertTrue(e.code == 1, "Wrong error code received")

        self.assertFalse(testResult, None)

    def test_check_configuration_file(self):
        """Tests the check_configuration_file method of Class Bake. """

        bakeInstance = Bake()

        testResult = bakeInstance.check_configuration_file("strangeName")
        self.assertEqual(testResult, "strangeName",
                         "New name is not respected")

        testResult = bakeInstance.check_configuration_file("bakeconf.xml")
        self.assertEqual(
            testResult, "bakeconf.xml", "Default file should"
            " exist but it changed the name.")

        testStatus = subprocess.getoutput('mv bakeconf.xml bc.xml')
        testResult = bakeInstance.check_configuration_file("bakeconf.xml")
        self.assertTrue(
            testResult.endswith("bakeconf.xml"), "Should have"
            " returned the bakeconf.xml but returned " + testResult)

        #        testStatus = subprocess.getoutput('mv bakefile.xml bf.xml')
        #        testStatus = subprocess.getoutput('mv bc.xml bakeconf.xml ')
        #        testResult = bakeInstance.check_configuration_file("bakefile.xml", True)
        #        self.assertTrue(testResult.endswith("bakeconf.xml"), "Should have"
        #                        " returned the bakeconf but returned " + testResult)

        testStatus = subprocess.getoutput('mv bakeconf.xml bc.xml')
        testResult = bakeInstance.check_configuration_file("bakefile.xml")
        self.assertEqual(
            testResult, "bakefile.xml", "Default file should"
            " be returned in the last case.")

        testStatus = subprocess.getoutput('mv bc.xml bakeconf.xml ')
        testStatus = subprocess.getoutput('mv bf.xml bakefile.xml ')

#     xmlVar = '<configuration> <modules> <module name="test1">
#
#      <source type="mercurial">
#    <attribute name="url" value="http://code.nsnam.org/bake"/>
#      </source>
#      <build type="waf" objdir="yes">
#    <attribute name="configure_arguments" value="configure --prefix=$INSTALLDIR --enable-examples --enable-tests"/>
#      </build>
#  </module>
#
#    <module name="test2">
#      <source type="bazaar">
#    <attribute name="url" value="https://launchpad.net/pybindgen"/>
#    <attribute name="revision" value="revno:809"/>
#      </source>
#      <build type="waf" objdir="yes">
#    <attribute name="configure_arguments" value="configure --prefix=$INSTALLDIR"/>
#    <attribute name="build_arguments" value="--generate-version"/>
#      </build>
#      <depends_on name="test1" optional="False"/>
#    </module>
#
#    <module name="test3">
#      <source type="bazaar">
#    <attribute name="url" value="https://launchpad.net/pybindgen"/>
#    <attribute name="revision" value="revno:809"/>
#      </source>
#      <build type="waf" objdir="yes">
#    <attribute name="configure_arguments" value="configure --prefix=$INSTALLDIR"/>
#    <attribute name="build_arguments" value="--generate-version"/>
#      </build>
#      <depends_on name="test2" optional="True"/>
#      <depends_on name="pygccxml" optional="True"/>
#    </module>
#
#  </modules>
#
#</configuration>'

#    def test_dependencies(self):
#        """Tests the Dependencies mechanism of Bake. """
#
#        configuration = Configuration("bakefile")
##        et = ET.parse(filename)
##        self._read_metadata(et)
#
#
#        testStatus = subprocess.getoutput('cp bakeconf.xml bc.xml ')
#        testStatus = subprocess.getoutput('cp bakefile.xml bf.xml ')
#
#        bake = Bake()
#        config = "bakefile.xml" #bakefile.xml"
#        args = []
#        parser = bake._option_parser('install')
#        parser.add_option('-j', '--jobs', help='Allow N jobs at once. Default is 1.',
#                          type='int', action='store', dest='jobs', default=1)
#        parser.add_option("--debug", action="store_true",
#                          dest="debug", default=False,
#                          help="Should we enable extra Bake debugging output ?")
#        (options, args_left) = parser.parse_args(args)
#        Bake.main_options = options
#
#        # Tests typical case, the module is there and the object directory is not
#        self._env._installdir = self._env.srcdir+"/install_bake"
#        testResult = bake._check_build_version(config, options);
#        self.assertEqual(testResult, None)
#
#
#
#        testStatus = subprocess.getoutput('mv bc.xml bakeconf.xml ')
#        testStatus = subprocess.getoutput('mv bf.xml bakefile.xml ')
#

    def test_systemReturnValues(self):
        """Tests the values get from the system point of view. """

        self._env._debug = True
        pathname = os.path.dirname(compensate_third_runner())
        if not pathname:
            pathname = "."

        commandTmp = (
            '%s/../bake.py -f /tmp/myconf.xml configure -c %s/../bakeconf.xml --enable=openflow-ns3'
            ' --sourcedir=/tmp/source'
            ' --installdir=/tmp/source' % (pathname, pathname))
        (status, output) = subprocess.getstatusoutput(commandTmp)

        (status, output
         ) = subprocess.getstatusoutput('python ' + pathname +
                                        '/../bake.py --debug download -vvv')
        self.assertFalse(status == 0, 'Wrong system status return.')

        #        (status, output) = subprocess.getstatusoutput('python ' + pathname +
        #                                        '/../bake.py --debug download -vvv --sudo')
        #        self.assertTrue(status==0, 'Wrong system status return.')

        (status, output) = subprocess.getstatusoutput('python ' + pathname +
                                                      '/../bake.py build')
        self.assertTrue(status != 0, 'Wrong system status return.')

    def test_printTree(self):
        """Tests tree visualization mechanism. """

        first = dict()
        second = dict()
        third = dict()
        bake = Bake()

        mainDep = {'first': first, 'second': second, 'third': third}

        keys = bake.deptree(mainDep, mainDep, 'main', dict(), ' ')
        self.assertTrue(keys != None, 'Error during tree processing')
        self.assertTrue(len(mainDep) > 0, 'Error during tree processing')
        self.assertTrue(keys == 'main/third.second.first.',
                        'Error during tree processing')

        first = {'second': True}
        second = {'third': True}
        mainDep = {'first': first, 'second': second, 'third': third}
        keys = bake.deptree(mainDep, mainDep, 'main', dict(), ' ')
        self.assertTrue(keys != None, 'Error during tree processing')
        self.assertTrue(len(mainDep) > 0, 'Error during tree processing')
        self.assertTrue(keys == 'main/third.first/second/third.second/third.')

        # One more level
        fourth = dict()
        second = {'third': True, 'fourth': True}
        mainDep = {
            'first': first,
            'second': second,
            'third': third,
            'fourth': fourth
        }
        keys = bake.deptree(mainDep, mainDep, 'main', dict(), ' ')
        self.assertTrue(keys != None, 'Error during tree processing')
        self.assertTrue(len(mainDep) > 0, 'Error during tree processing')
        self.assertTrue(
            keys ==
            'main/third.fourth.first/second/third.fourth.second/third.fourth.')

        # the loops
        # simple to self
        first = {'first': True}
        mainDep = {'first': first}
        keys = bake.deptree(mainDep, mainDep, 'main', dict(), ' ')
        self.assertTrue(keys != None, 'Error during tree processing')
        self.assertTrue(len(mainDep) > 0, 'Error during tree processing')
        self.assertTrue(keys == 'main/first/> Cyclic Dependency.')

        # two levels loop
        first = {'second': True}
        second = {'first': True}
        mainDep = {
            'first': first,
            'second': second
        }
        keys = bake.deptree(mainDep, mainDep, 'main', dict(), ' ')
        self.assertTrue(keys != None, 'Error during tree processing')
        self.assertTrue(len(mainDep) > 0, 'Error during tree processing')
        self.assertTrue(keys == 'main/first/second/> Cyclic Dependency.'
                        'second/first/> Cyclic Dependency.')

        # the same as before, but now with loop
        second = {'third': True, 'first': first}
        mainDep = {'first': first, 'second': second, 'third': third}
        keys = bake.deptree(mainDep, mainDep, 'main', dict(), ' ')
        self.assertTrue(keys != None, 'Error during tree processing')
        self.assertTrue(len(mainDep) > 0, 'Error during tree processing')
        self.assertTrue(
            keys == 'main/third.first/second/third.> Cyclic Dependency.'
            'second/third.first/> Cyclic Dependency.')

        # multyLayer loop
        fourth = {'first': True}
        third = {'second': True}
        second = {'third': True, 'fourth': True}
        mainDep = {
            'first': first,
            'second': second,
            'third': third,
            'fourth': fourth
        }
        keys = bake.deptree(mainDep, mainDep, 'main', dict(), ' ')
        self.assertTrue(keys != None, 'Error during tree processing')
        self.assertTrue(len(mainDep) > 0, 'Error during tree processing')
        self.assertTrue(
            keys == 'main/first/second/fourth/> Cyclic'
            ' Dependency.third/> Cyclic Dependency.fourth/first/second/>'
            ' Cyclic Dependency.third/> Cyclic '
            'Dependency.second/fourth/first/> Cyclic '
            'Dependency.third/> Cyclic Dependency.third/second/fourth/first/>'
            ' Cyclic Dependency.> Cyclic Dependency.')

    def test_printDependencies(self):
        """Tests the print of dependencies mechanism. """

        bake = Bake()
        first = SystemDependency()
        first.attribute('dependency_test').value = 'passwd'
        first.attribute(
            'more_information').value = 'Missing the required dependency'
        first.attribute('name_apt-get').value = 'libpcap-dev'
        first.attribute('name_yum').value = 'libpcap-devel'

        mainDep = {
            'passwd': first
        }
        returnValue = bake.showSystemDependencies(mainDep, 'bakeconf.xml')
        self.assertTrue(returnValue != None,
                        'Error during dependencies processing')
        self.assertTrue(returnValue == 'passwd')

        first.attribute('dependency_test').value = 'nononononononononon'

        mainDep = {'nononononononononon': first}
        returnValue = None
        try:
            returnValue = bake.showSystemDependencies(mainDep, 'bakeconf.xml')
            self.fail("Should have stoped")
        except SystemExit as e:
            self.assertTrue(returnValue == None,
                            'Error during dependencies processing')

        second = SystemDependency()
        second.attribute('dependency_test').value = 'passwd'
        second.attribute(
            'more_information').value = 'Has not the required dependency'
        mainDep = {'nononononononononon': first, 'passwd': second}
        returnValue = None
        try:
            returnValue = bake.showSystemDependencies(mainDep, 'bakeconf.xml')
            self.fail("Should have stoped")
        except SystemExit as e:
            self.assertTrue(returnValue == None,
                            'Error during dependencies processing')
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)
示例#9
0
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 TestBake(unittest.TestCase):
    """Tests cases for the main Bake Class."""

           
    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 = commands.getoutput('cp ' + pathname + '/bakefile.xml /tmp/.')
        testStatus = commands.getoutput('chmod 755 /tmp/source')
        testStatus = commands.getoutput('rm -rf /tmp/source')

        
    def tearDown(self):
        """Cleans the environment environment for the next tests."""
        self._env = None
        pathname = os.path.dirname("/tmp/source")  
#        pathname = os.path.dirname(compensate_third_runner())  
        testStatus = commands.getoutput('rm -f ' + pathname +'/bakefile.xml')
        testStatus = commands.getoutput('chmod 755 /tmp/source')
        testStatus = commands.getoutput('rm -rf /tmp/source')
        testStatus = commands.getoutput('mv bc.xml bakeconf.xml ')
        testStatus = commands.getoutput('mv bf.xml bakefile.xml ')
        testStatus = commands.getoutput('mv ~/.bakerc_saved ~/.bakerc')

    def test_simple_proceedings(self):
        """Tests a simple download and build of Bake. """

        mercurial = ModuleSource.create("mercurial")
        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._env._module_dir="bake"
        testStatus = commands.getoutput('rm -rf /tmp/source')
        self._logger.set_current_module(self._env._module_name)
        testResult = mercurial.download(self._env)
        self.assertFalse(testResult)

        testStatus = commands.getoutput('cd /tmp/source/bake;./bake.py configure -p ns3-min')
        self.assertEquals(testStatus, "", "Should have worked the download of the code")
        testStatus = commands.getoutput('cd /tmp/source/bake;./bake.py download')
        self.assertFalse("Problem" in testStatus, 
                        "Should have worked the download of the code")
        testStatus = commands.getoutput('cd /tmp/source/bake;./bake.py build')
        self.assertFalse("Problem" in testStatus, 
                        "Should have worked the build of the code")
  
 
    def test_read_resource_file(self):
        """Tests the _read_resource_file method of Class Bake."""
        
        configuration = Configuration("bakefile.xml")
        testStatus,testMessage = commands.getstatusoutput('mv ~/.bakerc ~/.bakerc_saved')
        self.assertTrue(testStatus==0 or testStatus==256,"Couldn't move the ressource file!")
        bake = Bake()
        
        testResult = bake._read_resource_file(configuration)
        self.assertFalse(testResult,"Shouldn't find a configuration!")
        
        testStatus = commands.getoutput('touch ~/.bakerc')
        testResult = bake._read_resource_file(configuration)
        self.assertFalse(testResult,"Configuration should be empty!")

        testStatus = commands.getoutput('cp ./bakeTest.rc ~/.bakerc')
        testResult = bake._read_resource_file(configuration)
        self.assertTrue(testResult[0].name=="my-ns3","Shouldn't find a configuration!")
        
        testStatus,testMessage = commands.getstatusoutput('mv ~/.bakerc_saved ~/.bakerc')
      
    def test_save_resource_configuration(self):
        """Tests the _save_resource_configuration method of Class Bake."""
        
        pathname = os.path.dirname(compensate_third_runner())  
        if not pathname:
            pathname="."
        testStatus = commands.getoutput('python ' + pathname + 
                                        '/../bake.py -f ./ttt.xml configure ' 
                                        '--enable=openflow-ns3 ' 
                                        '--sourcedir=/tmp/source ' 
                                        '--installdir=/tmp/source')

        configuration = Configuration("./ttt.xml")
        configuration.read()
        testStatus,testMessage = commands.getstatusoutput('mv ~/.bakerc ~/.bakerc_saved')
        self.assertTrue(testStatus==0 or testStatus==256,
                        "Couldn't move the resource file!")
        fileName = os.path.join(os.path.expanduser("~"), ".bakerc")
        testStatus,testMessage = commands.getstatusoutput('rm -rf ./ttt.xml')
        bake = Bake()
        
        testResult = bake._save_resource_configuration(configuration)
        self.assertFalse(testResult,"Should have write configuration!")
        self.assertTrue(os.path.isfile(fileName), "Didn't create the .bakerc file")
        fin = open(fileName, "r")
        string = fin.read()
        fin.close()
        self.assertTrue("last" in string, "Didn't save the last configuration")
        self.assertTrue("openflow-ns3" in string, 
                        "Didn't save the last configuration")
        
        testStatus = commands.getoutput('cp ./bakeTest.rc ~/.bakerc')
        fin = open(fileName, "r")
        string = fin.read()
        fin.close()
        self.assertFalse("last" in string, "Did find last in the configuration")
        
        testResult = bake._save_resource_configuration(configuration)
        self.assertFalse(testResult,"Should have write configuration!")
        self.assertTrue(os.path.isfile(fileName), "Didn't create the .bakerc file")
        fin = open(fileName, "r")
        string = fin.read()
        fin.close()
        self.assertTrue("<predefined name=\"last\">" in string, "Didn't save the last configuration")
        self.assertTrue("<enable name=\"openflow-ns3\"/>" in string, 
                        "Didn't save the last configuration")


        testStatus,testMessage = commands.getstatusoutput('mv ~/.bakerc_saved ~/.bakerc')
  
   
    def test_check_source_code(self):
        """Tests the _check_source_code method of Class Bake. """

        # Environment settings        
        mercurial = ModuleSource.create("mercurial")
        testResult = mercurial.check_version(self._env)
        self.assertTrue(testResult)
        
        pathname = os.path.dirname(compensate_third_runner())  
        if not pathname:
            pathname="."
        testStatus = commands.getoutput('python ' + pathname + 
                                        '/../bake.py configure ' 
                                        '--enable=openflow-ns3 ' 
                                        '--sourcedir=/tmp/source ' 
                                        '--installdir=/tmp/source')

        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)

        bake = Bake()
        config = "bakefile.xml" #bakefile.xml"
        args = []
        parser = bake._option_parser('build')
        parser.add_option('-j', '--jobs', 
                          help='Allow N jobs at once. Default is 1.',
                          type='int', action='store', dest='jobs', default=1)
        parser.add_option("--debug", action="store_true", 
                          dest="debug", default=True, 
                          help="Should we enable extra Bake debugging output ?")
        (options, args_left) = parser.parse_args(args)
#        bake.setMainOptions(options)
        Bake.main_options = options
        
        # Tests typical case, the module is there
        testResult = bake._check_source_code(config, options);
        self.assertEqual(testResult, None)
 
        # if the user has no permission to see the file
        testStatus = commands.getoutput('chmod 000 /tmp/source')
        testResult=None
        try:
            testResult = bake._check_source_code(config, options);
        except SystemExit as e:
            self.assertTrue(e.code==1,"Wrong error code received")
            
        self.assertFalse(testResult, None)    
        
        testStatus = commands.getoutput('chmod 755 /tmp/source')
           
        # if the folder is not where it should be
        testStatus = commands.getoutput('rm -rf /tmp/source')
        testResult=None
        try:
            testResult = bake._check_source_code(config, options);
        except SystemExit as e:
            self.assertTrue(e.code==1,"Wrong error code received")
            
        self.assertFalse(testResult, None)    
             

    def test_check_build_version(self):
        """Tests the _check_source_code method of Class Bake. """

        # Environment settings        
        # Environment settings        
        mercurial = ModuleSource.create("mercurial")
        testResult = mercurial.check_version(self._env)
        self.assertTrue(testResult)
        
        self._env._debug = True
        pathname = os.path.dirname(compensate_third_runner()) 
        if not pathname:
            pathname="."
 
        testStatus = commands.getoutput('python ' + pathname + 
                                        '/../bake.py configure' 
                                        ' --enable=openflow-ns3' 
                                        ' --sourcedir=/tmp/source' 
                                        ' --installdir=/tmp/source')

        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)
#        try:
#            testResult = mercurial.download(self._env)
#            self.fail("The directory does not exist, this shouldn't work")
#        except TaskError as e:
#            self.assertNotEqual(e._reason, None)    
#            self.assertEqual(testResult, None)
        

        bake = Bake()
        config = "bakefile.xml" #bakefile.xml"
        args = []
        parser = bake._option_parser('build')
        parser.add_option('-j', '--jobs', help='Allow N jobs at once. Default is 1.',
                          type='int', action='store', dest='jobs', default=1)
        parser.add_option("--debug", action="store_true", 
                          dest="debug", default=False, 
                          help="Should we enable extra Bake debugging output ?")
        (options, args_left) = parser.parse_args(args)
#        bake.setMainOptions(options)
        Bake.main_options = options
        
        # Tests typical case, the module is there and the object directory is not
        self._env._installdir = self._env.srcdir+"/install_bake"
        testResult = bake._check_build_version(config, options);
        self.assertEqual(testResult, None)
 
        # if the user has no permission to see the file
        testStatus = commands.getoutput('chmod 000 /tmp/source')

        testResult=None
        try:
            testResult = bake._check_source_code(config, options);
        except SystemExit as e:
            self.assertTrue(e.code==1,"Wrong error code received")
            
        self.assertFalse(testResult, None)    
        
        testStatus = commands.getoutput('chmod 755 /tmp/source')
           
        # if the folder is not where it should be
        testStatus = commands.getoutput('rm -rf /tmp/source')
        testResult=None
        testResult=None
        try:
            testResult = bake._check_source_code(config, options);
        except SystemExit as e:
            self.assertTrue(e.code==1,"Wrong error code received")
            
        self.assertFalse(testResult, None)    

    def test_check_configuration_file(self):
        """Tests the check_configuration_file method of Class Bake. """

        bakeInstance = Bake() 

        testResult = bakeInstance.check_configuration_file("strangeName")
        self.assertEqual(testResult, "strangeName", "New name is not respected")

        testResult = bakeInstance.check_configuration_file("bakeconf.xml")
        self.assertEqual(testResult, "bakeconf.xml", "Default file should"
                         " exist but it changed the name.")
        
        testStatus = commands.getoutput('mv bakeconf.xml bc.xml')
        testResult = bakeInstance.check_configuration_file("bakeconf.xml")
        self.assertTrue(testResult.endswith("bakeconf.xml"), "Should have"
                        " returned the bakeconf.xml but returned " + testResult)

#        testStatus = commands.getoutput('mv bakefile.xml bf.xml')
#        testStatus = commands.getoutput('mv bc.xml bakeconf.xml ')
#        testResult = bakeInstance.check_configuration_file("bakefile.xml", True)
#        self.assertTrue(testResult.endswith("bakeconf.xml"), "Should have"
#                        " returned the bakeconf but returned " + testResult)

        testStatus = commands.getoutput('mv bakeconf.xml bc.xml')
        testResult = bakeInstance.check_configuration_file("bakefile.xml")
        self.assertEqual(testResult, "bakefile.xml", "Default file should"
                         " be returned in the last case.")
        
        testStatus = commands.getoutput('mv bc.xml bakeconf.xml ')
        testStatus = commands.getoutput('mv bf.xml bakefile.xml ')

#     xmlVar = '<configuration> <modules> <module name="test1"> 
#    
#      <source type="mercurial">
#    <attribute name="url" value="http://code.nsnam.org/bake"/>
#      </source>
#      <build type="waf" objdir="yes">
#    <attribute name="configure_arguments" value="configure --prefix=$INSTALLDIR --enable-examples --enable-tests"/>
#      </build>
#  </module>
#
#    <module name="test2">
#      <source type="bazaar">
#    <attribute name="url" value="https://launchpad.net/pybindgen"/>
#    <attribute name="revision" value="revno:809"/>
#      </source>
#      <build type="waf" objdir="yes">
#    <attribute name="configure_arguments" value="configure --prefix=$INSTALLDIR"/>
#    <attribute name="build_arguments" value="--generate-version"/>
#      </build>
#      <depends_on name="test1" optional="False"/>
#    </module>
#
#    <module name="test3">
#      <source type="bazaar">
#    <attribute name="url" value="https://launchpad.net/pybindgen"/>
#    <attribute name="revision" value="revno:809"/>
#      </source>
#      <build type="waf" objdir="yes">
#    <attribute name="configure_arguments" value="configure --prefix=$INSTALLDIR"/>
#    <attribute name="build_arguments" value="--generate-version"/>
#      </build>
#      <depends_on name="test2" optional="True"/>
#      <depends_on name="pygccxml" optional="True"/>
#    </module>
#
#  </modules>
#
#</configuration>'

       
#    def test_dependencies(self):
#        """Tests the Dependencies mechanism of Bake. """
#        
#        configuration = Configuration("bakefile")
##        et = ET.parse(filename)
##        self._read_metadata(et)
#
#
#        testStatus = commands.getoutput('cp bakeconf.xml bc.xml ')
#        testStatus = commands.getoutput('cp bakefile.xml bf.xml ')
#
#        bake = Bake() 
#        config = "bakefile.xml" #bakefile.xml"
#        args = []
#        parser = bake._option_parser('install')
#        parser.add_option('-j', '--jobs', help='Allow N jobs at once. Default is 1.',
#                          type='int', action='store', dest='jobs', default=1)
#        parser.add_option("--debug", action="store_true", 
#                          dest="debug", default=False, 
#                          help="Should we enable extra Bake debugging output ?")
#        (options, args_left) = parser.parse_args(args)
#        Bake.main_options = options
#        
#        # Tests typical case, the module is there and the object directory is not
#        self._env._installdir = self._env.srcdir+"/install_bake"
#        testResult = bake._check_build_version(config, options);
#        self.assertEqual(testResult, None)
#
#
#        
#        testStatus = commands.getoutput('mv bc.xml bakeconf.xml ')
#        testStatus = commands.getoutput('mv bf.xml bakefile.xml ')
#       

    def test_systemReturnValues(self):
        """Tests the values get from the system point of view. """

        self._env._debug = True
        pathname = os.path.dirname(compensate_third_runner()) 
        if not pathname:
            pathname="."
 
        commandTmp = ('%s/../bake.py -f /tmp/myconf.xml configure -c %s/../bakeconf.xml --enable=openflow-ns3' 
        ' --sourcedir=/tmp/source' 
        ' --installdir=/tmp/source' %(pathname, pathname))
        (status, output) = commands.getstatusoutput(commandTmp)    

        (status, output) = commands.getstatusoutput('python ' + pathname + 
                                        '/../bake.py --debug download -vvv')
        self.assertFalse(status==0, 'Wrong system status return.')
        
#        (status, output) = commands.getstatusoutput('python ' + pathname + 
#                                        '/../bake.py --debug download -vvv --sudo')
#        self.assertTrue(status==0, 'Wrong system status return.')
    

        (status, output) = commands.getstatusoutput('python ' + pathname + 
                                        '/../bake.py build')
        self.assertTrue(status!=0, 'Wrong system status return.')    
        

    def test_printTree(self):
        """Tests tree visualization mechanism. """
        
        first = dict()
        second = dict()
        third = dict()
        bake = Bake()
        
        mainDep = {'first': first, 'second':second, 'third': third}
        
        keys = bake.deptree(mainDep, mainDep, 'main', dict(), ' ')
        self.assertTrue(keys!=None, 'Error during tree processing')    
        self.assertTrue(len(mainDep)>0, 'Error during tree processing')
        self.assertTrue(keys=='main/third.second.first.', 'Error during tree processing')

        first={'second':True}
        second={'third':True}
        mainDep = {'first': first, 'second':second, 'third': third}
        keys = bake.deptree(mainDep, mainDep, 'main', dict(), ' ')
        self.assertTrue(keys!=None, 'Error during tree processing')    
        self.assertTrue(len(mainDep)>0, 'Error during tree processing')
        self.assertTrue(keys=='main/third.first/second/third.second/third.')

        # One more level
        fourth = dict()
        second={'third':True, 'fourth':True}
        mainDep = {'first': first, 'second':second, 'third': third,'fourth':fourth};
        keys = bake.deptree(mainDep, mainDep, 'main', dict(), ' ')
        self.assertTrue(keys!=None, 'Error during tree processing')    
        self.assertTrue(len(mainDep)>0, 'Error during tree processing')
        self.assertTrue(keys=='main/third.fourth.first/second/third.fourth.second/third.fourth.')

        # the loops
        # simple to self
        first={'first':True}
        mainDep = {'first': first}
        keys = bake.deptree(mainDep, mainDep, 'main', dict(), ' ')
        self.assertTrue(keys!=None, 'Error during tree processing')    
        self.assertTrue(len(mainDep)>0, 'Error during tree processing')
        self.assertTrue(keys== 'main/first/> Cyclic Dependency.')


        # two levels loop
        first={'second':True}
        second={'first':True}
        mainDep = {'first': first, 'second':second};
        keys = bake.deptree(mainDep, mainDep, 'main', dict(), ' ')
        self.assertTrue(keys!=None, 'Error during tree processing')    
        self.assertTrue(len(mainDep)>0, 'Error during tree processing')
        self.assertTrue(keys== 'main/first/second/> Cyclic Dependency.'
                        'second/first/> Cyclic Dependency.')

        # the same as before, but now with loop
        second={'third':True, 'first':first}
        mainDep = {'first': first, 'second':second, 'third': third}
        keys = bake.deptree(mainDep, mainDep, 'main', dict(), ' ')
        self.assertTrue(keys!=None, 'Error during tree processing')    
        self.assertTrue(len(mainDep)>0, 'Error during tree processing')
        self.assertTrue(keys==
                        'main/third.first/second/third.> Cyclic Dependency.'
                        'second/third.first/> Cyclic Dependency.')

        # multyLayer loop
        fourth = {'first':True}
        third = {'second':True}
        second={'third':True, 'fourth':True}
        mainDep = {'first': first, 'second':second, 'third': third,'fourth':fourth}
        keys = bake.deptree(mainDep, mainDep, 'main', dict(), ' ')
        self.assertTrue(keys!=None, 'Error during tree processing')    
        self.assertTrue(len(mainDep)>0, 'Error during tree processing')
        self.assertTrue(keys=='main/first/second/fourth/> Cyclic'
                        ' Dependency.third/> Cyclic Dependency.fourth/first/second/>'
                        ' Cyclic Dependency.third/> Cyclic '
                        'Dependency.second/fourth/first/> Cyclic '
                        'Dependency.third/> Cyclic Dependency.third/second/fourth/first/>'
                        ' Cyclic Dependency.> Cyclic Dependency.')
        
    def test_printDependencies(self):
        """Tests the print of dependencies mechanism. """
        
        bake = Bake()
        first = SystemDependency()
        first.attribute('dependency_test').value ='passwd'
        first.attribute('more_information').value ='Missing the required dependency'
        first.attribute('name_apt-get').value = 'libpcap-dev'
        first.attribute('name_yum').value = 'libpcap-devel'
       
        mainDep = {'passwd': first};
        returnValue = bake.showSystemDependencies(mainDep, 'bakeconf.xml')
        self.assertTrue(returnValue!=None, 'Error during dependencies processing')    
        self.assertTrue(returnValue=='passwd')
        
        first.attribute('dependency_test').value ='nononononononononon'
        
        mainDep = {'nononononononononon': first}
        returnValue=None
        try:
            returnValue = bake.showSystemDependencies(mainDep, 'bakeconf.xml')
            self.fail("Should have stoped")
        except SystemExit as e: 
            self.assertTrue(returnValue==None, 'Error during dependencies processing')    
         
        second = SystemDependency()
        second.attribute('dependency_test').value ='passwd'
        second.attribute('more_information').value ='Has not the required dependency'
        mainDep = {'nononononononononon': first, 'passwd':second}
        returnValue=None
        try:
            returnValue = bake.showSystemDependencies(mainDep, 'bakeconf.xml')
            self.fail("Should have stoped")
        except SystemExit as e: 
            self.assertTrue(returnValue==None, 'Error during dependencies processing')    
示例#13
0
 def setUp(self):
     self._logger = StdoutModuleLogger()
     self._logger.set_verbose(1)