-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(pypi): Dependency count shown in stack analysis report is incorrect
- Add unit test for pypi parser TODO: Similar exercise has to be repeated for npm and maven
- Loading branch information
1 parent
e30bc20
commit f42291c
Showing
7 changed files
with
170 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,5 @@ set -ex | |
install_dependencies | ||
|
||
build_project | ||
|
||
run_unit_tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--require ts-node/register | ||
--full-trace | ||
--bail | ||
test/**/*.test.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { expect } from 'chai'; | ||
import { ReqDependencyCollector } from '../src/collector'; | ||
|
||
describe('PyPi requirements.txt parser test', () => { | ||
const collector:ReqDependencyCollector = new ReqDependencyCollector(); | ||
|
||
it('tests valid requirements.txt', async () => { | ||
const deps = await collector.collect(`a==1 | ||
b==2.1.1 | ||
c>=10.1 | ||
d<=20.1.2.3.4.5.6.7.8 | ||
`); | ||
expect(deps.length).equal(4); | ||
expect(deps[0]).is.eql({ | ||
name: {value: 'a', position: {line: 0, column: 0}}, | ||
version: {value: '1', position: {line: 1, column: 4}} | ||
}); | ||
expect(deps[1]).is.eql({ | ||
name: {value: 'b', position: {line: 0, column: 0}}, | ||
version: {value: '2.1.1', position: {line: 2, column: 16}} | ||
}); | ||
expect(deps[2]).is.eql({ | ||
name: {value: 'c', position: {line: 0, column: 0}}, | ||
version: {value: '10.1', position: {line: 3, column: 16}} | ||
}); | ||
expect(deps[3]).is.eql({ | ||
name: {value: 'd', position: {line: 0, column: 0}}, | ||
version: {value: '20.1.2.3.4.5.6.7.8', position: {line: 4, column: 16}} | ||
}); | ||
}); | ||
|
||
it('tests requirements.txt with comments', async () => { | ||
const deps = await collector.collect(`# hello world | ||
a==1 # hello | ||
# another comment b==2.1.1 | ||
c # yet another comment >=10.1 | ||
d<=20.1.2.3.4.5.6.7.8 | ||
# done | ||
`); | ||
expect(deps.length).equal(3); | ||
expect(deps[0]).is.eql({ | ||
name: {value: 'a', position: {line: 0, column: 0}}, | ||
version: {value: '1', position: {line: 2, column: 16}} | ||
}); | ||
expect(deps[1]).is.eql({ | ||
name: {value: 'c', position: {line: 0, column: 0}}, | ||
version: {value: '', position: {line: 4, column: 1}} // column shouldn't matter for empty versions | ||
}); | ||
expect(deps[2]).is.eql({ | ||
name: {value: 'd', position: {line: 0, column: 0}}, | ||
version: {value: '20.1.2.3.4.5.6.7.8', position: {line: 5, column: 16}} | ||
}); | ||
}); | ||
|
||
it('tests empty lines', async () => { | ||
const deps = await collector.collect(` | ||
a==1 | ||
`); | ||
expect(deps.length).equal(1); | ||
expect(deps[0]).is.eql({ | ||
name: {value: 'a', position: {line: 0, column: 0}}, | ||
version: {value: '1', position: {line: 3, column: 16}} | ||
}); | ||
}); | ||
|
||
it('tests deps with spaces before and after comparators', async () => { | ||
const deps = await collector.collect(` | ||
a ==1 | ||
b <= 10.1 | ||
`); | ||
expect(deps.length).equal(2); | ||
expect(deps[0]).is.eql({ | ||
name: {value: 'a', position: {line: 0, column: 0}}, | ||
version: {value: '1', position: {line: 2, column: 24}} | ||
}); | ||
expect(deps[1]).is.eql({ | ||
name: {value: 'b', position: {line: 0, column: 0}}, | ||
version: {value: '10.1', position: {line: 4, column: 35}} | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES6", | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"sourceMap": true, | ||
"outDir": "output" | ||
}, | ||
"exclude": [ | ||
"node_modules" | ||
] | ||
} | ||
{ | ||
"compilerOptions": { | ||
"target": "ES6", | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"sourceMap": true, | ||
"outDir": "output" | ||
}, | ||
"exclude": [ | ||
"node_modules", | ||
"test" | ||
] | ||
} |