def test_dependencies(self): self.local_bear_list.append(SimpleBear(self.settings, self.message_queue)) self.local_bear_list.append(DependentBear(self.settings, self.message_queue)) self.global_bear_list.append(SimpleGlobalBear({}, self.settings, self.message_queue)) self.global_bear_list.append(DependentGlobalBear({}, self.settings, self.message_queue)) self.global_bear_queue.put(1) self.global_bear_queue.put(0) self.file_name_queue.put("t") self.file_dict["t"] = [] run(self.file_name_queue, self.local_bear_list, self.global_bear_list, self.global_bear_queue, self.file_dict, self.local_result_dict, self.global_result_dict, self.message_queue, self.control_queue) try: while True: msg = self.message_queue.get(timeout=0) self.assertEqual(msg.log_level, LOG_LEVEL.DEBUG) except queue.Empty: pass
def test_strange_bear(self): self.local_bear_list.append(UnexpectedBear1(self.settings, self.message_queue)) self.local_bear_list.append(UnexpectedBear2(self.settings, self.message_queue)) self.file_name_queue.put("t") self.file_dict["t"] = [] run(self.file_name_queue, self.local_bear_list, self.global_bear_list, self.global_bear_queue, self.file_dict, self.local_result_dict, self.global_result_dict, self.message_queue, self.control_queue) expected_messages = [LOG_LEVEL.DEBUG, LOG_LEVEL.ERROR, LOG_LEVEL.DEBUG, LOG_LEVEL.DEBUG, LOG_LEVEL.WARNING] for msg in expected_messages: self.assertEqual(msg, self.message_queue.get(timeout=0).log_level)
def test_strange_bear(self): self.local_bear_list.append(UnexpectedBear1(self.settings, self.message_queue)) self.local_bear_list.append(UnexpectedBear2(self.settings, self.message_queue)) self.file_name_queue.put('t') self.file_dict['t'] = [] run(self.file_name_queue, self.local_bear_list, self.global_bear_list, self.global_bear_queue, self.file_dict, self.local_result_dict, self.global_result_dict, self.message_queue, self.control_queue) expected_messages = [LOG_LEVEL.DEBUG, LOG_LEVEL.ERROR, LOG_LEVEL.DEBUG, LOG_LEVEL.DEBUG, LOG_LEVEL.ERROR] for msg in expected_messages: self.assertEqual(msg, self.message_queue.get(timeout=0).log_level)
def test_dependencies(self): self.local_bear_list.append(SimpleBear(self.settings, self.message_queue)) self.local_bear_list.append(DependentBear(self.settings, self.message_queue)) self.global_bear_list.append(SimpleGlobalBear({}, self.settings, self.message_queue)) self.global_bear_list.append(DependentGlobalBear({}, self.settings, self.message_queue)) self.global_bear_queue.put(1) self.global_bear_queue.put(0) self.file_name_queue.put('t') self.file_dict['t'] = [] run(self.file_name_queue, self.local_bear_list, self.global_bear_list, self.global_bear_queue, self.file_dict, self.local_result_dict, self.global_result_dict, self.message_queue, self.control_queue) try: while True: msg = self.message_queue.get(timeout=0) self.assertEqual(msg.log_level, LOG_LEVEL.DEBUG) except queue.Empty: pass
def test_bear_impossible(self): self.settings.append(Setting('cls', 'OSError')) self.settings.append(Setting('msg', 'fake error')) self.local_bear_list.append( RaiseTestExecuteBear(self.settings, self.message_queue)) self.file_name_queue.put('t') self.file_dict['t'] = [] with self.assertRaisesRegex(OSError, 'fake error'): run(self.file_name_queue, self.local_bear_list, self.global_bear_list, self.global_bear_queue, self.file_dict, self.local_result_dict, self.global_result_dict, self.message_queue, self.control_queue, debug=True, ) run(self.file_name_queue, self.local_bear_list, self.global_bear_list, self.global_bear_queue, self.file_dict, self.local_result_dict, self.global_result_dict, self.message_queue, self.control_queue, debug=False, )
def test_evil_bear(self): self.local_bear_list.append(EvilBear(self.settings, self.message_queue)) self.file_name_queue.put("t") self.file_dict["t"] = [] run(self.file_name_queue, self.local_bear_list, self.global_bear_list, self.global_bear_queue, self.file_dict, self.local_result_dict, self.global_result_dict, self.message_queue, self.control_queue)
def test_run(self): run(self.file_name_queue, self.local_bear_list, self.global_bear_list, self.global_bear_queue, self.file_dict, self.local_result_dict, self.global_result_dict, self.message_queue, self.control_queue) expected_messages = [ LOG_LEVEL.DEBUG, LOG_LEVEL.WARNING, LOG_LEVEL.DEBUG, LOG_LEVEL.WARNING, LOG_LEVEL.DEBUG, LOG_LEVEL.WARNING, LOG_LEVEL.ERROR, LOG_LEVEL.DEBUG, LOG_LEVEL.DEBUG, LOG_LEVEL.WARNING ] for msg in expected_messages: self.assertEqual(msg, self.message_queue.get(timeout=0).log_level) local_result_expected = [[], [ Result.from_values( "LocalTestBear", "something went wrong", 'arbitrary') ]] for expected in local_result_expected: control_elem, index = self.control_queue.get() self.assertEqual(control_elem, CONTROL_ELEMENT.LOCAL) real = self.local_result_dict[index] self.assertEqual(real, expected) global_results_expected = [ Result.from_values("GlobalTestBear", "Files are bad in general!", "file1", severity=RESULT_SEVERITY.INFO), Result.from_values("GlobalTestBear", "Files are bad in general!", "arbitrary", severity=RESULT_SEVERITY.INFO) ] control_elem, index = self.control_queue.get() self.assertEqual(control_elem, CONTROL_ELEMENT.LOCAL_FINISHED) control_elem, index = self.control_queue.get() self.assertEqual(control_elem, CONTROL_ELEMENT.GLOBAL) real = self.global_result_dict[index] self.assertEqual(sorted(global_results_expected), sorted(real)) control_elem, none = self.control_queue.get(timeout=0) self.assertEqual(control_elem, CONTROL_ELEMENT.GLOBAL_FINISHED) self.assertEqual(none, None) # The invalid bear gets a None in that dict for dependency resolution self.assertEqual(len(self.global_result_dict), 2) self.assertEqual(len(self.local_result_dict), len(local_result_expected)) self.assertRaises(queue.Empty, self.message_queue.get, timeout=0) self.assertRaises(queue.Empty, self.control_queue.get, timeout=0)
def test_evil_bear(self): self.settings.append(Setting('cls', 'NotImplementedError')) self.local_bear_list.append( RaiseTestExecuteBear(self.settings, self.message_queue)) self.file_name_queue.put('t') self.file_dict['t'] = [] run(self.file_name_queue, self.local_bear_list, self.global_bear_list, self.global_bear_queue, self.file_dict, self.local_result_dict, self.global_result_dict, self.message_queue, self.control_queue)
def test_run(self): run(self.file_name_queue, self.local_bear_list, self.global_bear_list, self.global_bear_queue, self.file_dict, self.local_result_dict, self.global_result_dict, self.message_queue, self.control_queue) expected_messages = [LOG_LEVEL.DEBUG, LOG_LEVEL.WARNING, LOG_LEVEL.DEBUG, LOG_LEVEL.WARNING, LOG_LEVEL.DEBUG, LOG_LEVEL.WARNING, LOG_LEVEL.ERROR, LOG_LEVEL.DEBUG, LOG_LEVEL.DEBUG, LOG_LEVEL.WARNING] for msg in expected_messages: self.assertEqual(msg, self.message_queue.get(timeout=0).log_level) local_result_expected = [[], [Result.from_values("LocalTestBear", "something went wrong", 'arbitrary')] ] for expected in local_result_expected: control_elem, index = self.control_queue.get() self.assertEqual(control_elem, CONTROL_ELEMENT.LOCAL) real = self.local_result_dict[index] self.assertEqual(real, expected) global_results_expected = [Result.from_values( "GlobalTestBear", "Files are bad in general!", "file1", severity=RESULT_SEVERITY.INFO), Result.from_values( "GlobalTestBear", "Files are bad in general!", "arbitrary", severity=RESULT_SEVERITY.INFO)] control_elem, index = self.control_queue.get() self.assertEqual(control_elem, CONTROL_ELEMENT.LOCAL_FINISHED) control_elem, index = self.control_queue.get() self.assertEqual(control_elem, CONTROL_ELEMENT.GLOBAL) real = self.global_result_dict[index] self.assertEqual(sorted(global_results_expected), sorted(real)) control_elem, none = self.control_queue.get(timeout=0) self.assertEqual(control_elem, CONTROL_ELEMENT.GLOBAL_FINISHED) self.assertEqual(none, None) # The invalid bear gets a None in that dict for dependency resolution self.assertEqual(len(self.global_result_dict), 2) self.assertEqual(len(self.local_result_dict), len(local_result_expected)) self.assertRaises(queue.Empty, self.message_queue.get, timeout=0) self.assertRaises(queue.Empty, self.control_queue.get, timeout=0)