Skip to content

Commit 6549d2a

Browse files
authored
chore: fix requirements.txt parser init & re-enable python tests (#404)
1 parent 0e9ba23 commit 6549d2a

File tree

2 files changed

+47
-51
lines changed

2 files changed

+47
-51
lines changed

src/providers/requirements_parser.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ import { Language, Parser, Query } from 'web-tree-sitter';
55
const require = createRequire(import.meta.url);
66

77
async function init() {
8-
await Parser.init({
9-
locateFile() {
10-
return require.resolve('web-tree-sitter/web-tree-sitter.wasm')
11-
}
12-
});
8+
await Parser.init();
139
return await Language.load(require.resolve('tree-sitter-requirements/tree-sitter-requirements.wasm'));
1410
}
1511

test/providers/python_pip.test.js

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ async function sharedComponentAnalysisTestFlow(testCase, usePipDepTreeUtility) {
1313
let expectedSbom = fs.readFileSync(`test/providers/tst_manifests/pip/${testCase}/expected_component_sbom.json`).toString().trim()
1414
expectedSbom = JSON.stringify(JSON.parse(expectedSbom))
1515
// invoke sut stack analysis for scenario manifest
16-
let opts = { "TRUSTIFY_DA_PIP_USE_DEP_TREE" : usePipDepTreeUtility }
16+
let opts = { TRUSTIFY_DA_PIP_USE_DEP_TREE: usePipDepTreeUtility.toString() }
1717
let providedDatForComponent = await pythonPip.provideComponent(`test/providers/tst_manifests/pip/${testCase}/requirements.txt`, opts)
1818
// verify returned data matches expectation
1919
expect(providedDatForComponent).to.deep.equal({
@@ -34,7 +34,7 @@ async function sharedStackAnalysisTestFlow(testCase, usePipDepTreeUtility) {
3434
} catch (error) {
3535
throw new Error('fail installing requirements.txt manifest in created virtual python environment', {cause: error})
3636
}
37-
let opts = { "TRUSTIFY_DA_PIP_USE_DEP_TREE" : usePipDepTreeUtility }
37+
let opts = { TRUSTIFY_DA_PIP_USE_DEP_TREE: usePipDepTreeUtility.toString() }
3838
let providedDataForStack = await pythonPip.provideStack(`test/providers/tst_manifests/pip/${testCase}/requirements.txt`, opts)
3939
// new(year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number): Date
4040

@@ -48,14 +48,14 @@ async function sharedStackAnalysisTestFlow(testCase, usePipDepTreeUtility) {
4848
}
4949

5050
suite('testing the python-pip data provider', () => {
51-
// [
52-
// {name: 'requirements.txt', expected: true},
53-
// {name: 'some_other.file', expected: false}
54-
// ].forEach(testCase => {
55-
// test(`verify isSupported returns ${testCase.expected} for ${testCase.name}`, () =>
56-
// expect(pythonPip.isSupported(testCase.name)).to.equal(testCase.expected)
57-
// )
58-
// });
51+
[
52+
{name: 'requirements.txt', expected: true},
53+
{name: 'some_other.file', expected: false}
54+
].forEach(testCase => {
55+
test(`verify isSupported returns ${testCase.expected} for ${testCase.name}`, () =>
56+
expect(pythonPip.isSupported(testCase.name)).to.equal(testCase.expected)
57+
)
58+
});
5959

6060
[
6161
// "pip_requirements_txt_no_ignore",
@@ -72,46 +72,46 @@ suite('testing the python-pip data provider', () => {
7272
// these test cases takes ~1400-2000 ms each pr >10000 in CI (for the first test-case)
7373
}).timeout(process.env.GITHUB_ACTIONS ? 15000 : 10000)
7474

75-
// test(`verify requirements.txt sbom provided for stack analysis using pipdeptree utility with scenario ${scenario}`, () => {
76-
// sharedStackAnalysisTestFlow(testCase, true);
77-
// // these test cases takes ~2500-2700 ms each pr >10000 in CI (for the first test-case)
78-
// }).timeout(process.env.GITHUB_ACTIONS ? 30000 : 10000)
75+
test(`verify requirements.txt sbom provided for stack analysis using pipdeptree utility with scenario ${scenario}`, async () => {
76+
await sharedStackAnalysisTestFlow(testCase, true);
77+
// these test cases takes ~2500-2700 ms each pr >10000 in CI (for the first test-case)
78+
}).timeout(process.env.GITHUB_ACTIONS ? 30000 : 10000)
7979

80-
// test(`verify requirements.txt sbom provided for component analysis using pipdeptree utility with scenario ${scenario}`, () => {
81-
// sharedComponentAnalysisTestFlow(testCase, true);
82-
// // these test cases takes ~1400-2000 ms each pr >10000 in CI (for the first test-case)
83-
// }).timeout(process.env.GITHUB_ACTIONS ? 15000 : 10000)
80+
test(`verify requirements.txt sbom provided for component analysis using pipdeptree utility with scenario ${scenario}`, async () => {
81+
await sharedComponentAnalysisTestFlow(testCase, true);
82+
// these test cases takes ~1400-2000 ms each pr >10000 in CI (for the first test-case)
83+
}).timeout(process.env.GITHUB_ACTIONS ? 15000 : 10000)
8484
});
8585

8686
}).beforeAll(() => clock = useFakeTimers(new Date('2023-10-01T00:00:00.000Z'))).afterAll(()=> clock.restore());
8787

88-
// suite('testing the python-pip data provider with virtual environment', () => {
89-
// [
90-
// "pip_requirements_virtual_env_txt_no_ignore",
91-
// "pip_requirements_virtual_env_with_ignore"
92-
// ].forEach(testCase => {
93-
// let scenario = testCase.replace('pip_requirements_', '').replaceAll('_', ' ')
94-
// test(`verify requirements.txt sbom provided for stack analysis using virutal python environment, with scenario ${scenario}`, async () => {
95-
// // load the expected sbom stack analysis
96-
// let expectedSbom = fs.readFileSync(`test/providers/tst_manifests/pip/${testCase}/expected_stack_sbom.json`,).toString()
97-
// process.env["TRUSTIFY_DA_PYTHON_VIRTUAL_ENV"] = "true"
98-
// // process.env["TRUSTIFY_DA_DEBUG"] = "true"
99-
// expectedSbom = JSON.stringify(JSON.parse(expectedSbom), null, 4)
100-
// // invoke sut stack analysis for scenario manifest
101-
// let providedDataForStack = await pythonPip.provideStack(`test/providers/tst_manifests/pip/${testCase}/requirements.txt`)
102-
// // new(year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number): Date
88+
suite('testing the python-pip data provider with virtual environment', () => {
89+
[
90+
"pip_requirements_virtual_env_txt_no_ignore",
91+
"pip_requirements_virtual_env_with_ignore"
92+
].forEach(testCase => {
93+
let scenario = testCase.replace('pip_requirements_', '').replaceAll('_', ' ')
94+
test(`verify requirements.txt sbom provided for stack analysis using virutal python environment, with scenario ${scenario}`, async () => {
95+
// load the expected sbom stack analysis
96+
let expectedSbom = fs.readFileSync(`test/providers/tst_manifests/pip/${testCase}/expected_stack_sbom.json`,).toString()
97+
expectedSbom = JSON.stringify(JSON.parse(expectedSbom), null, 4)
98+
// invoke sut stack analysis for scenario manifest
99+
let providedDataForStack = await pythonPip.provideStack(`test/providers/tst_manifests/pip/${testCase}/requirements.txt`, {
100+
TRUSTIFY_DA_PYTHON_VIRTUAL_ENV: "true"
101+
})
102+
// new(year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number): Date
103103

104-
// // providedDataForStack.content = providedDataForStack.content.replaceAll("\"timestamp\":\"[a-zA-Z0-9\\-\\:]+\"","")
105-
// // verify returned data matches expectation
106-
// providedDataForStack.content = JSON.stringify(JSON.parse(providedDataForStack.content), null, 4)
107-
// expect(providedDataForStack.content).to.deep.equal(expectedSbom)
108-
// // expect(providedDataForStack).to.deep.equal({
109-
// // ecosystem: 'pip',
110-
// // contentType: 'application/vnd.cyclonedx+json',
111-
// // content: expectedSbom
112-
// // })
113-
// // these test cases takes ~2500-2700 ms each pr >10000 in CI (for the first test-case)
114-
// }).timeout(process.env.GITHUB_ACTIONS ? 60000 : 30000)
115-
// })
104+
// providedDataForStack.content = providedDataForStack.content.replaceAll("\"timestamp\":\"[a-zA-Z0-9\\-\\:]+\"","")
105+
// verify returned data matches expectation
106+
providedDataForStack.content = JSON.stringify(JSON.parse(providedDataForStack.content), null, 4)
107+
expect(providedDataForStack.content).to.deep.equal(expectedSbom)
108+
// expect(providedDataForStack).to.deep.equal({
109+
// ecosystem: 'pip',
110+
// contentType: 'application/vnd.cyclonedx+json',
111+
// content: expectedSbom
112+
// })
113+
// these test cases takes ~2500-2700 ms each pr >10000 in CI (for the first test-case)
114+
}).timeout(process.env.GITHUB_ACTIONS ? 60000 : 30000)
115+
})
116116

117-
// }).beforeAll(() => {clock = useFakeTimers(new Date('2023-10-01T00:00:00.000Z'))}).afterAll(()=> clock.restore());
117+
}).beforeAll(() => {clock = useFakeTimers(new Date('2023-10-01T00:00:00.000Z'))}).afterAll(()=> clock.restore());

0 commit comments

Comments
 (0)