|
| 1 | +package modelsindex |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/arduino/go-paths-helper" |
| 7 | + "github.com/stretchr/testify/assert" |
| 8 | + "github.com/stretchr/testify/require" |
| 9 | +) |
| 10 | + |
| 11 | +func TestModelsIndex(t *testing.T) { |
| 12 | + modelsIndex, err := GenerateModelsIndexFromFile(paths.New("testdata")) |
| 13 | + require.NoError(t, err) |
| 14 | + require.NotNil(t, modelsIndex) |
| 15 | + |
| 16 | + t.Run("it parses a valid model-list.yaml", func(t *testing.T) { |
| 17 | + models := modelsIndex.GetModels() |
| 18 | + assert.Len(t, models, 2, "Expected 2 models to be parsed") |
| 19 | + }) |
| 20 | + |
| 21 | + t.Run("it gets a model by ID", func(t *testing.T) { |
| 22 | + model, found := modelsIndex.GetModelByID("not-existing-model") |
| 23 | + assert.False(t, found) |
| 24 | + assert.Nil(t, model) |
| 25 | + |
| 26 | + model, found = modelsIndex.GetModelByID("face-detection") |
| 27 | + assert.Equal(t, "brick", model.Runner) |
| 28 | + require.True(t, found, "face-detection should be found") |
| 29 | + assert.Equal(t, "face-detection", model.ID) |
| 30 | + assert.Equal(t, "Lightweight-Face-Detection", model.Name) |
| 31 | + assert.Equal(t, "Face bounding box detection. This model is trained on the WIDER FACE dataset and can detect faces in images.", model.ModuleDescription) |
| 32 | + assert.Equal(t, []string{"face"}, model.ModelLabels) |
| 33 | + assert.Equal(t, "/models/ootb/ei/lw-face-det.eim", model.ModelConfiguration["EI_OBJ_DETECTION_MODEL"]) |
| 34 | + assert.Equal(t, []string{"arduino:object_detection", "arduino:video_object_detection"}, model.Bricks) |
| 35 | + assert.Equal(t, "qualcomm-ai-hub", model.Metadata["source"]) |
| 36 | + assert.Equal(t, "false", model.Metadata["ei-gpu-mode"]) |
| 37 | + assert.Equal(t, "face-det-lite", model.Metadata["source-model-id"]) |
| 38 | + assert.Equal(t, "https://aihub.qualcomm.com/models/face_det_lite", model.Metadata["source-model-url"]) |
| 39 | + }) |
| 40 | + |
| 41 | + t.Run("it fails if model-list.yaml does not exist", func(t *testing.T) { |
| 42 | + nonExistentPath := paths.New("nonexistentdir") |
| 43 | + modelsIndex, err := GenerateModelsIndexFromFile(nonExistentPath) |
| 44 | + assert.Error(t, err) |
| 45 | + assert.Nil(t, modelsIndex) |
| 46 | + }) |
| 47 | + |
| 48 | + t.Run("it gets models by a brick", func(t *testing.T) { |
| 49 | + model := modelsIndex.GetModelsByBrick("not-existing-brick") |
| 50 | + assert.Nil(t, model) |
| 51 | + |
| 52 | + model = modelsIndex.GetModelsByBrick("arduino:object_detection") |
| 53 | + assert.Len(t, model, 1) |
| 54 | + assert.Equal(t, "face-detection", model[0].ID) |
| 55 | + }) |
| 56 | + |
| 57 | + t.Run("it gets models by bricks", func(t *testing.T) { |
| 58 | + models := modelsIndex.GetModelsByBricks([]string{"arduino:non_existing"}) |
| 59 | + assert.Len(t, models, 0) |
| 60 | + assert.Nil(t, models) |
| 61 | + |
| 62 | + models = modelsIndex.GetModelsByBricks([]string{"arduino:video_object_detection"}) |
| 63 | + assert.Len(t, models, 2) |
| 64 | + assert.Equal(t, "face-detection", models[0].ID) |
| 65 | + assert.Equal(t, "yolox-object-detection", models[1].ID) |
| 66 | + |
| 67 | + models = modelsIndex.GetModelsByBricks([]string{"arduino:object_detection", "arduino:video_object_detection"}) |
| 68 | + assert.Len(t, models, 2) |
| 69 | + assert.Equal(t, "face-detection", models[0].ID) |
| 70 | + assert.Equal(t, "yolox-object-detection", models[1].ID) |
| 71 | + }) |
| 72 | +} |
0 commit comments