def test_plot_high_entropy_file(self): temp_dir = tempfile.gettempdir() # temp_dir = self.test_file_dir bin_src = os.path.join( temp_dir, 'CodescannerAnalysisDataTest-test_plot_high_entropy_file.bin') bp_src = os.path.join( temp_dir, 'CodescannerAnalysisDataTest-test_plot_high_entropy_file.pic.png') bar_src = os.path.join( temp_dir, 'CodescannerAnalysisDataTest-test_plot_high_entropy_file.bar.png') helper.create_random_file(bin_src, 0x800) cad = CodescannerAnalysisData(bin_src) cad.regions['HighEntropy'] = [(0, 3584)] bar_bytes = cad.plot_to_buffer(100, cad.COLOR_MAP) bp_bytes = cad.plot_to_buffer(100, cad.BYTE_PLOT) cad.plot_to_file(bar_src, 100, cad.COLOR_MAP) cad.plot_to_file(bp_src, 100, cad.BYTE_PLOT) assert bar_bytes.startswith(helper.MAGIC_PNG_BYTES) assert bp_bytes.startswith(helper.MAGIC_PNG_BYTES) assert os.path.isfile(bar_src) assert os.path.isfile(bp_src) os.remove(bin_src) os.remove(bar_src) os.remove(bp_src)
def test_plot_to_buffer_byte_plot(self): ''' To visually test the output, this method may be run with calling the _write_image method. Otherwise it only tests if the bytes would create a png file. ''' cad = CodescannerAnalysisData(self.test_file) pic_bytes = cad.plot_to_buffer(100, cad.BYTE_PLOT) assert pic_bytes.startswith(helper.MAGIC_PNG_BYTES)
def test_plot_to_buffer_color_map(self): ''' To visually test the output, this method may be run with calling the _write_image method. Otherwise it only tests if the bytes would create a png file. ''' cad = CodescannerAnalysisData(self.test_file) pic_bytes = cad.plot_to_buffer(100, cad.COLOR_MAP) # test_img = self._get_image_src(self._test_file_dir, 'ccsat_test_plot_to_buffer_color_bar.png') # cad.write_image(pic_bytes, test_img) assert pic_bytes.startswith(helper.MAGIC_PNG_BYTES)
def test_not_supported_file_plot(self): dpi = 100 temp_dir = tempfile.gettempdir() unsupported = os.path.join( temp_dir, 'CodescannerAnalysisDataTest-est_not_supported_file_plot_in.png') cad = CodescannerAnalysisData(self.test_file) cad.plot_to_file(str(unsupported), dpi, True) # img_path2 = self._get_image_src(self._test_file_dir, 'test_not_supported_file_plot.png') img_path2 = os.path.join( temp_dir, 'CodescannerAnalysisDataTest-test_not_supported_file_plot_out.png') cad = CodescannerAnalysisData(unsupported) cad.plot_to_file(img_path2, dpi, True) pic_bytes = cad.plot_to_buffer(dpi, True) assert pic_bytes.startswith(helper.MAGIC_PNG_BYTES) os.remove(unsupported) os.remove(img_path2)