Slow test refactoring (now using testing.Short())

This commit is contained in:
Michael Mayer 2019-04-29 20:09:10 +02:00
parent f242f117f4
commit b079882354
13 changed files with 289 additions and 317 deletions

View file

@ -12,67 +12,70 @@ func TestMediaFile_GetColors(t *testing.T) {
conf.InitializeTestData(t)
if mediaFile1, err := NewMediaFile(conf.ImportPath() + "/dog.jpg"); err == nil {
colors, main, l, s, err := mediaFile1.Colors()
t.Run("dog.jpg", func(t *testing.T) {
if mediaFile, err := NewMediaFile(conf.ImportPath() + "/dog.jpg"); err == nil {
colors, main, l, s, err := mediaFile.Colors()
t.Log(colors, main, l, s, err)
t.Log(colors, main, l, s, err)
assert.Nil(t, err)
assert.Equal(t, 2, s.Int())
assert.IsType(t, MaterialColors{}, colors)
assert.Equal(t, "grey", main.Name())
assert.Equal(t, MaterialColors{0x1, 0x2, 0x1, 0x2, 0x2, 0x1, 0x1, 0x1, 0x0}, colors)
assert.Equal(t, LightMap{5, 9, 7, 10, 9, 5, 5, 6, 2}, l)
} else {
t.Error(err)
}
assert.Nil(t, err)
assert.Equal(t, 2, s.Int())
assert.IsType(t, MaterialColors{}, colors)
assert.Equal(t, "grey", main.Name())
assert.Equal(t, MaterialColors{0x1, 0x2, 0x1, 0x2, 0x2, 0x1, 0x1, 0x1, 0x0}, colors)
assert.Equal(t, LightMap{5, 9, 7, 10, 9, 5, 5, 6, 2}, l)
} else {
t.Error(err)
}
})
if mediaFile2, err := NewMediaFile(conf.ImportPath() + "/ape.jpeg"); err == nil {
colors, main, l, s, err := mediaFile2.Colors()
t.Run("ape.jpeg", func(t *testing.T) {
if mediaFile, err := NewMediaFile(conf.ImportPath() + "/ape.jpeg"); err == nil {
colors, main, l, s, err := mediaFile.Colors()
t.Log(colors, main, l, s, err)
t.Log(colors, main, l, s, err)
assert.Nil(t, err)
assert.Equal(t, 3, s.Int())
assert.IsType(t, MaterialColors{}, colors)
assert.Equal(t, "teal", main.Name())
assert.Equal(t, MaterialColors{0x8, 0x8, 0x2, 0x8, 0x2, 0x1, 0x8, 0x1, 0x2}, colors)
assert.Equal(t, LightMap{8, 8, 7, 7, 7, 5, 8, 6, 8}, l)
} else {
t.Error(err)
}
assert.Nil(t, err)
assert.Equal(t, 3, s.Int())
assert.IsType(t, MaterialColors{}, colors)
assert.Equal(t, "teal", main.Name())
assert.Equal(t, MaterialColors{0x8, 0x8, 0x2, 0x8, 0x2, 0x1, 0x8, 0x1, 0x2}, colors)
assert.Equal(t, LightMap{8, 8, 7, 7, 7, 5, 8, 6, 8}, l)
} else {
t.Error(err)
}
})
if testing.Short() {
return
}
t.Run("iphone/IMG_6788.JPG", func(t *testing.T) {
if mediaFile, err := NewMediaFile(conf.ImportPath() + "/iphone/IMG_6788.JPG"); err == nil {
colors, main, l, s, err := mediaFile.Colors()
if mediaFile2, err := NewMediaFile(conf.ImportPath() + "/iphone/IMG_6788.JPG"); err == nil {
colors, main, l, s, err := mediaFile2.Colors()
t.Log(colors, main, l, s, err)
t.Log(colors, main, l, s, err)
assert.Nil(t, err)
assert.Equal(t, 3, s.Int())
assert.IsType(t, MaterialColors{}, colors)
assert.Equal(t, "grey", main.Name())
assert.Equal(t, MaterialColors{0x2, 0x1, 0x2, 0x1, 0x1, 0x1, 0x2, 0x1, 0x2}, colors)
} else {
t.Error(err)
}
})
assert.Nil(t, err)
assert.Equal(t, 3, s.Int())
assert.IsType(t, MaterialColors{}, colors)
assert.Equal(t, "grey", main.Name())
assert.Equal(t, MaterialColors{0x2, 0x1, 0x2, 0x1, 0x1, 0x1, 0x2, 0x1, 0x2}, colors)
} else {
t.Error(err)
}
t.Run("raw/20140717_154212_1EC48F8489.jpg", func(t *testing.T) {
if mediaFile, err := NewMediaFile(conf.ImportPath() + "/raw/20140717_154212_1EC48F8489.jpg"); err == nil {
colors, main, l, s, err := mediaFile.Colors()
if mediaFile3, err := NewMediaFile(conf.ImportPath() + "/raw/20140717_154212_1EC48F8489.jpg"); err == nil {
colors, main, l, s, err := mediaFile3.Colors()
t.Log(colors, main, l, s, err)
t.Log(colors, main, l, s, err)
assert.Nil(t, err)
assert.Equal(t, 2, s.Int())
assert.IsType(t, MaterialColors{}, colors)
assert.Equal(t, "grey", main.Name())
assert.Nil(t, err)
assert.Equal(t, 2, s.Int())
assert.IsType(t, MaterialColors{}, colors)
assert.Equal(t, "grey", main.Name())
assert.Equal(t, MaterialColors{0x3, 0x2, 0x2, 0x1, 0x2, 0x2, 0x2, 0x2, 0x1}, colors)
} else {
t.Error(err)
}
assert.Equal(t, MaterialColors{0x3, 0x2, 0x2, 0x1, 0x2, 0x2, 0x2, 0x2, 0x1}, colors)
} else {
t.Error(err)
}
})
}

View file

@ -1,104 +0,0 @@
// +build slow
package photoprism
import (
"os"
"testing"
"github.com/photoprism/photoprism/internal/fsutil"
"github.com/photoprism/photoprism/internal/test"
"github.com/stretchr/testify/assert"
)
func TestConverter_ConvertToJpeg(t *testing.T) {
conf := test.NewConfig()
conf.InitializeTestData(t)
converter := NewConverter(conf.DarktableCli())
jpegFilename := conf.ImportPath() + "/iphone/IMG_6788.JPG"
assert.Truef(t, fsutil.Exists(jpegFilename), "file does not exist: %s", jpegFilename)
t.Logf("Testing RAW to JPEG converter with %s", jpegFilename)
jpegMediaFile, err := NewMediaFile(jpegFilename)
assert.Nil(t, err)
imageJpeg, err := converter.ConvertToJpeg(jpegMediaFile)
assert.Empty(t, err, "ConvertToJpeg() failed")
infoJpeg, err := imageJpeg.GetExifData()
assert.Emptyf(t, err, "GetExifData() failed")
assert.Equal(t, jpegFilename, imageJpeg.filename)
assert.False(t, infoJpeg == nil || err != nil, "Could not read EXIF data of JPEG image")
assert.Equal(t, "iPhone SE", infoJpeg.CameraModel)
rawFilemame := conf.ImportPath() + "/raw/IMG_1435.CR2"
t.Logf("Testing RAW to JPEG converter with %s", rawFilemame)
rawMediaFile, err := NewMediaFile(rawFilemame)
assert.Nil(t, err)
imageRaw, _ := converter.ConvertToJpeg(rawMediaFile)
assert.True(t, fsutil.Exists(conf.ImportPath()+"/raw/IMG_1435.jpg"), "Jpeg file was not found - is Darktable installed?")
assert.NotEqual(t, rawFilemame, imageRaw.filename)
infoRaw, err := imageRaw.GetExifData()
assert.False(t, infoRaw == nil || err != nil, "Could not read EXIF data of RAW image")
assert.Equal(t, "Canon EOS M10", infoRaw.CameraModel)
}
func TestConverter_ConvertAll(t *testing.T) {
conf := test.NewConfig()
conf.InitializeTestData(t)
converter := NewConverter(conf.DarktableCli())
converter.ConvertAll(conf.ImportPath())
jpegFilename := conf.ImportPath() + "/raw/IMG_1435.jpg"
assert.True(t, fsutil.Exists(jpegFilename), "Jpeg file was not found - is Darktable installed?")
image, err := NewMediaFile(jpegFilename)
assert.Nil(t, err)
assert.Equal(t, jpegFilename, image.filename, "FileName must be the same")
infoRaw, err := image.GetExifData()
assert.False(t, infoRaw == nil || err != nil, "Could not read EXIF data of RAW image")
assert.Equal(t, "Canon EOS M10", infoRaw.CameraModel, "Camera model should be Canon EOS M10")
existingJpegFilename := conf.ImportPath() + "/raw/20140717_154212_1EC48F8489.jpg"
oldHash := fsutil.Hash(existingJpegFilename)
os.Remove(existingJpegFilename)
converter.ConvertAll(conf.ImportPath())
newHash := fsutil.Hash(existingJpegFilename)
assert.True(t, fsutil.Exists(existingJpegFilename), "Jpeg file was not found - is Darktable installed?")
assert.NotEqual(t, oldHash, newHash, "Fingerprint of old and new JPEG file must not be the same")
}

View file

@ -1,8 +1,10 @@
package photoprism
import (
"os"
"testing"
"github.com/photoprism/photoprism/internal/fsutil"
"github.com/photoprism/photoprism/internal/test"
"github.com/stretchr/testify/assert"
)
@ -14,3 +16,103 @@ func TestNewConverter(t *testing.T) {
assert.IsType(t, &Converter{}, converter)
}
func TestConverter_ConvertToJpeg(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}
conf := test.NewConfig()
conf.InitializeTestData(t)
converter := NewConverter(conf.DarktableCli())
jpegFilename := conf.ImportPath() + "/iphone/IMG_6788.JPG"
assert.Truef(t, fsutil.Exists(jpegFilename), "file does not exist: %s", jpegFilename)
t.Logf("Testing RAW to JPEG converter with %s", jpegFilename)
jpegMediaFile, err := NewMediaFile(jpegFilename)
assert.Nil(t, err)
imageJpeg, err := converter.ConvertToJpeg(jpegMediaFile)
assert.Empty(t, err, "ConvertToJpeg() failed")
infoJpeg, err := imageJpeg.GetExifData()
assert.Emptyf(t, err, "GetExifData() failed")
assert.Equal(t, jpegFilename, imageJpeg.filename)
assert.False(t, infoJpeg == nil || err != nil, "Could not read EXIF data of JPEG image")
assert.Equal(t, "iPhone SE", infoJpeg.CameraModel)
rawFilemame := conf.ImportPath() + "/raw/IMG_1435.CR2"
t.Logf("Testing RAW to JPEG converter with %s", rawFilemame)
rawMediaFile, err := NewMediaFile(rawFilemame)
assert.Nil(t, err)
imageRaw, _ := converter.ConvertToJpeg(rawMediaFile)
assert.True(t, fsutil.Exists(conf.ImportPath()+"/raw/IMG_1435.jpg"), "Jpeg file was not found - is Darktable installed?")
assert.NotEqual(t, rawFilemame, imageRaw.filename)
infoRaw, err := imageRaw.GetExifData()
assert.False(t, infoRaw == nil || err != nil, "Could not read EXIF data of RAW image")
assert.Equal(t, "Canon EOS M10", infoRaw.CameraModel)
}
func TestConverter_ConvertAll(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}
conf := test.NewConfig()
conf.InitializeTestData(t)
converter := NewConverter(conf.DarktableCli())
converter.ConvertAll(conf.ImportPath())
jpegFilename := conf.ImportPath() + "/raw/IMG_1435.jpg"
assert.True(t, fsutil.Exists(jpegFilename), "Jpeg file was not found - is Darktable installed?")
image, err := NewMediaFile(jpegFilename)
assert.Nil(t, err)
assert.Equal(t, jpegFilename, image.filename, "FileName must be the same")
infoRaw, err := image.GetExifData()
assert.False(t, infoRaw == nil || err != nil, "Could not read EXIF data of RAW image")
assert.Equal(t, "Canon EOS M10", infoRaw.CameraModel, "Camera model should be Canon EOS M10")
existingJpegFilename := conf.ImportPath() + "/raw/20140717_154212_1EC48F8489.jpg"
oldHash := fsutil.Hash(existingJpegFilename)
os.Remove(existingJpegFilename)
converter.ConvertAll(conf.ImportPath())
newHash := fsutil.Hash(existingJpegFilename)
assert.True(t, fsutil.Exists(existingJpegFilename), "Jpeg file was not found - is Darktable installed?")
assert.NotEqual(t, oldHash, newHash, "Fingerprint of old and new JPEG file must not be the same")
}

View file

@ -1,28 +0,0 @@
// +build slow
package photoprism
import (
"testing"
"github.com/photoprism/photoprism/internal/test"
"github.com/stretchr/testify/assert"
)
func TestMediaFile_GetExifData_Slow(t *testing.T) {
conf := test.NewConfig()
conf.InitializeTestData(t)
image2, err := NewMediaFile(conf.ImportPath() + "/raw/IMG_1435.CR2")
assert.Nil(t, err)
info, err := image2.GetExifData()
assert.Empty(t, err)
assert.IsType(t, &ExifData{}, info)
assert.Equal(t, "Canon EOS M10", info.CameraModel)
}

View file

@ -24,3 +24,25 @@ func TestMediaFile_GetExifData(t *testing.T) {
assert.Equal(t, "iPhone SE", info.CameraModel)
}
func TestMediaFile_GetExifData_Slow(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}
conf := test.NewConfig()
conf.InitializeTestData(t)
image2, err := NewMediaFile(conf.ImportPath() + "/raw/IMG_1435.CR2")
assert.Nil(t, err)
info, err := image2.GetExifData()
assert.Empty(t, err)
assert.IsType(t, &ExifData{}, info)
assert.Equal(t, "Canon EOS M10", info.CameraModel)
}

View file

@ -1,25 +0,0 @@
// +build slow
package photoprism
import (
"testing"
"github.com/photoprism/photoprism/internal/test"
)
func TestImporter_ImportPhotosFromDirectory(t *testing.T) {
conf := test.NewConfig()
conf.InitializeTestData(t)
tensorFlow := NewTensorFlow(conf.TensorFlowModelPath())
indexer := NewIndexer(conf.OriginalsPath(), tensorFlow, conf.Db())
converter := NewConverter(conf.DarktableCli())
importer := NewImporter(conf.OriginalsPath(), indexer, converter)
importer.ImportPhotosFromDirectory(conf.ImportPath())
}

View file

@ -43,3 +43,23 @@ func TestImporter_GetDestinationFilename(t *testing.T) {
assert.Equal(t, conf.OriginalsPath()+"/2018/02/20180204_170813_863A6248DCCA.cr2", filename)
}
func TestImporter_ImportPhotosFromDirectory(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}
conf := test.NewConfig()
conf.InitializeTestData(t)
tensorFlow := NewTensorFlow(conf.TensorFlowModelPath())
indexer := NewIndexer(conf.OriginalsPath(), tensorFlow, conf.Db())
converter := NewConverter(conf.DarktableCli())
importer := NewImporter(conf.OriginalsPath(), indexer, converter)
importer.ImportPhotosFromDirectory(conf.ImportPath())
}

View file

@ -1,42 +0,0 @@
// +build slow
package photoprism
import (
"testing"
"github.com/photoprism/photoprism/internal/test"
"github.com/stretchr/testify/assert"
)
func TestMediaFile_GetPerceptiveHash_Slow(t *testing.T) {
conf := test.NewConfig()
conf.InitializeTestData(t)
mediaFile1, err := NewMediaFile(conf.ImportPath() + "/20130203_193332_0AE340D280.jpg")
assert.Nil(t, err)
hash1, _ := mediaFile1.GetPerceptualHash()
assert.Equal(t, "ef95", hash1)
mediaFile2, err := NewMediaFile(conf.ImportPath() + "/20130203_193332_0AE340D280_V2.jpg")
assert.Nil(t, err)
hash2, _ := mediaFile2.GetPerceptualHash()
assert.Equal(t, "6f95", hash2)
distance, _ := mediaFile1.GetPerceptualDistance(hash2)
assert.Equal(t, 1, distance)
mediaFile3, err := NewMediaFile(conf.ImportPath() + "/iphone/IMG_6788.JPG")
assert.Nil(t, err)
hash3, _ := mediaFile3.GetPerceptualHash()
assert.Equal(t, "ad73", hash3)
distance, _ = mediaFile1.GetPerceptualDistance(hash3)
assert.Equal(t, 7, distance)
}

View file

@ -120,3 +120,39 @@ func TestMediaFile_Exists(t *testing.T) {
assert.NotNil(t, err)
assert.Nil(t, mediaFile)
}
func TestMediaFile_GetPerceptiveHash_Slow(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}
conf := test.NewConfig()
conf.InitializeTestData(t)
mediaFile1, err := NewMediaFile(conf.ImportPath() + "/20130203_193332_0AE340D280.jpg")
assert.Nil(t, err)
hash1, _ := mediaFile1.GetPerceptualHash()
assert.Equal(t, "ef95", hash1)
mediaFile2, err := NewMediaFile(conf.ImportPath() + "/20130203_193332_0AE340D280_V2.jpg")
assert.Nil(t, err)
hash2, _ := mediaFile2.GetPerceptualHash()
assert.Equal(t, "6f95", hash2)
distance, _ := mediaFile1.GetPerceptualDistance(hash2)
assert.Equal(t, 1, distance)
mediaFile3, err := NewMediaFile(conf.ImportPath() + "/iphone/IMG_6788.JPG")
assert.Nil(t, err)
hash3, _ := mediaFile3.GetPerceptualHash()
assert.Equal(t, "ad73", hash3)
distance, _ = mediaFile1.GetPerceptualDistance(hash3)
assert.Equal(t, 7, distance)
}

View file

@ -1,36 +0,0 @@
// +build slow
package photoprism
import (
"io/ioutil"
"math"
"testing"
"github.com/photoprism/photoprism/internal/test"
"github.com/stretchr/testify/assert"
)
func TestTensorFlow_GetImageTags(t *testing.T) {
conf := test.NewConfig()
conf.InitializeTestData(t)
tensorFlow := NewTensorFlow(conf.TensorFlowModelPath())
if imageBuffer, err := ioutil.ReadFile(conf.ImportPath() + "/iphone/IMG_6788.JPG"); err != nil {
t.Error(err)
} else {
result, err := tensorFlow.GetImageTags(string(imageBuffer))
assert.NotNil(t, result)
assert.Nil(t, err)
assert.IsType(t, []TensorFlowLabel{}, result)
assert.Equal(t, 5, len(result))
assert.Equal(t, "tabby", result[0].Label)
assert.Equal(t, "tiger cat", result[1].Label)
assert.Equal(t, float64(0.165), math.Round(float64(result[1].Probability)*1000)/1000)
}
}

View file

@ -1,6 +1,7 @@
package photoprism
import (
"io/ioutil"
"math"
"testing"
@ -27,3 +28,31 @@ func TestTensorFlow_GetImageTagsFromFile(t *testing.T) {
assert.Equal(t, float64(0.165), math.Round(float64(result[1].Probability)*1000)/1000)
}
func TestTensorFlow_GetImageTags(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}
conf := test.NewConfig()
conf.InitializeTestData(t)
tensorFlow := NewTensorFlow(conf.TensorFlowModelPath())
if imageBuffer, err := ioutil.ReadFile(conf.ImportPath() + "/iphone/IMG_6788.JPG"); err != nil {
t.Error(err)
} else {
result, err := tensorFlow.GetImageTags(string(imageBuffer))
assert.NotNil(t, result)
assert.Nil(t, err)
assert.IsType(t, []TensorFlowLabel{}, result)
assert.Equal(t, 5, len(result))
assert.Equal(t, "tabby", result[0].Label)
assert.Equal(t, "tiger cat", result[1].Label)
assert.Equal(t, float64(0.165), math.Round(float64(result[1].Probability)*1000)/1000)
}
}

View file

@ -1,31 +0,0 @@
// +build slow
package photoprism
import (
"testing"
"github.com/photoprism/photoprism/internal/test"
)
func TestCreateThumbnailsFromOriginals(t *testing.T) {
conf := test.NewConfig()
conf.CreateDirectories()
conf.InitializeTestData(t)
tensorFlow := NewTensorFlow(conf.TensorFlowModelPath())
indexer := NewIndexer(conf.OriginalsPath(), tensorFlow, conf.Db())
converter := NewConverter(conf.DarktableCli())
importer := NewImporter(conf.OriginalsPath(), indexer, converter)
importer.ImportPhotosFromDirectory(conf.ImportPath())
CreateThumbnailsFromOriginals(conf.OriginalsPath(), conf.ThumbnailsPath(), 600, false)
CreateThumbnailsFromOriginals(conf.OriginalsPath(), conf.ThumbnailsPath(), 300, true)
}

View file

@ -40,3 +40,29 @@ func TestMediaFile_GetSquareThumbnail(t *testing.T) {
assert.IsType(t, &MediaFile{}, thumbnail1)
}
func TestCreateThumbnailsFromOriginals(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}
conf := test.NewConfig()
conf.CreateDirectories()
conf.InitializeTestData(t)
tensorFlow := NewTensorFlow(conf.TensorFlowModelPath())
indexer := NewIndexer(conf.OriginalsPath(), tensorFlow, conf.Db())
converter := NewConverter(conf.DarktableCli())
importer := NewImporter(conf.OriginalsPath(), indexer, converter)
importer.ImportPhotosFromDirectory(conf.ImportPath())
CreateThumbnailsFromOriginals(conf.OriginalsPath(), conf.ThumbnailsPath(), 600, false)
CreateThumbnailsFromOriginals(conf.OriginalsPath(), conf.ThumbnailsPath(), 300, true)
}