<commit_before>package imagick

import (
	"github.com/stretchr/testify/assert"
	"path/filepath"
	"testing"
	"os"
	"io/ioutil"
)

func TestReadImageWrongFile(t *testing.T) {
	filename, _ := filepath.Abs("./test_data/none.jpg")
	img := NewMagickWand()
	defer img.Destroy()
	err := img.ReadImage(filename)

	assert.Error(t, err)
	assert.Regexp(t, "BlobError: unable to open image", err.Error())
}

func TestReadImageOK(t *testing.T) {
	filename, _ := filepath.Abs("./test_data/kth.jpg")

	img := NewMagickWand()
	defer img.Destroy()
	
	err := img.ReadImage(filename)
	assert.Nil(t, err)
	assert.Equal(t, int(img.GetImageWidth()), 320)
	assert.Equal(t, int(img.GetImageHeight()), 240)
}

func TestDestroy(t *testing.T) {
	img := NewMagickWand()
	err := img.ReadImage("./test_data/kth.jpg")
	img.Destroy()
	assert.Nil(t, img.mw)
	assert.Nil(t, err)
}

func TestGetImageBlob(t *testing.T) {
	img := NewMagickWand()
	defer img.Destroy()
	err := img.ReadImage("./test_data/kth.jpg")
	assert.Nil(t, err)
	assert.InEpsilon(t, len(img.GetImageBlob()), 28611, 10)
}


func TestReadImageBlob(t *testing.T) {
	img := NewMagickWand()
	defer img.Destroy()
	
	file, err := os.Open("./test_data/kth.jpg")
	assert.Nil(t, err)
	defer file.Close()
	imgData, err := ioutil.ReadAll(file)
	assert.Nil(t, err)
	err = img.ReadImageBlob(imgData)
	assert.Nil(t, err)
	assert.InEpsilon(t, len(img.GetImageBlob()), 28611, 10)
	assert.Equal(t, int(img.GetImageWidth()), 320)
	assert.Equal(t, int(img.GetImageHeight()), 240)
}

func TestRotateImage(t *testing.T) {<commit_msg>Adding test for zero byte blob<commit_after>package imagick

import (
	"github.com/stretchr/testify/assert"
	"path/filepath"
	"testing"
	"os"
	"io/ioutil"
)

func TestReadImageWrongFile(t *testing.T) {
	filename, _ := filepath.Abs("./test_data/none.jpg")
	img := NewMagickWand()
	defer img.Destroy()
	err := img.ReadImage(filename)

	assert.Error(t, err)
	assert.Regexp(t, "BlobError: unable to open image", err.Error())
}

func TestReadImageOK(t *testing.T) {
	filename, _ := filepath.Abs("./test_data/kth.jpg")

	img := NewMagickWand()
	defer img.Destroy()
	
	err := img.ReadImage(filename)
	assert.Nil(t, err)
	assert.Equal(t, int(img.GetImageWidth()), 320)
	assert.Equal(t, int(img.GetImageHeight()), 240)
}

func TestDestroy(t *testing.T) {
	img := NewMagickWand()
	err := img.ReadImage("./test_data/kth.jpg")
	img.Destroy()
	assert.Nil(t, img.mw)
	assert.Nil(t, err)
}

func TestGetImageBlob(t *testing.T) {
	img := NewMagickWand()
	defer img.Destroy()
	err := img.ReadImage("./test_data/kth.jpg")
	assert.Nil(t, err)
	assert.InEpsilon(t, len(img.GetImageBlob()), 28611, 10)
}


func TestReadImageBlob(t *testing.T) {
	img := NewMagickWand()
	defer img.Destroy()
	
	file, err := os.Open("./test_data/kth.jpg")
	assert.Nil(t, err)
	defer file.Close()
	imgData, err := ioutil.ReadAll(file)
	assert.Nil(t, err)
	err = img.ReadImageBlob(imgData)
	assert.Nil(t, err)
	assert.InEpsilon(t, len(img.GetImageBlob()), 28611, 10)
	assert.Equal(t, int(img.GetImageWidth()), 320)
	assert.Equal(t, int(img.GetImageHeight()), 240)
}

func TestReadImageBlobZeroLength(t *testing.T) {
	img := NewMagickWand()
	defer img.Destroy()
	assert.Error(t, img.ReadImageBlob([]byte{}))
}

func TestRotateImage(t *testing.T) {
{'fraction_non_alphanumeric': 0.17857142857142858, 'fraction_numerical': 0.01600985221674877, 'mean_word_length': 4.907272727272727, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5080171', 'n_tokens_mistral': 1368, 'n_tokens_neox': 1304, 'n_words': 234}