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 args_array = {"-o": self.test_out, "-n": True, "-z": True, "-m": os.path.join(self.test_path, self.base_marker3), "-g": "w"} check_log.run_program(args_array) 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)
def test_file_g_option_append(self): """Function: test_file_g_option_append Description: Test file logs with -w option with append value. Arguments: """ self.args_array.update({"-f": [self.log_file4], "-o": self.test_out, "-z": True, "-g": "a"}) check_log.run_program(self.args_array) self.args_array["-f"] = [self.log_file5] check_log.run_program(self.args_array) 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 1\nLine 2\n") else: self.assertTrue(False)
def test_clear_marker(self): """Function: test_clear_marker Description: Test clearing the marker file. Arguments: """ args_array = {"-c": True, "-m": self.file_marker} check_log.run_program(args_array) self.assertTrue(os.stat(self.file_marker).st_size == 0)
def test_file_w_option_empty(self): """Function: test_file_w_option_empty Description: Test file logs with -w option and no data. Arguments: """ self.args_array.update({"-f": [self.log_file3], "-o": self.test_out, "-z": True, "-w": True}) check_log.run_program(self.args_array) self.assertFalse(os.path.isfile(self.test_out))
def test_marker(self): """Function: test_marker Description: Test file log marker. Arguments: """ self.args_array.update({"-z": True, "-m": self.file_marker}) check_log.run_program(self.args_array) with open(self.file_marker) as f_hdlr: out_str = f_hdlr.readline().rstrip() self.assertEqual(out_str, "This is the seventh line")
def test_file_suppress(self): """Function: test_file_suppress Description: Test file logs with standard out suppression. Arguments: """ with gen_libs.no_std_out(): self.assertFalse(check_log.run_program(self.args_array))
def test_stdin(self, mock_sys): """Function: test_stdin Description: Test with standard in option. Arguments: """ mock_sys.isatty.return_value = False self.assertFalse(check_log.run_program(self.args_array))
def test_f_option_set(self): """Function: test_f_option_set Description: Test with -f option in args_array. Arguments: """ self.args_array["-f"] = self.log_file self.assertFalse(check_log.run_program(self.args_array))
def test_search_and(self): """Function: test_search_and Description: Test with and search clause. Arguments: """ with gen_libs.no_std_out(): check_log.run_program(self.args_array2) if os.path.isfile(self.test_out): with open(self.test_out) as f_hdlr: out_str = f_hdlr.readline().rstrip() self.assertEqual(out_str, self.line3) else: self.assertTrue(False)
def test_stdin_empty(self, mock_atty): """Function: test_stdin_empty Description: Test with standard in no data. Arguments: """ mock_atty.isatty.return_value = False self.assertFalse(check_log.run_program({}))
def test_full_chk(self, mock_log): """Function: test_full_chk Description: Test with full_chk returning True. Arguments: """ mock_log.return_value = self.log self.args_array["-f"] = self.log_file self.assertFalse(check_log.run_program(self.args_array))
def test_clear_option(self): """Function: test_clear_option Description: Test with -c and -m options. Arguments: """ self.args_array["-c"] = True self.args_array["-m"] = "/opt/local/check-log/markerfile" self.assertFalse(check_log.run_program(self.args_array))
def test_loglist_data(self, mock_log): """Function: test_loglist_data Description: Test with loglist having data. Arguments: """ mock_log.return_value = self.log self.args_array["-f"] = self.log_file self.assertFalse(check_log.run_program(self.args_array))
def test_filter_data(self): """Function: test_filter_data Description: Test filter data. Arguments: """ self.args_array.update({"-F": self.filter_data, "-o": self.test_out}) with gen_libs.no_std_out(): check_log.run_program(self.args_array) if os.path.isfile(self.test_out): with open(self.test_out) as f_hdlr: out_str = f_hdlr.readline().rstrip() self.assertEqual(out_str, self.line3) else: self.assertTrue(False)
def test_ignore_msg(self): """Function: test_ignore_msg Description: Test ignore messages. Arguments: """ self.args_array.update({"-i": self.ignore_msgs, "-o": self.test_out}) with gen_libs.no_std_out(): check_log.run_program(self.args_array) if os.path.isfile(self.test_out): with open(self.test_out) as f_hdlr: out_str = f_hdlr.readline().rstrip() self.assertEqual(out_str, self.line3) else: self.assertTrue(False)
def test_file_w_option(self): """Function: test_file_w_option Description: Test file logs with -w option. Arguments: """ self.args_array.update({"-f": [self.log_file2], "-o": self.test_out, "-z": True, "-w": True, "-g": "w"}) check_log.run_program(self.args_array) 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)
def test_stdin(self, mock_atty): """Function: test_stdin Description: Test with standard in. Arguments: """ mock_atty.isatty.return_value = False args_array = {"-o": self.test_out, "-z": True, "-g": "w"} check_log.run_program(args_array) 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)
def test_file(self): """Function: test_file Description: Test file logs. Arguments: """ self.args_array.update({"-f": [self.log_file2], "-o": self.test_out}) with gen_libs.no_std_out(): check_log.run_program(self.args_array) 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)