Skip to content

Commit

Permalink
test: [OSM-2368] more robust test case for python acceptance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gemaxim committed Jan 13, 2025
1 parent 5c1155e commit e015d24
Show file tree
Hide file tree
Showing 16 changed files with 171 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .circleci/chocolatey.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<package id="maven" version="3.8.2" />
<package id="make" version="4.4.1" />
<package id="gradle" version="8.1.1" />
<package id="python3" version="3.11.4" />
<package id="python3" version="3.12.8" />
<package id="dotnet-sdk" version="8.0.100" />
</packages>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pandas @ https://files.pythonhosted.org/packages/ee/7c/c6dbdb0cb2a4344cacfb8de1c5808ca885b2e4dcfde8008266608f9372af/pandas-2.2.3-cp313-cp313-musllinux_1_2_aarch64.whl ; python_version=="3.13"
pandas @ https://files.pythonhosted.org/packages/20/e8/45a05d9c39d2cea61ab175dbe6a2de1d05b679e8de2011da4ee190d7e748/pandas-2.2.3-cp312-cp312-musllinux_1_2_aarch64.whl ; python_version=="3.12"
pandas @ https://files.pythonhosted.org/packages/b9/57/708135b90391995361636634df1f1130d03ba456e95bcf576fada459115a/pandas-2.2.3-cp311-cp311-musllinux_1_2_aarch64.whl ; python_version=="3.11"
pandas @ https://files.pythonhosted.org/packages/61/61/a89015a6d5536cb0d6c3ba02cebed51a95538cf83472975275e28ebf7d0c/pandas-2.2.3-cp310-cp310-musllinux_1_2_aarch64.whl ; python_version=="3.10"
pandas @ https://files.pythonhosted.org/packages/31/a3/18508e10a31ea108d746c848b5a05c0711e0278fa0d6f1c52a8ec52b80a5/pandas-2.2.3-cp39-cp39-musllinux_1_2_aarch64.whl ; python_version=="3.9"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-r ./module/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pandas @ https://files.pythonhosted.org/packages/e8/31/aa8da88ca0eadbabd0a639788a6da13bb2ff6edbbb9f29aa786450a30a91/pandas-2.2.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl ; python_version=="3.13"
pandas @ https://files.pythonhosted.org/packages/38/f8/d8fddee9ed0d0c0f4a2132c1dfcf0e3e53265055da8df952a53e7eaf178c/pandas-2.2.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl ; python_version=="3.12"
pandas @ https://files.pythonhosted.org/packages/cd/5f/4dba1d39bb9c38d574a9a22548c540177f78ea47b32f99c0ff2ec499fac5/pandas-2.2.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl ; python_version=="3.11"
pandas @ https://files.pythonhosted.org/packages/44/50/7db2cd5e6373ae796f0ddad3675268c8d59fb6076e66f0c339d61cea886b/pandas-2.2.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl ; python_version=="3.10"
pandas @ https://files.pythonhosted.org/packages/3d/dd/bed19c2974296661493d7acc4407b1d2db4e2a482197df100f8f965b6225/pandas-2.2.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl ; python_version=="3.9"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-r ./module/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
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"
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/45/fb/c4beeb084718598ba19aa9f5abbc8aed8b42f90930da861fcb1acdb54c3a/pandas-2.2.3-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.whl ; python_version=="3.11"
pandas @ https://files.pythonhosted.org/packages/ed/12/86c1747ea27989d7a4064f806ce2bae2c6d575b950be087837bdfcabacc9/pandas-2.2.3-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.whl ; python_version=="3.10"
pandas @ https://files.pythonhosted.org/packages/31/af/89e35619fb573366fa68dc26dad6ad2c08c17b8004aad6d98f1a31ce4bb3/pandas-2.2.3-cp39-cp39-manylinux2014_aarch64.manylinux_2_17_aarch64.whl ; python_version=="3.9"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-r ./module/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pandas @ https://files.pythonhosted.org/packages/e4/93/b3f5d1838500e22c8d793625da672f3eec046b1a99257666c94446969282/pandas-2.2.3-cp313-cp313-macosx_11_0_arm64.whl ; python_version=="3.13"
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/52/11/9eac327a38834f162b8250aab32a6781339c69afe7574368fffe46387edf/pandas-2.2.3-cp311-cp311-macosx_11_0_arm64.whl ; python_version=="3.11"
pandas @ https://files.pythonhosted.org/packages/99/f2/c4527768739ffa4469b2b4fff05aa3768a478aed89a2f271a79a40eee984/pandas-2.2.3-cp310-cp310-macosx_11_0_arm64.whl ; python_version=="3.10"
pandas @ https://files.pythonhosted.org/packages/9c/b9/5cead4f63b6d31bdefeb21a679bc5a7f4aaf262ca7e07e2bc1c341b68470/pandas-2.2.3-cp39-cp39-macosx_11_0_arm64.whl ; python_version=="3.9"
1 change: 1 addition & 0 deletions test/acceptance/workspaces/pip-app-macos/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-r ./module/requirements.txt
1 change: 1 addition & 0 deletions test/acceptance/workspaces/pip-app-robust/constraints.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requests==2.31.0
1 change: 1 addition & 0 deletions test/acceptance/workspaces/pip-app-robust/req.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oauth2==1.1.3
11 changes: 11 additions & 0 deletions test/acceptance/workspaces/pip-app-robust/requirements.txt
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
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"
2 changes: 2 additions & 0 deletions test/acceptance/workspaces/pip-app-windows/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pywin32; sys_platform == 'win32'
-r module\requirements.txt
11 changes: 9 additions & 2 deletions test/jest/acceptance/snyk-test/basic-test-all-languages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,15 @@ describe('`snyk test` of basic projects for each language/ecosystem', () => {
expect(code).toEqual(0);
});

test('run `snyk test` on a python project', async () => {
const project = await createProjectFromWorkspace('pip-app');
test.each([
{
fixture: 'pip-app',
},
{
fixture: 'pip-app-robust',
},
])('run `snyk test` on a python project $fixture', async ({ fixture }) => {
const project = await createProjectFromWorkspace(fixture);
let pythonCommand = 'python';

await runCommand(pythonCommand, ['--version']).catch(function () {
Expand Down
120 changes: 120 additions & 0 deletions test/jest/acceptance/snyk-test/test-python-os-specific.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
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';
import * as fs from 'fs';

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_arm64: 'pip-app-alpine-arm64',
};

function getCurrentPlatform(): string {
const ALPINE_RELEASE_PATH = '/etc/alpine-release';
const currentPlatform = os.platform() + '_' + os.arch();

if (currentPlatform == 'linux_arm64') {
if (fs.existsSync(ALPINE_RELEASE_PATH) || process.env.OSTYPE === 'alpine') {
return 'alpine_arm64';
}
}

return currentPlatform;
}

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 = getCurrentPlatform();

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);
});
});

0 comments on commit e015d24

Please sign in to comment.