mirror of
https://github.com/safedep/vet.git
synced 2025-12-10 13:43:01 -06:00
Added new test cases scenarios
This commit is contained in:
parent
d1c6a84fc0
commit
3fb8e9b5fd
35
pkg/parser/custom/py/fixtures/setuppy/setup2_parser1.py
Normal file
35
pkg/parser/custom/py/fixtures/setuppy/setup2_parser1.py
Normal file
@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env python
|
||||
# import pytest
|
||||
import re
|
||||
import sys
|
||||
import os
|
||||
from setuptools import setup, find_packages
|
||||
from setuptools.command.test import test as TestCommand
|
||||
|
||||
rootdir = os.path.abspath(os.path.dirname(__file__))
|
||||
name = open(os.path.join(rootdir, 'NAME')).read().strip()
|
||||
version = open(os.path.join(rootdir, 'VERSION')).read().strip()
|
||||
#long_description = open(os.path.join(rootdir, 'README.md')).read()
|
||||
long_description = "food Integrations"
|
||||
|
||||
setup(
|
||||
name=name,
|
||||
packages=find_packages(),
|
||||
version=version,
|
||||
description=long_description,
|
||||
long_description=long_description,
|
||||
author='Jitendra Chauhan',
|
||||
author_email='jitendra.chauhan@xxxxx.com',
|
||||
url="",
|
||||
include_package_data=True,
|
||||
# python_requires='>=2.7,>=3.5,<4.0',
|
||||
install_requires=[
|
||||
"google-cloud-storage",
|
||||
"google-cloud-pubsub>=2.0",
|
||||
"knowledge-graph==3.12.0",
|
||||
"statistics"
|
||||
],
|
||||
setup_requires=[],
|
||||
tests_require=["mock"],
|
||||
# cmdclass={'test': PyTest},
|
||||
)
|
||||
@ -1,6 +1,7 @@
|
||||
package py_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"github.com/safedep/vet/pkg/parser/custom/py"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@ -80,3 +81,72 @@ func TestParseRequirementsFileLine(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
func TestParseSetuppy(t *testing.T) {
|
||||
tests := []struct {
|
||||
filepath string
|
||||
expectedDeps []lockfile.PackageDetails
|
||||
}{
|
||||
{
|
||||
filepath: "./fixtures/setuppy/setup2_parser1.py", // Path to your test file
|
||||
expectedDeps: []lockfile.PackageDetails{
|
||||
{
|
||||
Name: "google-cloud-storage",
|
||||
Version: "0.0.0",
|
||||
Ecosystem: lockfile.PipEcosystem,
|
||||
CompareAs: lockfile.PipEcosystem,
|
||||
},
|
||||
{
|
||||
Name: "google-cloud-pubsub",
|
||||
Version: "2.0",
|
||||
Ecosystem: lockfile.PipEcosystem,
|
||||
CompareAs: lockfile.PipEcosystem,
|
||||
},
|
||||
{
|
||||
Name: "knowledge-graph",
|
||||
Version: "3.12.0",
|
||||
Ecosystem: lockfile.PipEcosystem,
|
||||
CompareAs: lockfile.PipEcosystem,
|
||||
},
|
||||
{
|
||||
Name: "statistics",
|
||||
Version: "0.0.0",
|
||||
Ecosystem: lockfile.PipEcosystem,
|
||||
CompareAs: lockfile.PipEcosystem,
|
||||
},
|
||||
},
|
||||
},
|
||||
// Add more test cases here
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.filepath, func(t *testing.T) {
|
||||
dependencies, err := py.ParseSetuppy(test.filepath)
|
||||
assert.Nil(t, err)
|
||||
|
||||
if len(dependencies) != len(test.expectedDeps) {
|
||||
// fmt.Println(dependencies)
|
||||
// fmt.Println(test.expectedDeps)
|
||||
// fmt.Println(Difference(dependencies, test.expectedDeps))
|
||||
// fmt.Println(Difference(test.expectedDeps, dependencies))
|
||||
t.Fatalf("Expected %d dependencies, but got %d", len(test.expectedDeps), len(dependencies))
|
||||
}
|
||||
|
||||
dep_map := make(map[string]lockfile.PackageDetails, 0)
|
||||
for _, v := range test.expectedDeps {
|
||||
dep_map[v.Name] = v
|
||||
}
|
||||
|
||||
for _, v := range dependencies {
|
||||
ev, ok := dep_map[v.Name]
|
||||
assert.True(t, ok, fmt.Sprintf("Package %s not found in expected result", v.Name))
|
||||
assert.Equal(t, ev.Name, v.Name, fmt.Sprintf("Mismatch for the package: %s", v.Name))
|
||||
assert.Equal(t, ev.Version, v.Version, fmt.Sprintf("Mismatch for the package: %s", v.Name))
|
||||
assert.Equal(t, ev.Ecosystem, v.Ecosystem, fmt.Sprintf("Mismatch for the package: %s", v.Name))
|
||||
assert.Equal(t, ev.CompareAs, v.CompareAs, fmt.Sprintf("Mismatch for the package: %s", v.Name))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user