コード例 #1
0
    def test_file(self):
        """Function:  test_file

        Description:  Test file log.

        Arguments:

        """

        self.argv_list.extend(["-f", self.log_file2, "-o", self.test_out])
        cmdline = gen_libs.get_inst(sys)
        cmdline.argv = self.argv_list

        with gen_libs.no_std_out():
            check_log.main()

        if os.path.isfile(self.test_out):
            with open(self.test_out) as f_hdlr:
                out_str = f_hdlr.read()

            self.assertEqual(
                out_str, "This is the sixth line\nThis is the seventh line\n")

        else:
            self.assertTrue(False)
コード例 #2
0
    def test_stdin_marker_empty(self, mock_atty):
        """Function:  test_stdin_marker_empty

        Description:  Test with standard in with an empty marker file.

        Arguments:

        """

        mock_atty.isatty.return_value = False
        self.argv_list.extend([
            "-o", self.test_out, "-n", "-z", "-m",
            os.path.join(self.test_path, self.base_marker3)
        ])
        cmdline = gen_libs.get_inst(sys)
        cmdline.argv = self.argv_list

        check_log.main()

        if os.path.isfile(self.test_out):
            with open(self.test_out) as f_hdlr:
                out_str = f_hdlr.read().rstrip()

            self.assertEqual(out_str, "Line one\nLine two")

        else:
            self.assertTrue(False)
コード例 #3
0
    def test_search_logic_miss(self, mock_arg, mock_help):
        """Function:  test_search_logic_miss

        Description:  Test with missing -k option.

        Arguments:

        """

        mock_arg.return_value = self.args2
        mock_help.return_value = True

        self.assertFalse(check_log.main())
コード例 #4
0
    def test_search_logic_present(self, mock_arg, mock_help):
        """Function:  test_search_logic_present

        Description:  Test with -k option present.

        Arguments:

        """

        mock_arg.return_value = self.args3
        mock_help.return_value = True

        self.assertFalse(check_log.main())
コード例 #5
0
    def test_help_true(self, mock_arg, mock_help):
        """Function:  test_help_true

        Description:  Test with help_func returns True.

        Arguments:

        """

        mock_arg.return_value = self.args
        mock_help.return_value = True

        self.assertFalse(check_log.main())
コード例 #6
0
    def test_clear_marker(self):
        """Function:  test_clear_marker

        Description:  Test clear marker file.

        Arguments:

        """

        self.argv_list.extend(["-c", "-m", self.file_marker])
        cmdline = gen_libs.get_inst(sys)
        cmdline.argv = self.argv_list

        check_log.main()

        if os.stat(self.file_marker).st_size == 0:
            status = True

        else:
            status = False

        self.assertTrue(status)
コード例 #7
0
    def test_help_false(self, mock_arg, mock_help):
        """Function:  test_help_false

        Description:  Test with help_func returns False.

        Arguments:

        """

        mock_arg.arg_parse2.return_value = self.args
        mock_help.return_value = False
        mock_arg.arg_cond_req_or.return_value = False

        self.assertFalse(check_log.main())
コード例 #8
0
    def test_file_chk_true(self, mock_arg, mock_help):
        """Function:  test_file_chk_true

        Description:  Test with arg_file_chk returns True.

        Arguments:

        """

        mock_arg.arg_parse2.return_value = self.args
        mock_help.return_value = False
        mock_arg.arg_cond_req_or.return_value = True
        mock_arg.arg_file_chk.return_value = True

        self.assertFalse(check_log.main())
コード例 #9
0
    def test_help(self):
        """Function:  test_help

        Description:  Test help_func function.

        Arguments:

        """

        self.argv_list.append("-h")
        cmdline = gen_libs.get_inst(sys)
        cmdline.argv = self.argv_list

        with gen_libs.no_std_out():
            self.assertFalse(check_log.main())
コード例 #10
0
    def test_arg_cond_req_or(self):
        """Function:  test_arg_cond_req_or

        Description:  Test arg_cond_req_or function.

        Arguments:

        """

        self.argv_list.append("-c")
        cmdline = gen_libs.get_inst(sys)
        cmdline.argv = self.argv_list

        with gen_libs.no_std_out():
            self.assertFalse(check_log.main())
コード例 #11
0
    def test_stdin(self, mock_atty):
        """Function:  test_stdin

        Description:  Test with standard in.

        Arguments:

        """

        mock_atty.isatty.return_value = False
        self.argv_list.extend(["-o", self.test_out, "-z"])
        cmdline = gen_libs.get_inst(sys)
        cmdline.argv = self.argv_list

        check_log.main()

        if os.path.isfile(self.test_out):
            with open(self.test_out) as f_hdlr:
                out_str = f_hdlr.read()

            self.assertEqual(out_str, "Line one\nLine two\n")

        else:
            self.assertTrue(False)
コード例 #12
0
    def test_arg_file_chk(self):
        """Function:  test_arg_file_chk

        Description:  Test arg_file_chk function.

        Arguments:

        """

        self.argv_list.extend(
            ["-f", os.path.join(self.test_path, "main_dummy.txt")])
        cmdline = gen_libs.get_inst(sys)
        cmdline.argv = self.argv_list

        with gen_libs.no_std_out():
            self.assertFalse(check_log.main())
コード例 #13
0
    def test_programlock_fail(self, mock_arg, mock_help, mock_lock):
        """Function:  test_programlock_fail

        Description:  Test ProgramLock fails to lock.

        Arguments:

        """

        mock_arg.arg_parse2.return_value = self.args
        mock_help.return_value = False
        mock_arg.arg_cond_req_or.return_value = True
        mock_arg.arg_file_chk.return_value = False
        mock_lock.side_effect = check_log.gen_class.SingleInstanceException

        with gen_libs.no_std_out():
            self.assertFalse(check_log.main())
コード例 #14
0
    def test_valid_val_true(self, mock_arg, mock_help, mock_run, mock_lock):
        """Function:  test_valid_val_true

        Description:  Test with arg_valid_val returns True.

        Arguments:

        """

        mock_arg.arg_parse2.return_value = self.args
        mock_help.return_value = False
        mock_arg.arg_cond_req_or.return_value = True
        mock_arg.arg_file_chk.return_value = False
        mock_arg.arg_valid_val.return_value = True
        mock_run.return_value = True
        mock_lock.side_effect = None

        self.assertFalse(check_log.main())