-
Notifications
You must be signed in to change notification settings - Fork 573
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: [OSM-2368] more robust test case for python acceptance tests
- Loading branch information
Showing
12 changed files
with
142 additions
and
3 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
2 changes: 2 additions & 0 deletions
2
test/acceptance/workspaces/pip-app-linux-arm64/module/requirements.txt
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,2 @@ | ||
pandas @ https://files.pythonhosted.org/packages/c6/2a/4bba3f03f7d07207481fed47f5b35f556c7441acddc368ec43d6643c5777/pandas-2.2.3-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl ; python_version=="3.12" | ||
pandas @ https://files.pythonhosted.org/packages/f5/94/6c79b07f0e5aab1dcfa35a75f4817f5c4f677931d4234afcd75f0e6a66ca/pandas-2.2.3-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl ; python_version=="3.13" |
1 change: 1 addition & 0 deletions
1
test/acceptance/workspaces/pip-app-linux-arm64/requirements.txt
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 @@ | ||
-r ./module/requirements.txt |
2 changes: 2 additions & 0 deletions
2
test/acceptance/workspaces/pip-app-macos/module/requirements.txt
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,2 @@ | ||
pandas @ https://files.pythonhosted.org/packages/e1/0c/ad295fd74bfac85358fd579e271cded3ac969de81f62dd0142c426b9da91/pandas-2.2.3-cp312-cp312-macosx_11_0_arm64.whl ; python_version=="3.12" | ||
pandas @ https://files.pythonhosted.org/packages/e4/93/b3f5d1838500e22c8d793625da672f3eec046b1a99257666c94446969282/pandas-2.2.3-cp313-cp313-macosx_11_0_arm64.whl ; python_version=="3.13" |
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 @@ | ||
-r ./module/requirements.txt |
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 @@ | ||
requests==2.31.0 |
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 @@ | ||
oauth2==1.1.3 |
11 changes: 11 additions & 0 deletions
11
test/acceptance/workspaces/pip-app-robust/requirements.txt
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,11 @@ | ||
--trusted-host pypi.fury.io | ||
|
||
Jinja2==2.7.2 | ||
git+https://github.com/snyk-fixtures/[email protected]#egg=simple==v1.0.0 | ||
-e git+https://github.com/snyk-fixtures/python-pypi-package-sample-subdir#egg=sample&subdirectory=subdir | ||
https://files.pythonhosted.org/packages/d0/d7/4806fd165c27716f02a3a9c23d207854b8a3ed884db53c2781b92bd8d4f4/whl.setup-0.2-py2.py3-none-any.whl | ||
requests; python_version >= "3.8.dev0" | ||
pydantic[email]==1.9.0 | ||
djangorestframework @ git+https://github.com/encode/django-rest-framework.git@1db19f4b2d1500894448634852e02f73043382e4 | ||
-r req.txt | ||
-c constraints.txt |
4 changes: 4 additions & 0 deletions
4
test/acceptance/workspaces/pip-app-windows/module/requirements.txt
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 @@ | ||
pandas @ https://files.pythonhosted.org/packages/52/11/9eac327a38834f162b8250aab32a6781339c69afe7574368fffe46387edf/pandas-2.2.3-cp311-cp311-macosx_11_0_arm64.whl ; python_version=="3.12" | ||
pandas @ https://files.pythonhosted.org/packages/3b/bc/4b18e2b8c002572c5a441a64826252ce5da2aa738855747247a971988043/pandas-2.2.3-cp313-cp313-win_amd64.whl ; python_version=="3.13" | ||
|
||
git commit -m "test: [OSM-2368] python acceptance tests specific to windows" |
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,2 @@ | ||
pywin32; sys_platform == 'win32' | ||
-r module\requirements.txt |
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
107 changes: 107 additions & 0 deletions
107
test/jest/acceptance/snyk-test/test-python-os-specific.spec.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,107 @@ | ||
import { createProjectFromWorkspace } from '../../util/createProject'; | ||
import { runSnykCLI } from '../../util/runSnykCLI'; | ||
import { fakeServer } from '../../../acceptance/fake-server'; | ||
import { runCommand } from '../../util/runCommand'; | ||
import { isDontSkipTestsEnabled } from '../../util/isDontSkipTestsEnabled'; | ||
import { getServerPort } from '../../util/getServerPort'; | ||
import * as os from 'os'; | ||
|
||
jest.setTimeout(1000 * 60); | ||
|
||
const PLATFORM_FIXTURES_MAPS = { | ||
win32_amd64: 'pip-app-windows', | ||
darwin_arm64: 'pip-app-macos', | ||
linux_arm64: 'pip-app-linux-arm64', | ||
// linux_amd64: 'pip-app-linux-amd64', | ||
// alpine_amd64: 'pip-app-alpine-amd64', | ||
// alpine_arm64: 'pip-app-alpine-arm64', | ||
}; | ||
|
||
describe('`snyk test` of python projects with OS specific dependencies', () => { | ||
let server; | ||
let env: Record<string, string>; | ||
let dontSkip: boolean; | ||
|
||
beforeAll((done) => { | ||
const port = getServerPort(process); | ||
const baseApi = '/api/v1'; | ||
env = { | ||
...process.env, | ||
SNYK_API: 'http://localhost:' + port + baseApi, | ||
SNYK_HOST: 'http://localhost:' + port, | ||
SNYK_TOKEN: '123456789', | ||
SNYK_DISABLE_ANALYTICS: '1', | ||
}; | ||
server = fakeServer(baseApi, env.SNYK_TOKEN); | ||
server.listen(port, () => { | ||
done(); | ||
}); | ||
dontSkip = isDontSkipTestsEnabled(); | ||
console.debug("Don't skip tests: " + dontSkip); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.resetAllMocks(); | ||
server.restore(); | ||
}); | ||
|
||
afterAll((done) => { | ||
server.close(() => { | ||
done(); | ||
}); | ||
}); | ||
|
||
test('run `snyk test` on python project $fixture on the corresponding platform', async () => { | ||
const currentPlatform = os.platform() + '_' + os.arch(); | ||
|
||
if (!(currentPlatform in PLATFORM_FIXTURES_MAPS)) { | ||
return; | ||
} | ||
|
||
const fixture = PLATFORM_FIXTURES_MAPS[currentPlatform]; | ||
|
||
const project = await createProjectFromWorkspace(fixture); | ||
let pythonCommand = 'python'; | ||
|
||
await runCommand(pythonCommand, ['--version']).catch(function () { | ||
pythonCommand = 'python3'; | ||
}); | ||
|
||
console.debug('Using: ' + pythonCommand); | ||
let pipResult = await runCommand( | ||
pythonCommand, | ||
[ | ||
'-m', | ||
'pip', | ||
'install', | ||
'-r', | ||
'requirements.txt', | ||
'--break-system-packages', | ||
], | ||
{ | ||
shell: true, | ||
cwd: project.path(), | ||
}, | ||
); | ||
|
||
if (pipResult && pipResult.code != 0) { | ||
pipResult = await runCommand( | ||
pythonCommand, | ||
['-m', 'pip', 'install', '-r', 'requirements.txt'], | ||
{ | ||
shell: true, | ||
cwd: project.path(), | ||
}, | ||
); | ||
} | ||
|
||
expect(pipResult.code).toEqual(0); | ||
|
||
const { code } = await runSnykCLI('test -d --command=' + pythonCommand, { | ||
cwd: project.path(), | ||
env, | ||
}); | ||
|
||
expect(code).toEqual(0); | ||
}); | ||
}); |