pulumi/pkg/codegen/python/gen_test.go
Pat Gavlin d07b325138
[codegen] Add type name generation tests. (#7470)
The inputs and expected outputs for the tests are encoded using a
schema. Each property present in the schema forms a testcase; the
expected outputs for each language are stored in each property's
`Language` field with the language name "test". Expected outputs can be
regenerated using `PULUMI_ACCEPT`.
2021-07-09 10:23:10 -07:00

59 lines
1.3 KiB
Go

package python
import (
"testing"
"github.com/pulumi/pulumi/pkg/v3/codegen/internal/test"
"github.com/pulumi/pulumi/pkg/v3/codegen/schema"
"github.com/stretchr/testify/require"
)
var pathTests = []struct {
input string
expected string
}{
{".", "."},
{"", "."},
{"../", ".."},
{"../..", "..."},
{"../../..", "...."},
{"something", ".something"},
{"../parent", "..parent"},
{"../../module", "...module"},
}
func TestRelPathToRelImport(t *testing.T) {
for _, tt := range pathTests {
t.Run(tt.input, func(t *testing.T) {
result := relPathToRelImport(tt.input)
if result != tt.expected {
t.Errorf("expected \"%s\"; got \"%s\"", tt.expected, result)
}
})
}
}
func TestGeneratePackage(t *testing.T) {
test.TestSDKCodegen(t, "python", GeneratePackage)
}
func TestGenerateTypeNames(t *testing.T) {
test.TestTypeNameCodegen(t, "python", func(pkg *schema.Package) test.TypeNameGeneratorFunc {
// Decode python-specific info
err := pkg.ImportLanguages(map[string]schema.Language{"python": Importer})
require.NoError(t, err)
info, _ := pkg.Language["python"].(PackageInfo)
modules, err := generateModuleContextMap("test", pkg, info, nil)
require.NoError(t, err)
root, ok := modules[""]
require.True(t, ok)
return func(t schema.Type) string {
return root.typeString(t, false, false)
}
})
}