コード例 #1
0
    def testInfoDirExists(self):
        """
        test calling _makeInfoFiles() on basedir with fully populated
        'info' directory
        """
        self.patch(os.path, "exists", mock.Mock(return_value=True))

        create_slave._makeInfoFiles("bdir", False)

        # there should be no messages to stdout
        self.assertWasQuiet()
コード例 #2
0
    def testInfoDirExists(self):
        """
        test calling _makeInfoFiles() on basedir with fully populated
        'info' directory
        """
        self.patch(os.path, "exists", mock.Mock(return_value=True))

        create_slave._makeInfoFiles("bdir", False)

        # there should be no messages to stdout
        self.assertWasQuiet()
コード例 #3
0
    def checkCreatedSuccessfully(self, quiet):
        """
        Utility function to test _makeInfoFiles() when called on
        base directory that does not have 'info' sub-directory.

        @param quiet: the value of 'quiet' argument for _makeInfoFiles()
        """
        # patch os.path.exists() to report the no dirs/files exists
        self.patch(os.path, "exists", mock.Mock(return_value=False))
        # patch os.mkdir() to do nothing
        mkdir_mock = mock.Mock()
        self.patch(os, "mkdir", mkdir_mock)
        # capture calls to open() and write()
        self.setUpOpen()

        # call _makeInfoFiles()
        create_slave._makeInfoFiles("bdir", quiet)

        # check calls to os.mkdir()
        info_path = os.path.join("bdir", "info")
        mkdir_mock.assert_called_once_with(info_path)

        # check open() calls
        self.open.assert_has_calls([
            mock.call(os.path.join(info_path, "admin"), "wt"),
            mock.call(os.path.join(info_path, "host"), "wt")
        ])

        # check write() calls
        self.fileobj.write.assert_has_calls([
            mock.call("Your Name Here <*****@*****.**>\n"),
            mock.call("Please put a description of this build host here\n")
        ])

        # check output to the log
        if quiet:
            self.assertWasQuiet()
        else:
            self.assertLogged(
                re.escape("mkdir %s" % info_path),
                re.escape("Creating %s, you need to edit it appropriately." %
                          os.path.join("info", "admin")),
                re.escape("Creating %s, you need to edit it appropriately." %
                          os.path.join("info", "host")),
                re.escape("Not creating %s - add it if you wish" %
                          os.path.join("info", "access_ur")),
                re.escape("Please edit the files in %s appropriately." %
                          info_path))
コード例 #4
0
    def checkCreatedSuccessfully(self, quiet):
        """
        Utility function to test _makeInfoFiles() when called on
        base directory that does not have 'info' sub-directory.

        @param quiet: the value of 'quiet' argument for _makeInfoFiles()
        """
        # patch os.path.exists() to report the no dirs/files exists
        self.patch(os.path, "exists", mock.Mock(return_value=False))
        # patch os.mkdir() to do nothing
        mkdir_mock = mock.Mock()
        self.patch(os, "mkdir", mkdir_mock)
        # capture calls to open() and write()
        self.setUpOpen()

        # call _makeInfoFiles()
        create_slave._makeInfoFiles("bdir", quiet)

        # check calls to os.mkdir()
        info_path = os.path.join("bdir", "info")
        mkdir_mock.assert_called_once_with(info_path)

        # check open() calls
        self.open.assert_has_calls(
            [mock.call(os.path.join(info_path, "admin"), "wt"),
             mock.call(os.path.join(info_path, "host"), "wt")])

        # check write() calls
        self.fileobj.write.assert_has_calls(
            [mock.call("Your Name Here <*****@*****.**>\n"),
             mock.call("Please put a description of this build host here\n")])

        # check output to the log
        if quiet:
            self.assertWasQuiet()
        else:
            self.assertLogged(
                re.escape("mkdir %s" % info_path),
                re.escape("Creating %s, you need to edit it appropriately." %
                          os.path.join("info", "admin")),
                re.escape("Creating %s, you need to edit it appropriately." %
                          os.path.join("info", "host")),
                re.escape("Not creating %s - add it if you wish" %
                          os.path.join("info", "access_ur")),
                re.escape("Please edit the files in %s appropriately." %
                          info_path)
            )