Skip to content

Commit

Permalink
fixed code generation for not downloaded models (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
RayanMarmar authored Apr 19, 2024
1 parent eb90476 commit f0628be
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
10 changes: 9 additions & 1 deletion internal/model/generation.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ func (m *Model) GenFile() *codegen.File {
}
}

// GenModelPath returns the model path to be used in the code generation
func (m *Model) GenModelPath() string {
if m.IsDownloaded {
return m.Path
}
return m.Name
}

// GenImports generate the imports for the given model
func (m *Model) GenImports() []codegen.Import {
return []codegen.Import{
Expand Down Expand Up @@ -146,7 +154,7 @@ func (m *Model) GenSuperInitParamsWithModule() []codegen.FunctionCallParameter {
},
{
Name: "model_path",
Value: "\"" + m.Path + "\"",
Value: "\"" + m.GenModelPath() + "\"",
},
{
Name: "model_class",
Expand Down
22 changes: 22 additions & 0 deletions internal/model/generation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,25 @@ func TestModel_GenFile_SingleFile(t *testing.T) {
test.AssertEqual(t, len(file.Classes), 1, "The file should contain one class.")
test.AssertEqual(t, len(file.HeaderComments), 2, "The file should contain two header comments.")
}

func TestGenModelPath_DownloadedModel(t *testing.T) {
// Init
m := Model{Name: "name", Path: "path", IsDownloaded: false}

// Get model path
path := m.GenModelPath()

// Assert
test.AssertEqual(t, path, "name", "The returned path name should be equal to model name.")
}

func TestGenModelPath_NotDownloadedModel(t *testing.T) {
// Init
m := Model{Name: "name", Path: "path", IsDownloaded: true}

// Get model path
path := m.GenModelPath()

// Assert
test.AssertEqual(t, path, "path", "The returned path name should be equal to model path.")
}

0 comments on commit f0628be

Please sign in to comment.