def test_save_data(self, versioned_plot_writer, mock_single_plot, tmp_path): """Test saving dictionary of plots with enabled versioning.""" versioned_plot_writer.save(mock_single_plot) test_path = tmp_path / "test_image.png" actual_filepath = PosixPath(versioned_plot_writer._get_load_path()) plt.savefig(str(test_path)) assert actual_filepath.read_bytes() == test_path.read_bytes()
def test_dict_save(self, tmp_path, mock_dict_plot, versioned_plot_writer): """Test saving dictionary of plots with enabled versioning.""" versioned_plot_writer.save(mock_dict_plot) for colour in COLOUR_LIST: test_path = tmp_path / "test_image.png" versioned_filepath = str(versioned_plot_writer._get_load_path()) mock_dict_plot[colour].savefig(str(test_path)) actual_filepath = PosixPath("{}/{}".format(versioned_filepath, colour)) assert actual_filepath.read_bytes() == test_path.read_bytes()
def test_list_save(self, tmp_path, mock_list_plot, versioned_plot_writer): """Test saving list of plots to with enabled versioning.""" versioned_plot_writer.save(mock_list_plot) for index in range(5): test_path = tmp_path / "test_image.png" versioned_filepath = str(versioned_plot_writer._get_load_path()) mock_list_plot[index].savefig(str(test_path)) actual_filepath = PosixPath("{}/{}.png".format( versioned_filepath, index)) assert actual_filepath.read_bytes() == test_path.read_bytes()
def translate_to_lf_line_endings(file: PosixPath) -> None: file_bytes_original_line_endings = file.read_bytes() file_bytes_lf_line_endings = file_bytes_original_line_endings.replace( b'\r\n', b'\n') file.write_bytes(file_bytes_lf_line_endings)