Improve test coverage (#206)
* #83 Add NewLocation() function * #83 Add NewPlace() function * #83 Add tests for maps/places/location * #83 Add tests for maps/location * #83 Add tests for internal/config * #83 Add test for meta/exif * #83 Add testfiles
This commit is contained in:
parent
aafeda0919
commit
6b1babe0ba
9 changed files with 165 additions and 35 deletions
|
@ -46,6 +46,14 @@ func TestConfig_TensorFlowVersion(t *testing.T) {
|
|||
assert.Equal(t, "1.14.0", version)
|
||||
}
|
||||
|
||||
func TestConfig_TensorFlowDisabled(t *testing.T) {
|
||||
ctx := CliTestContext()
|
||||
c := NewConfig(ctx)
|
||||
|
||||
version := c.TensorFlowDisabled()
|
||||
assert.Equal(t, false, version)
|
||||
}
|
||||
|
||||
func TestConfig_Copyright(t *testing.T) {
|
||||
ctx := CliTestContext()
|
||||
c := NewConfig(ctx)
|
||||
|
|
|
@ -44,9 +44,16 @@ type LocationSource interface {
|
|||
Source() string
|
||||
}
|
||||
|
||||
func NewLocation(id string) *Location {
|
||||
func NewLocation(id string, name string, category string, label string, city string, state string, country string, source string) *Location {
|
||||
result := &Location{
|
||||
ID: id,
|
||||
ID: id,
|
||||
LocName: name,
|
||||
LocCategory: category,
|
||||
LocLabel: label,
|
||||
LocCity: city,
|
||||
LocState: state,
|
||||
LocCountry: country,
|
||||
LocSource: source,
|
||||
}
|
||||
|
||||
return result
|
||||
|
|
|
@ -15,7 +15,7 @@ func TestLocation_QueryPlaces(t *testing.T) {
|
|||
lng := 13.40806264572578
|
||||
id := s2.Token(lat, lng)
|
||||
|
||||
l := NewLocation(id)
|
||||
l := NewLocation(id, "", "", "", "", "", "", "")
|
||||
|
||||
if err := l.QueryPlaces(); err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -179,7 +179,7 @@ func TestLocation_Unknown(t *testing.T) {
|
|||
lng := 0.0
|
||||
id := s2.Token(lat, lng)
|
||||
|
||||
l := NewLocation(id)
|
||||
l := NewLocation(id, "", "", "", "", "", "", "")
|
||||
|
||||
assert.Equal(t, true, l.Unknown())
|
||||
})
|
||||
|
@ -188,7 +188,7 @@ func TestLocation_Unknown(t *testing.T) {
|
|||
lng := 29.148046666666666
|
||||
id := s2.Token(lat, lng)
|
||||
|
||||
l := NewLocation(id)
|
||||
l := NewLocation(id, "", "", "", "", "", "", "")
|
||||
|
||||
assert.Equal(t, false, l.Unknown())
|
||||
})
|
||||
|
@ -200,12 +200,12 @@ func TestLocation_place(t *testing.T) {
|
|||
lng := 0.0
|
||||
id := s2.Token(lat, lng)
|
||||
|
||||
l := NewLocation(id)
|
||||
l := NewLocation(id, "", "", "", "", "", "", "")
|
||||
|
||||
assert.Equal(t, "Unknown", l.label())
|
||||
})
|
||||
t.Run("Nürnberg, Bayern, Germany", func(t *testing.T) {
|
||||
l := &Location{LocCountry: "de", LocCity: "Nürnberg", LocState: "Bayern"}
|
||||
l := NewLocation("", "", "", "", "Nürnberg", "Bayern", "de", "")
|
||||
|
||||
assert.Equal(t, "Unknown", l.label())
|
||||
})
|
||||
|
@ -213,7 +213,7 @@ func TestLocation_place(t *testing.T) {
|
|||
|
||||
func TestLocation_Name(t *testing.T) {
|
||||
t.Run("Christkindlesmarkt", func(t *testing.T) {
|
||||
l := &Location{LocCountry: "de", LocCity: "Nürnberg", LocState: "Bayern", LocName: "Christkindlesmarkt"}
|
||||
l := NewLocation("", "Christkindlesmarkt", "", "", "Nürnberg", "Bayern", "de", "")
|
||||
|
||||
assert.Equal(t, "Christkindlesmarkt", l.Name())
|
||||
})
|
||||
|
@ -221,7 +221,7 @@ func TestLocation_Name(t *testing.T) {
|
|||
|
||||
func TestLocation_City(t *testing.T) {
|
||||
t.Run("Nürnberg", func(t *testing.T) {
|
||||
l := &Location{LocCountry: "de", LocCity: "Nürnberg", LocState: "Bayern", LocName: "Christkindlesmarkt"}
|
||||
l := NewLocation("", "Christkindlesmarkt", "", "", "Nürnberg", "Bayern", "de", "")
|
||||
|
||||
assert.Equal(t, "Nürnberg", l.City())
|
||||
})
|
||||
|
@ -229,7 +229,7 @@ func TestLocation_City(t *testing.T) {
|
|||
|
||||
func TestLocation_State(t *testing.T) {
|
||||
t.Run("Bayern", func(t *testing.T) {
|
||||
l := &Location{LocCountry: "de", LocCity: "Nürnberg", LocState: "Bayern", LocName: "Christkindlesmarkt"}
|
||||
l := NewLocation("", "Christkindlesmarkt", "", "", "Nürnberg", "Bayern", "de", "")
|
||||
|
||||
assert.Equal(t, "Bayern", l.State())
|
||||
})
|
||||
|
@ -237,7 +237,7 @@ func TestLocation_State(t *testing.T) {
|
|||
|
||||
func TestLocation_Category(t *testing.T) {
|
||||
t.Run("test", func(t *testing.T) {
|
||||
l := &Location{LocCategory: "test", LocCountry: "de", LocCity: "Nürnberg", LocState: "Bayern", LocName: "Christkindlesmarkt"}
|
||||
l := NewLocation("", "Christkindlesmarkt", "test", "", "Nürnberg", "Bayern", "de", "")
|
||||
|
||||
assert.Equal(t, "test", l.Category())
|
||||
})
|
||||
|
@ -245,7 +245,7 @@ func TestLocation_Category(t *testing.T) {
|
|||
|
||||
func TestLocation_Source(t *testing.T) {
|
||||
t.Run("source", func(t *testing.T) {
|
||||
l := &Location{LocCategory: "test", LocCountry: "de", LocCity: "Nürnberg", LocState: "Bayern", LocName: "Christkindlesmarkt", LocSource: "source"}
|
||||
l := NewLocation("", "Christkindlesmarkt", "", "", "Nürnberg", "Bayern", "de", "source")
|
||||
|
||||
assert.Equal(t, "source", l.Source())
|
||||
})
|
||||
|
@ -253,7 +253,7 @@ func TestLocation_Source(t *testing.T) {
|
|||
|
||||
func TestLocation_Place(t *testing.T) {
|
||||
t.Run("test-label", func(t *testing.T) {
|
||||
l := &Location{LocCategory: "test", LocCountry: "de", LocCity: "Nürnberg", LocLabel: "test-label", LocState: "Bayern", LocName: "Christkindlesmarkt"}
|
||||
l := NewLocation("", "Christkindlesmarkt", "", "test-label", "Nürnberg", "Bayern", "de", "")
|
||||
|
||||
assert.Equal(t, "test-label", l.Label())
|
||||
})
|
||||
|
@ -261,7 +261,7 @@ func TestLocation_Place(t *testing.T) {
|
|||
|
||||
func TestLocation_CountryCode(t *testing.T) {
|
||||
t.Run("de", func(t *testing.T) {
|
||||
l := &Location{LocCategory: "test", LocCountry: "de", LocCity: "Nürnberg", LocLabel: "test-label", LocState: "Bayern", LocName: "Christkindlesmarkt"}
|
||||
l := NewLocation("", "Christkindlesmarkt", "test", "test-label", "Nürnberg", "Bayern", "de", "")
|
||||
|
||||
assert.Equal(t, "de", l.CountryCode())
|
||||
})
|
||||
|
@ -269,8 +269,25 @@ func TestLocation_CountryCode(t *testing.T) {
|
|||
|
||||
func TestLocation_CountryName(t *testing.T) {
|
||||
t.Run("Germany", func(t *testing.T) {
|
||||
l := &Location{LocCategory: "test", LocCountry: "de", LocCity: "Nürnberg", LocLabel: "test-label", LocState: "Bayern", LocName: "Christkindlesmarkt"}
|
||||
l := NewLocation("", "Christkindlesmarkt", "test", "test-label", "Nürnberg", "Bayern", "de", "")
|
||||
|
||||
assert.Equal(t, "Germany", l.CountryName())
|
||||
})
|
||||
}
|
||||
|
||||
func TestLocation_QueryApi(t *testing.T) {
|
||||
l := NewLocation("3", "Christkindlesmarkt", "test", "test-label", "Nürnberg", "Bayern", "de", "")
|
||||
t.Run("xxx", func(t *testing.T) {
|
||||
api := l.QueryApi("xxx")
|
||||
assert.Error(t, api, "maps: reverse lookup disabled")
|
||||
})
|
||||
t.Run("osm", func(t *testing.T) {
|
||||
api := l.QueryApi("osm")
|
||||
assert.Error(t, api)
|
||||
})
|
||||
t.Run("places", func(t *testing.T) {
|
||||
api := l.QueryApi("places")
|
||||
assert.Error(t, api)
|
||||
})
|
||||
|
||||
}
|
||||
|
|
|
@ -23,6 +23,19 @@ type Location struct {
|
|||
|
||||
var ReverseLookupURL = "https://places.photoprism.org/v1/location/%s"
|
||||
|
||||
func NewLocation(id string, lat float64, lng float64, name string, category string, place Place, cached bool) *Location {
|
||||
result := &Location{
|
||||
ID: id,
|
||||
LocLat: lat,
|
||||
LocLng: lng,
|
||||
LocName: name,
|
||||
LocCategory: category,
|
||||
Place: place,
|
||||
Cached: cached,
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
func FindLocation(id string) (result Location, err error) {
|
||||
if len(id) > 16 || len(id) == 0 {
|
||||
return result, fmt.Errorf("places: invalid location id %s", id)
|
||||
|
|
|
@ -24,4 +24,48 @@ func TestFindLocation(t *testing.T) {
|
|||
assert.Equal(t, "Berlin", l.City())
|
||||
assert.Equal(t, "de", l.CountryCode())
|
||||
})
|
||||
t.Run("wrong id", func(t *testing.T) {
|
||||
l, err := FindLocation("2")
|
||||
assert.Error(t, err, "places: skipping lat 0.000000, lng 0.000000")
|
||||
t.Log(l)
|
||||
})
|
||||
t.Run("invalid id", func(t *testing.T) {
|
||||
l, err := FindLocation("")
|
||||
assert.Error(t, err, "places: invalid location id ")
|
||||
t.Log(l)
|
||||
})
|
||||
t.Run("cached true", func(t *testing.T) {
|
||||
var p = NewPlace("1", "", "", "", "de")
|
||||
location := NewLocation("54", 52.51961810676184, 13.40806264572578, "TestLocation", "test", p, true)
|
||||
l, err := FindLocation(location.ID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Equal(t, false, l.Cached)
|
||||
l2, err2 := FindLocation("54")
|
||||
|
||||
if err2 != nil {
|
||||
t.Fatal(err2)
|
||||
}
|
||||
assert.Equal(t, true, l2.Cached)
|
||||
})
|
||||
}
|
||||
|
||||
func TestLocationGetters(t *testing.T) {
|
||||
var p = NewPlace("1", "testLabel", "berlin", "berlin", "de")
|
||||
location := NewLocation("54", 52.51961810676184, 13.40806264572578, "TestLocation", "test", p, true)
|
||||
t.Run("wrong id", func(t *testing.T) {
|
||||
assert.Equal(t, "54", location.CellID())
|
||||
assert.Equal(t, "TestLocation", location.Name())
|
||||
assert.Equal(t, "test", location.Category())
|
||||
assert.Equal(t, "testLabel", location.Label())
|
||||
assert.Equal(t, "berlin", location.State())
|
||||
assert.Equal(t, "de", location.CountryCode())
|
||||
assert.Equal(t, "berlin", location.City())
|
||||
assert.Equal(t, 52.51961810676184, location.Latitude())
|
||||
assert.Equal(t, 13.40806264572578, location.Longitude())
|
||||
assert.Equal(t, "places", location.Source())
|
||||
assert.Equal(t, []string{"testlabel"}, location.Keywords())
|
||||
})
|
||||
|
||||
}
|
||||
|
|
|
@ -8,3 +8,15 @@ type Place struct {
|
|||
LocState string `json:"state"`
|
||||
LocCountry string `json:"country"`
|
||||
}
|
||||
|
||||
func NewPlace(id string, label string, city string, state string, country string) Place {
|
||||
result := Place{
|
||||
PlaceID: id,
|
||||
LocLabel: label,
|
||||
LocCity: city,
|
||||
LocState: state,
|
||||
LocCountry: country,
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
|
|
@ -7,27 +7,56 @@ import (
|
|||
)
|
||||
|
||||
func TestExif(t *testing.T) {
|
||||
data, err := Exif("testdata/photoshop.jpg")
|
||||
t.Run("jpg file with exif data", func(t *testing.T) {
|
||||
data, err := Exif("testdata/photoshop.jpg")
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.Equal(t, "Michael Mayer", data.Artist)
|
||||
assert.Equal(t, "2020-01-01T16:28:23Z", data.TakenAt.Format("2006-01-02T15:04:05Z"))
|
||||
assert.Equal(t, "2020-01-01T17:28:23Z", data.TakenAtLocal.Format("2006-01-02T15:04:05Z"))
|
||||
assert.Equal(t, "Example file for development", data.Description)
|
||||
assert.Equal(t, "This is a legal notice", data.Copyright)
|
||||
assert.Equal(t, 2736, data.Height)
|
||||
assert.Equal(t, 3648, data.Width)
|
||||
assert.Equal(t, 52.459690093888895, data.Lat)
|
||||
assert.Equal(t, 13.321831703055555, data.Lng)
|
||||
assert.Equal(t, 0, data.Altitude)
|
||||
assert.Equal(t, "HUAWEI", data.CameraMake)
|
||||
assert.Equal(t, "ELE-L29", data.CameraModel)
|
||||
assert.Equal(t, 27, data.FocalLength)
|
||||
assert.Equal(t, 1, int(data.Orientation))
|
||||
assert.Equal(t, "Michael Mayer", data.Artist)
|
||||
assert.Equal(t, "2020-01-01T16:28:23Z", data.TakenAt.Format("2006-01-02T15:04:05Z"))
|
||||
assert.Equal(t, "2020-01-01T17:28:23Z", data.TakenAtLocal.Format("2006-01-02T15:04:05Z"))
|
||||
assert.Equal(t, "Example file for development", data.Description)
|
||||
assert.Equal(t, "This is a legal notice", data.Copyright)
|
||||
assert.Equal(t, 2736, data.Height)
|
||||
assert.Equal(t, 3648, data.Width)
|
||||
assert.Equal(t, 52.459690093888895, data.Lat)
|
||||
assert.Equal(t, 13.321831703055555, data.Lng)
|
||||
assert.Equal(t, 0, data.Altitude)
|
||||
assert.Equal(t, "HUAWEI", data.CameraMake)
|
||||
assert.Equal(t, "ELE-L29", data.CameraModel)
|
||||
assert.Equal(t, 27, data.FocalLength)
|
||||
assert.Equal(t, 1, int(data.Orientation))
|
||||
|
||||
// TODO: Values are empty - why?
|
||||
// assert.Equal(t, "HUAWEI P30 Rear Main Camera", data.LensModel)
|
||||
// TODO: Values are empty - why?
|
||||
// assert.Equal(t, "HUAWEI P30 Rear Main Camera", data.LensModel)
|
||||
})
|
||||
|
||||
t.Run("png file without exif", func(t *testing.T) {
|
||||
_, err := Exif("testdata/tweethog.png")
|
||||
|
||||
assert.Error(t, err, "file does not have EXIF")
|
||||
// TODO: png with exif data
|
||||
})
|
||||
|
||||
t.Run("heic file with exif data", func(t *testing.T) {
|
||||
data, err := Exif("testdata/iphone_7.heic")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.Equal(t, "2018-09-10T03:16:13Z", data.TakenAt.Format("2006-01-02T15:04:05Z"))
|
||||
assert.Equal(t, "2018-09-10T12:16:13Z", data.TakenAtLocal.Format("2006-01-02T15:04:05Z"))
|
||||
assert.Equal(t, 34.79745, data.Lat)
|
||||
assert.Equal(t, 134.76463333333334, data.Lng)
|
||||
assert.Equal(t, 0, data.Altitude)
|
||||
assert.Equal(t, "Apple", data.CameraMake)
|
||||
assert.Equal(t, "iPhone 7", data.CameraModel)
|
||||
assert.Equal(t, 74, data.FocalLength)
|
||||
assert.Equal(t, 6, int(data.Orientation))
|
||||
assert.Equal(t, "Apple", data.LensMake)
|
||||
assert.Equal(t, "iPhone 7 back camera 3.99mm f/1.8", data.LensModel)
|
||||
|
||||
})
|
||||
}
|
||||
|
|
BIN
internal/meta/testdata/iphone_7.heic
vendored
Normal file
BIN
internal/meta/testdata/iphone_7.heic
vendored
Normal file
Binary file not shown.
BIN
internal/meta/testdata/tweethog.png
vendored
Normal file
BIN
internal/meta/testdata/tweethog.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 83 KiB |
Loading…
Reference in a new issue