MCPcopy Index your code
hub / github.com/go-python/gopy / testPkgBackend

Function testPkgBackend

main_test.go:980–1092  ·  view source on GitHub ↗
(t *testing.T, pyvm string, table pkg)

Source from the content-addressed store, hash-verified

978}
979
980func testPkgBackend(t *testing.T, pyvm string, table pkg) {
981 curPkgPath := reflect.TypeOf(table).PkgPath()
982 _, pkgNm := filepath.Split(table.path)
983 cwd, _ := os.Getwd()
984 workdir, err := os.MkdirTemp("", "gopy-")
985 if err != nil {
986 t.Fatalf("[%s:%s]: could not create workdir: %v\n", pyvm, table.path, err)
987 }
988 genPkgDir := workdir
989 if table.outputdir != "" {
990 genPkgDir = filepath.Join(workdir, table.outputdir)
991 fmt.Printf("pyvm: %s making temp output dir: %s\n", pyvm, genPkgDir)
992 err = os.MkdirAll(genPkgDir, 0700)
993 if err != nil {
994 t.Fatalf("[%s:%s]: could not create temp output dir: %v\n", pyvm, table.path, err)
995 }
996 }
997 defer os.RemoveAll(workdir)
998 defer bind.ResetPackages()
999
1000 env := make([]string, len(testEnvironment))
1001 copy(env, testEnvironment)
1002 env = append(env, fmt.Sprintf("PYTHONPATH=%s", workdir))
1003
1004 writeGoMod(t, cwd, genPkgDir)
1005
1006 // fmt.Printf("building in work dir: %s\n", workdir)
1007 fpath := "./" + table.path
1008 if table.cmd != "build" { // non-build cases end up inside the working dir -- need a global import path
1009 fpath = filepath.Join(curPkgPath, table.path)
1010 }
1011 args := []string{table.cmd, "-vm=" + pyvm, "-output=" + genPkgDir, "-package-prefix", table.pkgprefix}
1012 if table.extras != nil {
1013 args = append(args, table.extras...)
1014 }
1015 args = append(args, fpath)
1016 fmt.Printf("run cmd: %s\n", args)
1017 err = run(args)
1018 if err != nil {
1019 t.Fatalf("[%s:%s]: error running gopy-build: %v\n", pyvm, table.path, err)
1020 }
1021
1022 // fmt.Printf("copying test.py\n")
1023 tstDir := genPkgDir
1024 if table.cmd != "build" {
1025 tstDir = filepath.Join(workdir, pkgNm)
1026 }
1027 if table.testdir != "" {
1028 tstDir = filepath.Join(workdir, table.testdir)
1029 }
1030 tstSrc := filepath.Join(filepath.Join(cwd, table.path), "test.py")
1031 tstDst := filepath.Join(tstDir, "test.py")
1032 err = copyCmd(tstSrc, tstDst)
1033 if err != nil {
1034 t.Fatalf("[%s:%s]: error copying 'test.py' from: %s to: %s: %v\n", pyvm, table.path, tstSrc, tstDst, err)
1035 }
1036
1037 fmt.Printf("running %s test.py\n", pyvm)

Callers 1

testPkgFunction · 0.85

Calls 7

ResetPackagesFunction · 0.92
writeGoModFunction · 0.85
runFunction · 0.85
copyCmdFunction · 0.85
PrintfMethod · 0.80
WriteMethod · 0.80
NameMethod · 0.45

Tested by

no test coverage detected