mirror of
https://github.com/safedep/vet.git
synced 2025-12-11 09:25:44 -06:00
feat: Building code graph Refactor to support import processing Handle relative import name fixup Add docs for code analysis framework Update docs to include additional examples feat: Function call graph Update code graph to link function decl and calls Include call node in function calls feat: Flatten vulnerabilities in CSV reporter refactor: Maintain separation of concerns for code analysis framework refactor: Separate storage entities in its own package feat: Add callback support in code graph builder docs: Fix code analysis framework docs Signed-off-by: abhisek <abhisek.datta@gmail.com>
57 lines
1.1 KiB
Go
57 lines
1.1 KiB
Go
package languages
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestResolveImportNameFromPath(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
path string
|
|
expected string
|
|
err error
|
|
}{
|
|
{
|
|
name: "Path is module",
|
|
path: "module.py",
|
|
expected: "module",
|
|
err: nil,
|
|
},
|
|
{
|
|
name: "Path is module with subdirectory",
|
|
path: "subdir/module.py",
|
|
expected: "subdir.module",
|
|
err: nil,
|
|
},
|
|
{
|
|
name: "Path is module with subdirectory and init",
|
|
path: "subdir/__init__.py",
|
|
expected: "subdir",
|
|
err: nil,
|
|
},
|
|
{
|
|
name: "Absolute path",
|
|
path: "/subdir/module.py",
|
|
expected: "",
|
|
err: fmt.Errorf("path is not relative: /subdir/module.py"),
|
|
},
|
|
}
|
|
|
|
l := &pythonSourceLanguage{}
|
|
for _, test := range cases {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
res, err := l.ResolveImportNameFromPath(test.path)
|
|
|
|
if test.err != nil {
|
|
assert.ErrorContains(t, err, test.err.Error())
|
|
} else {
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, test.expected, res)
|
|
}
|
|
})
|
|
}
|
|
}
|