def test_hex_to_str_function(self): """ Verify that the UUT uses the custom hex_to_str function, if provided. Given: FuzzLoggerCsv with a virtual file handle and custom hex_to_str function. When: Calling open_test_case with some test_case_id. and: Calling log_recv with some data. Then: open_test_case logs as expected. and: log_recv logs as expected, using the custom hex_to_str function. """ # Given def hex_to_str(hex_data): return hex_data.decode() self.logger = fuzz_logger_csv.FuzzLoggerCsv(file_handle=self.virtual_file, bytes_to_str=hex_to_str) # When self.logger.open_test_case(self.some_test_case_id, name=self.some_test_case_name, index=self.some_test_case_index) self.logger.log_recv(self.some_recv_data) # Then self.virtual_file.seek(0) six.assertRegex(self, self.virtual_file.readline(), LOGGER_PREAMBLE + re.escape( "open test case,,,Test case " + self.some_test_case_id + "\r\n")) six.assertRegex(self, self.virtual_file.readline(), LOGGER_PREAMBLE + re.escape( "recv," + str(len(self.some_recv_data)) + "," + hex_to_str( self.some_recv_data) + "," + self.some_recv_data.decode() + "\r\n"))
def setUp(self): self.virtual_file = StringIO.StringIO() self.logger = fuzz_logger_csv.FuzzLoggerCsv( file_handle=self.virtual_file) self.some_test_case_id = "some test case" self.some_test_step_msg = "Test!!!" self.some_log_check_msg = "logging" self.some_log_info_msg = "information" self.some_log_fail_msg = "broken" self.some_log_pass_msg = "it works so far!" self.some_log_error_msg = "D:" self.some_recv_data = bytes('A B C') self.some_send_data = bytes('123')