From 2f6d816a83312bddc9493637b65f4ccd75e96d55 Mon Sep 17 00:00:00 2001 From: yongjunhong Date: Fri, 13 Sep 2024 12:20:46 +0900 Subject: [PATCH 01/17] create test files Signed-off-by: yongjunhong --- tests/pytest/package_manager/__init__.py | 0 tests/pytest/package_manager/test_android.py | 0 tests/pytest/package_manager/test_carthage.py | 0 tests/pytest/package_manager/test_cocoapods.py | 0 tests/pytest/package_manager/test_go.py | 0 tests/pytest/package_manager/test_gradle.py | 0 tests/pytest/package_manager/test_helm.py | 0 tests/pytest/package_manager/test_maven.py | 0 tests/pytest/package_manager/test_npm.py | 0 tests/pytest/package_manager/test_nuget.py | 0 tests/pytest/package_manager/test_pub.py | 0 tests/pytest/package_manager/test_pypi.py | 0 tests/pytest/package_manager/test_swift.py | 0 tests/pytest/package_manager/test_unity.py | 0 14 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/pytest/package_manager/__init__.py create mode 100644 tests/pytest/package_manager/test_android.py create mode 100644 tests/pytest/package_manager/test_carthage.py create mode 100644 tests/pytest/package_manager/test_cocoapods.py create mode 100644 tests/pytest/package_manager/test_go.py create mode 100644 tests/pytest/package_manager/test_gradle.py create mode 100644 tests/pytest/package_manager/test_helm.py create mode 100644 tests/pytest/package_manager/test_maven.py create mode 100644 tests/pytest/package_manager/test_npm.py create mode 100644 tests/pytest/package_manager/test_nuget.py create mode 100644 tests/pytest/package_manager/test_pub.py create mode 100644 tests/pytest/package_manager/test_pypi.py create mode 100644 tests/pytest/package_manager/test_swift.py create mode 100644 tests/pytest/package_manager/test_unity.py diff --git a/tests/pytest/package_manager/__init__.py b/tests/pytest/package_manager/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/pytest/package_manager/test_android.py b/tests/pytest/package_manager/test_android.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/pytest/package_manager/test_carthage.py b/tests/pytest/package_manager/test_carthage.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/pytest/package_manager/test_cocoapods.py b/tests/pytest/package_manager/test_cocoapods.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/pytest/package_manager/test_go.py b/tests/pytest/package_manager/test_go.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/pytest/package_manager/test_gradle.py b/tests/pytest/package_manager/test_gradle.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/pytest/package_manager/test_helm.py b/tests/pytest/package_manager/test_helm.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/pytest/package_manager/test_maven.py b/tests/pytest/package_manager/test_maven.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/pytest/package_manager/test_npm.py b/tests/pytest/package_manager/test_npm.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/pytest/package_manager/test_nuget.py b/tests/pytest/package_manager/test_nuget.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/pytest/package_manager/test_pub.py b/tests/pytest/package_manager/test_pub.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/pytest/package_manager/test_pypi.py b/tests/pytest/package_manager/test_pypi.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/pytest/package_manager/test_swift.py b/tests/pytest/package_manager/test_swift.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/pytest/package_manager/test_unity.py b/tests/pytest/package_manager/test_unity.py new file mode 100644 index 00000000..e69de29b From 8d2092cb208e65cd706bc8554c6075aed80687ed Mon Sep 17 00:00:00 2001 From: yongjunhong Date: Fri, 20 Sep 2024 14:44:29 +0900 Subject: [PATCH 02/17] refactor run_ubuntu test codes Signed-off-by: yongjunhong --- tests/pytest/conftest.py | 10 +++++++ tests/pytest/package_manager/test_android.py | 14 ++++++++++ tests/pytest/package_manager/test_carthage.py | 14 ++++++++++ .../pytest/package_manager/test_cocoapods.py | 14 ++++++++++ tests/pytest/package_manager/test_gradle.py | 15 ++++++++++ tests/pytest/package_manager/test_helm.py | 14 ++++++++++ tests/pytest/package_manager/test_maven.py | 15 ++++++++++ tests/pytest/package_manager/test_npm.py | 15 ++++++++++ tests/pytest/package_manager/test_nuget.py | 15 ++++++++++ tests/pytest/package_manager/test_pub.py | 15 ++++++++++ tests/pytest/package_manager/test_pypi.py | 16 +++++++++++ tox.ini | 28 ++----------------- 12 files changed, 159 insertions(+), 26 deletions(-) create mode 100644 tests/pytest/conftest.py diff --git a/tests/pytest/conftest.py b/tests/pytest/conftest.py new file mode 100644 index 00000000..24e304dd --- /dev/null +++ b/tests/pytest/conftest.py @@ -0,0 +1,10 @@ +import pytest +import subprocess + + +@pytest.fixture +def run_command(): + def _run_command(command): + result = subprocess.run(command, shell=True, capture_output=True, text=True) + return result.returncode, result.stdout, result.stderr + return _run_command diff --git a/tests/pytest/package_manager/test_android.py b/tests/pytest/package_manager/test_android.py index e69de29b..371ed978 100644 --- a/tests/pytest/package_manager/test_android.py +++ b/tests/pytest/package_manager/test_android.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2021 LG Electronics Inc. +# SPDX-License-Identifier: Apache-2.0 + +GRADLE_COMMANDS = [ + "fosslight_dependency -p tests/test_android -o tests/result/android -m android" +] + + +def test_android_get_dependency(run_command): + for command in GRADLE_COMMANDS: + return_code, stdout, stderr = run_command(command) + assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" diff --git a/tests/pytest/package_manager/test_carthage.py b/tests/pytest/package_manager/test_carthage.py index e69de29b..795b450a 100644 --- a/tests/pytest/package_manager/test_carthage.py +++ b/tests/pytest/package_manager/test_carthage.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2021 LG Electronics Inc. +# SPDX-License-Identifier: Apache-2.0 + +GRADLE_COMMANDS = [ + "fosslight_dependency -p tests/test_carthage -o tests/result/carthage -m carthage" +] + + +def test_carthage_get_dependency(run_command): + for command in GRADLE_COMMANDS: + return_code, stdout, stderr = run_command(command) + assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" diff --git a/tests/pytest/package_manager/test_cocoapods.py b/tests/pytest/package_manager/test_cocoapods.py index e69de29b..e7acae1b 100644 --- a/tests/pytest/package_manager/test_cocoapods.py +++ b/tests/pytest/package_manager/test_cocoapods.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2021 LG Electronics Inc. +# SPDX-License-Identifier: Apache-2.0 + +GRADLE_COMMANDS = [ + "fosslight_dependency -p tests/test_cocoapods -o tests/result/cocoapods -m cocoapods" +] + + +def test_cocoapods_get_dependency(run_command): + for command in GRADLE_COMMANDS: + return_code, stdout, stderr = run_command(command) + assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" diff --git a/tests/pytest/package_manager/test_gradle.py b/tests/pytest/package_manager/test_gradle.py index e69de29b..654a224b 100644 --- a/tests/pytest/package_manager/test_gradle.py +++ b/tests/pytest/package_manager/test_gradle.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2021 LG Electronics Inc. +# SPDX-License-Identifier: Apache-2.0 + +GRADLE_COMMANDS = [ + "fosslight_dependency -p tests/test_gradle/jib -o tests/result/gradle", + "fosslight_dependency -p tests/test_gradle2 -o tests/result/gradle2" +] + + +def test_gradle_get_dependency(run_command): + for command in GRADLE_COMMANDS: + return_code, stdout, stderr = run_command(command) + assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" diff --git a/tests/pytest/package_manager/test_helm.py b/tests/pytest/package_manager/test_helm.py index e69de29b..dee325b2 100644 --- a/tests/pytest/package_manager/test_helm.py +++ b/tests/pytest/package_manager/test_helm.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2021 LG Electronics Inc. +# SPDX-License-Identifier: Apache-2.0 + +GRADLE_COMMANDS = [ + "fosslight_dependency -p tests/test_helm -o tests/result/helm -m helm" +] + + +def test_helm_get_dependency(run_command): + for command in GRADLE_COMMANDS: + return_code, stdout, stderr = run_command(command) + assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" diff --git a/tests/pytest/package_manager/test_maven.py b/tests/pytest/package_manager/test_maven.py index e69de29b..b8523705 100644 --- a/tests/pytest/package_manager/test_maven.py +++ b/tests/pytest/package_manager/test_maven.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2021 LG Electronics Inc. +# SPDX-License-Identifier: Apache-2.0 + +GRADLE_COMMANDS = [ + "fosslight_dependency -p tests/test_maven1/lombok.maven -o tests/result/maven1", + "fosslight_dependency -p tests/test_maven2 -o tests/result/maven2" +] + + +def test_maven_get_dependency(run_command): + for command in GRADLE_COMMANDS: + return_code, stdout, stderr = run_command(command) + assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" diff --git a/tests/pytest/package_manager/test_npm.py b/tests/pytest/package_manager/test_npm.py index e69de29b..020ff86f 100644 --- a/tests/pytest/package_manager/test_npm.py +++ b/tests/pytest/package_manager/test_npm.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2021 LG Electronics Inc. +# SPDX-License-Identifier: Apache-2.0 + +GRADLE_COMMANDS = [ + "fosslight_dependency -p tests/test_npm1 -o tests/result/npm1", + "fosslight_dependency -p tests/test_npm2 -o tests/result/npm2 -m npm" +] + + +def test_npm_get_dependency(run_command): + for command in GRADLE_COMMANDS: + return_code, stdout, stderr = run_command(command) + assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" diff --git a/tests/pytest/package_manager/test_nuget.py b/tests/pytest/package_manager/test_nuget.py index e69de29b..f8d2bb80 100644 --- a/tests/pytest/package_manager/test_nuget.py +++ b/tests/pytest/package_manager/test_nuget.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2021 LG Electronics Inc. +# SPDX-License-Identifier: Apache-2.0 + +GRADLE_COMMANDS = [ + "fosslight_dependency -p tests/test_nuget -o tests/result/nuget1", + "fosslight_dependency -p tests/test_nuget2 -o tests/result/nuget2" +] + + +def test_nuget_get_dependency(run_command): + for command in GRADLE_COMMANDS: + return_code, stdout, stderr = run_command(command) + assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" diff --git a/tests/pytest/package_manager/test_pub.py b/tests/pytest/package_manager/test_pub.py index e69de29b..c3d3457a 100644 --- a/tests/pytest/package_manager/test_pub.py +++ b/tests/pytest/package_manager/test_pub.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2021 LG Electronics Inc. +# SPDX-License-Identifier: Apache-2.0 + +GRADLE_COMMANDS = [ + "fosslight_dependency -p tests/test_pub -o tests/result/pub", + "fosslight_dependency -p tests/test_exclude -e requirements.txt -o tests/result/exclude" +] + + +def test_pub_get_dependency(run_command): + for command in GRADLE_COMMANDS: + return_code, stdout, stderr = run_command(command) + assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" diff --git a/tests/pytest/package_manager/test_pypi.py b/tests/pytest/package_manager/test_pypi.py index e69de29b..467ca130 100644 --- a/tests/pytest/package_manager/test_pypi.py +++ b/tests/pytest/package_manager/test_pypi.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2021 LG Electronics Inc. +# SPDX-License-Identifier: Apache-2.0 + +GRADLE_COMMANDS = [ + "fosslight_dependency -p tests/test_pypi -o tests/result/pypi", + "fosslight_dependency -p tests/test_multi_pypi_npm -o tests/result/multi_pypi_npm", + "fosslight_dependency -p tests/test_multi_pypi_npm -o tests/result/multi_pypi_npm -f opossum" +] + + +def test_pypi_get_dependency(run_command): + for command in GRADLE_COMMANDS: + return_code, stdout, stderr = run_command(command) + assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" diff --git a/tox.ini b/tox.ini index 06a05216..0c4f1434 100644 --- a/tox.ini +++ b/tox.ini @@ -38,32 +38,8 @@ deps = commands = # Test for PEP8 pytest -v --flake8 - # Test for Pypi - fosslight_dependency -p tests/test_pypi -o tests/result/pypi - # Test for NPM (without optional command) - fosslight_dependency -p tests/test_npm1 -o tests/result/npm1 - # Test for NPM (with optional command) - fosslight_dependency -p tests/test_npm2 -o tests/result/npm2 -m npm - # Test for Maven (without optional command) - fosslight_dependency -p tests/test_maven1/lombok.maven -o tests/result/maven1 - # Test for Maven (with optional command) - fosslight_dependency -p tests/test_maven2 -o tests/result/maven2 - # Test for Gradle - fosslight_dependency -p tests/test_gradle/jib -o tests/result/gradle - # Test for Gradle2 - fosslight_dependency -p tests/test_gradle2 -o tests/result/gradle2 - # Test for Pub - fosslight_dependency -p tests/test_pub -o tests/result/pub - # Test for multi package manager (npm, pypi) - fosslight_dependency -p tests/test_multi_pypi_npm -o tests/result/multi_pypi_npm - # Test for opossum result - fosslight_dependency -p tests/test_multi_pypi_npm -o tests/result/multi_pypi_npm -f opossum - # Test for nuget (for packageReference) - fosslight_dependency -p tests/test_nuget -o tests/result/nuget1 - # Test for nuget2 (for packages.config) - fosslight_dependency -p tests/test_nuget2 -o tests/result/nuget2 - # Test for excluding path (scan only pub, exclude pypi) - fosslight_dependency -p tests/test_exclude -e requirements.txt -o tests/result/exclude + pytest -n auto + [testenv:run_windows] deps = From d4479e5ab76dc354464e5ac70988a0e55ed407c5 Mon Sep 17 00:00:00 2001 From: yongjunhong Date: Fri, 20 Sep 2024 14:47:06 +0900 Subject: [PATCH 03/17] rename constant value Signed-off-by: yongjunhong --- tests/pytest/package_manager/test_android.py | 4 ++-- tests/pytest/package_manager/test_carthage.py | 4 ++-- tests/pytest/package_manager/test_cocoapods.py | 4 ++-- tests/pytest/package_manager/test_gradle.py | 4 ++-- tests/pytest/package_manager/test_helm.py | 4 ++-- tests/pytest/package_manager/test_maven.py | 4 ++-- tests/pytest/package_manager/test_npm.py | 4 ++-- tests/pytest/package_manager/test_nuget.py | 4 ++-- tests/pytest/package_manager/test_pub.py | 4 ++-- tests/pytest/package_manager/test_pypi.py | 4 ++-- 10 files changed, 20 insertions(+), 20 deletions(-) diff --git a/tests/pytest/package_manager/test_android.py b/tests/pytest/package_manager/test_android.py index 371ed978..39a62dd6 100644 --- a/tests/pytest/package_manager/test_android.py +++ b/tests/pytest/package_manager/test_android.py @@ -3,12 +3,12 @@ # Copyright (c) 2021 LG Electronics Inc. # SPDX-License-Identifier: Apache-2.0 -GRADLE_COMMANDS = [ +COMMANDS = [ "fosslight_dependency -p tests/test_android -o tests/result/android -m android" ] def test_android_get_dependency(run_command): - for command in GRADLE_COMMANDS: + for command in COMMANDS: return_code, stdout, stderr = run_command(command) assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" diff --git a/tests/pytest/package_manager/test_carthage.py b/tests/pytest/package_manager/test_carthage.py index 795b450a..43e57cc8 100644 --- a/tests/pytest/package_manager/test_carthage.py +++ b/tests/pytest/package_manager/test_carthage.py @@ -3,12 +3,12 @@ # Copyright (c) 2021 LG Electronics Inc. # SPDX-License-Identifier: Apache-2.0 -GRADLE_COMMANDS = [ +COMMANDS = [ "fosslight_dependency -p tests/test_carthage -o tests/result/carthage -m carthage" ] def test_carthage_get_dependency(run_command): - for command in GRADLE_COMMANDS: + for command in COMMANDS: return_code, stdout, stderr = run_command(command) assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" diff --git a/tests/pytest/package_manager/test_cocoapods.py b/tests/pytest/package_manager/test_cocoapods.py index e7acae1b..09a2fed9 100644 --- a/tests/pytest/package_manager/test_cocoapods.py +++ b/tests/pytest/package_manager/test_cocoapods.py @@ -3,12 +3,12 @@ # Copyright (c) 2021 LG Electronics Inc. # SPDX-License-Identifier: Apache-2.0 -GRADLE_COMMANDS = [ +COMMANDS = [ "fosslight_dependency -p tests/test_cocoapods -o tests/result/cocoapods -m cocoapods" ] def test_cocoapods_get_dependency(run_command): - for command in GRADLE_COMMANDS: + for command in COMMANDS: return_code, stdout, stderr = run_command(command) assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" diff --git a/tests/pytest/package_manager/test_gradle.py b/tests/pytest/package_manager/test_gradle.py index 654a224b..8501acbf 100644 --- a/tests/pytest/package_manager/test_gradle.py +++ b/tests/pytest/package_manager/test_gradle.py @@ -3,13 +3,13 @@ # Copyright (c) 2021 LG Electronics Inc. # SPDX-License-Identifier: Apache-2.0 -GRADLE_COMMANDS = [ +COMMANDS = [ "fosslight_dependency -p tests/test_gradle/jib -o tests/result/gradle", "fosslight_dependency -p tests/test_gradle2 -o tests/result/gradle2" ] def test_gradle_get_dependency(run_command): - for command in GRADLE_COMMANDS: + for command in COMMANDS: return_code, stdout, stderr = run_command(command) assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" diff --git a/tests/pytest/package_manager/test_helm.py b/tests/pytest/package_manager/test_helm.py index dee325b2..281ba8cd 100644 --- a/tests/pytest/package_manager/test_helm.py +++ b/tests/pytest/package_manager/test_helm.py @@ -3,12 +3,12 @@ # Copyright (c) 2021 LG Electronics Inc. # SPDX-License-Identifier: Apache-2.0 -GRADLE_COMMANDS = [ +COMMANDS = [ "fosslight_dependency -p tests/test_helm -o tests/result/helm -m helm" ] def test_helm_get_dependency(run_command): - for command in GRADLE_COMMANDS: + for command in COMMANDS: return_code, stdout, stderr = run_command(command) assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" diff --git a/tests/pytest/package_manager/test_maven.py b/tests/pytest/package_manager/test_maven.py index b8523705..cea4ea16 100644 --- a/tests/pytest/package_manager/test_maven.py +++ b/tests/pytest/package_manager/test_maven.py @@ -3,13 +3,13 @@ # Copyright (c) 2021 LG Electronics Inc. # SPDX-License-Identifier: Apache-2.0 -GRADLE_COMMANDS = [ +COMMANDS = [ "fosslight_dependency -p tests/test_maven1/lombok.maven -o tests/result/maven1", "fosslight_dependency -p tests/test_maven2 -o tests/result/maven2" ] def test_maven_get_dependency(run_command): - for command in GRADLE_COMMANDS: + for command in COMMANDS: return_code, stdout, stderr = run_command(command) assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" diff --git a/tests/pytest/package_manager/test_npm.py b/tests/pytest/package_manager/test_npm.py index 020ff86f..f9685bcb 100644 --- a/tests/pytest/package_manager/test_npm.py +++ b/tests/pytest/package_manager/test_npm.py @@ -3,13 +3,13 @@ # Copyright (c) 2021 LG Electronics Inc. # SPDX-License-Identifier: Apache-2.0 -GRADLE_COMMANDS = [ +COMMANDS = [ "fosslight_dependency -p tests/test_npm1 -o tests/result/npm1", "fosslight_dependency -p tests/test_npm2 -o tests/result/npm2 -m npm" ] def test_npm_get_dependency(run_command): - for command in GRADLE_COMMANDS: + for command in COMMANDS: return_code, stdout, stderr = run_command(command) assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" diff --git a/tests/pytest/package_manager/test_nuget.py b/tests/pytest/package_manager/test_nuget.py index f8d2bb80..c8d0b3d4 100644 --- a/tests/pytest/package_manager/test_nuget.py +++ b/tests/pytest/package_manager/test_nuget.py @@ -3,13 +3,13 @@ # Copyright (c) 2021 LG Electronics Inc. # SPDX-License-Identifier: Apache-2.0 -GRADLE_COMMANDS = [ +COMMANDS = [ "fosslight_dependency -p tests/test_nuget -o tests/result/nuget1", "fosslight_dependency -p tests/test_nuget2 -o tests/result/nuget2" ] def test_nuget_get_dependency(run_command): - for command in GRADLE_COMMANDS: + for command in COMMANDS: return_code, stdout, stderr = run_command(command) assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" diff --git a/tests/pytest/package_manager/test_pub.py b/tests/pytest/package_manager/test_pub.py index c3d3457a..15916b78 100644 --- a/tests/pytest/package_manager/test_pub.py +++ b/tests/pytest/package_manager/test_pub.py @@ -3,13 +3,13 @@ # Copyright (c) 2021 LG Electronics Inc. # SPDX-License-Identifier: Apache-2.0 -GRADLE_COMMANDS = [ +COMMANDS = [ "fosslight_dependency -p tests/test_pub -o tests/result/pub", "fosslight_dependency -p tests/test_exclude -e requirements.txt -o tests/result/exclude" ] def test_pub_get_dependency(run_command): - for command in GRADLE_COMMANDS: + for command in COMMANDS: return_code, stdout, stderr = run_command(command) assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" diff --git a/tests/pytest/package_manager/test_pypi.py b/tests/pytest/package_manager/test_pypi.py index 467ca130..60faf395 100644 --- a/tests/pytest/package_manager/test_pypi.py +++ b/tests/pytest/package_manager/test_pypi.py @@ -3,7 +3,7 @@ # Copyright (c) 2021 LG Electronics Inc. # SPDX-License-Identifier: Apache-2.0 -GRADLE_COMMANDS = [ +COMMANDS = [ "fosslight_dependency -p tests/test_pypi -o tests/result/pypi", "fosslight_dependency -p tests/test_multi_pypi_npm -o tests/result/multi_pypi_npm", "fosslight_dependency -p tests/test_multi_pypi_npm -o tests/result/multi_pypi_npm -f opossum" @@ -11,6 +11,6 @@ def test_pypi_get_dependency(run_command): - for command in GRADLE_COMMANDS: + for command in COMMANDS: return_code, stdout, stderr = run_command(command) assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" From aeadbbc964c824ee880f6b04f9e25831bd567592 Mon Sep 17 00:00:00 2001 From: yongjunhong Date: Thu, 26 Sep 2024 13:00:38 +0900 Subject: [PATCH 04/17] refactor test codes - rename test methods - separate window, ubuntu test codes Signed-off-by: yongjunhong --- requirements-dev.txt | 2 +- tests/pytest/package_manager/test_android.py | 16 +++++++++--- tests/pytest/package_manager/test_carthage.py | 6 ++--- .../pytest/package_manager/test_cocoapods.py | 6 ++--- tests/pytest/package_manager/test_gradle.py | 6 ++--- tests/pytest/package_manager/test_helm.py | 6 ++--- tests/pytest/package_manager/test_maven.py | 6 ++--- tests/pytest/package_manager/test_npm.py | 6 ++--- tests/pytest/package_manager/test_nuget.py | 6 ++--- tests/pytest/package_manager/test_pub.py | 6 ++--- tests/pytest/package_manager/test_pypi.py | 6 ++--- tox.ini | 26 +++---------------- 12 files changed, 44 insertions(+), 54 deletions(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 3ab0fa69..49006f4a 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,5 +1,5 @@ flake8==3.9.2 -pyinstaller +pyinstaller>=6.10.0 tox>=4.18.1 pytest pytest-cov diff --git a/tests/pytest/package_manager/test_android.py b/tests/pytest/package_manager/test_android.py index 39a62dd6..8e632c45 100644 --- a/tests/pytest/package_manager/test_android.py +++ b/tests/pytest/package_manager/test_android.py @@ -3,12 +3,22 @@ # Copyright (c) 2021 LG Electronics Inc. # SPDX-License-Identifier: Apache-2.0 -COMMANDS = [ +UBUNTU_COMMANDS = [ "fosslight_dependency -p tests/test_android -o tests/result/android -m android" ] +WINDOW_COMMANDS = [ + "\dist\cli.exe -p tests\test_maven2 -o tests\result\maven2 -m maven" +] + + +def test_ubuntu(run_command): + for command in UBUNTU_COMMANDS: + return_code, stdout, stderr = run_command(command) + assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" + -def test_android_get_dependency(run_command): - for command in COMMANDS: +def test_window(run_command): + for command in WINDOW_COMMANDS: return_code, stdout, stderr = run_command(command) assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" diff --git a/tests/pytest/package_manager/test_carthage.py b/tests/pytest/package_manager/test_carthage.py index 43e57cc8..04d5c30c 100644 --- a/tests/pytest/package_manager/test_carthage.py +++ b/tests/pytest/package_manager/test_carthage.py @@ -3,12 +3,12 @@ # Copyright (c) 2021 LG Electronics Inc. # SPDX-License-Identifier: Apache-2.0 -COMMANDS = [ +UBUNTU_COMMANDS = [ "fosslight_dependency -p tests/test_carthage -o tests/result/carthage -m carthage" ] -def test_carthage_get_dependency(run_command): - for command in COMMANDS: +def test_ubuntu(run_command): + for command in UBUNTU_COMMANDS: return_code, stdout, stderr = run_command(command) assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" diff --git a/tests/pytest/package_manager/test_cocoapods.py b/tests/pytest/package_manager/test_cocoapods.py index 09a2fed9..b5b00731 100644 --- a/tests/pytest/package_manager/test_cocoapods.py +++ b/tests/pytest/package_manager/test_cocoapods.py @@ -3,12 +3,12 @@ # Copyright (c) 2021 LG Electronics Inc. # SPDX-License-Identifier: Apache-2.0 -COMMANDS = [ +UBUNTU_COMMANDS = [ "fosslight_dependency -p tests/test_cocoapods -o tests/result/cocoapods -m cocoapods" ] -def test_cocoapods_get_dependency(run_command): - for command in COMMANDS: +def test_ubuntu(run_command): + for command in UBUNTU_COMMANDS: return_code, stdout, stderr = run_command(command) assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" diff --git a/tests/pytest/package_manager/test_gradle.py b/tests/pytest/package_manager/test_gradle.py index 8501acbf..a78e5f4a 100644 --- a/tests/pytest/package_manager/test_gradle.py +++ b/tests/pytest/package_manager/test_gradle.py @@ -3,13 +3,13 @@ # Copyright (c) 2021 LG Electronics Inc. # SPDX-License-Identifier: Apache-2.0 -COMMANDS = [ +UBUNTU_COMMANDS = [ "fosslight_dependency -p tests/test_gradle/jib -o tests/result/gradle", "fosslight_dependency -p tests/test_gradle2 -o tests/result/gradle2" ] -def test_gradle_get_dependency(run_command): - for command in COMMANDS: +def test_ubuntu(run_command): + for command in UBUNTU_COMMANDS: return_code, stdout, stderr = run_command(command) assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" diff --git a/tests/pytest/package_manager/test_helm.py b/tests/pytest/package_manager/test_helm.py index 281ba8cd..106c1f35 100644 --- a/tests/pytest/package_manager/test_helm.py +++ b/tests/pytest/package_manager/test_helm.py @@ -3,12 +3,12 @@ # Copyright (c) 2021 LG Electronics Inc. # SPDX-License-Identifier: Apache-2.0 -COMMANDS = [ +UBUNTU_COMMANDS = [ "fosslight_dependency -p tests/test_helm -o tests/result/helm -m helm" ] -def test_helm_get_dependency(run_command): - for command in COMMANDS: +def test_ubuntu(run_command): + for command in UBUNTU_COMMANDS: return_code, stdout, stderr = run_command(command) assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" diff --git a/tests/pytest/package_manager/test_maven.py b/tests/pytest/package_manager/test_maven.py index cea4ea16..2bca205e 100644 --- a/tests/pytest/package_manager/test_maven.py +++ b/tests/pytest/package_manager/test_maven.py @@ -3,13 +3,13 @@ # Copyright (c) 2021 LG Electronics Inc. # SPDX-License-Identifier: Apache-2.0 -COMMANDS = [ +UBUNTU_COMMANDS = [ "fosslight_dependency -p tests/test_maven1/lombok.maven -o tests/result/maven1", "fosslight_dependency -p tests/test_maven2 -o tests/result/maven2" ] -def test_maven_get_dependency(run_command): - for command in COMMANDS: +def test_ubuntu(run_command): + for command in UBUNTU_COMMANDS: return_code, stdout, stderr = run_command(command) assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" diff --git a/tests/pytest/package_manager/test_npm.py b/tests/pytest/package_manager/test_npm.py index f9685bcb..e92ab1db 100644 --- a/tests/pytest/package_manager/test_npm.py +++ b/tests/pytest/package_manager/test_npm.py @@ -3,13 +3,13 @@ # Copyright (c) 2021 LG Electronics Inc. # SPDX-License-Identifier: Apache-2.0 -COMMANDS = [ +UBUNTU_COMMANDS = [ "fosslight_dependency -p tests/test_npm1 -o tests/result/npm1", "fosslight_dependency -p tests/test_npm2 -o tests/result/npm2 -m npm" ] -def test_npm_get_dependency(run_command): - for command in COMMANDS: +def test_ubuntu(run_command): + for command in UBUNTU_COMMANDS: return_code, stdout, stderr = run_command(command) assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" diff --git a/tests/pytest/package_manager/test_nuget.py b/tests/pytest/package_manager/test_nuget.py index c8d0b3d4..45ba789a 100644 --- a/tests/pytest/package_manager/test_nuget.py +++ b/tests/pytest/package_manager/test_nuget.py @@ -3,13 +3,13 @@ # Copyright (c) 2021 LG Electronics Inc. # SPDX-License-Identifier: Apache-2.0 -COMMANDS = [ +UBUNTU_COMMANDS = [ "fosslight_dependency -p tests/test_nuget -o tests/result/nuget1", "fosslight_dependency -p tests/test_nuget2 -o tests/result/nuget2" ] -def test_nuget_get_dependency(run_command): - for command in COMMANDS: +def test_ubuntu(run_command): + for command in UBUNTU_COMMANDS: return_code, stdout, stderr = run_command(command) assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" diff --git a/tests/pytest/package_manager/test_pub.py b/tests/pytest/package_manager/test_pub.py index 15916b78..9016980f 100644 --- a/tests/pytest/package_manager/test_pub.py +++ b/tests/pytest/package_manager/test_pub.py @@ -3,13 +3,13 @@ # Copyright (c) 2021 LG Electronics Inc. # SPDX-License-Identifier: Apache-2.0 -COMMANDS = [ +UBUNTU_COMMANDS = [ "fosslight_dependency -p tests/test_pub -o tests/result/pub", "fosslight_dependency -p tests/test_exclude -e requirements.txt -o tests/result/exclude" ] -def test_pub_get_dependency(run_command): - for command in COMMANDS: +def test_ubuntu(run_command): + for command in UBUNTU_COMMANDS: return_code, stdout, stderr = run_command(command) assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" diff --git a/tests/pytest/package_manager/test_pypi.py b/tests/pytest/package_manager/test_pypi.py index 60faf395..7b91e9f8 100644 --- a/tests/pytest/package_manager/test_pypi.py +++ b/tests/pytest/package_manager/test_pypi.py @@ -3,14 +3,14 @@ # Copyright (c) 2021 LG Electronics Inc. # SPDX-License-Identifier: Apache-2.0 -COMMANDS = [ +UBUNTU_COMMANDS = [ "fosslight_dependency -p tests/test_pypi -o tests/result/pypi", "fosslight_dependency -p tests/test_multi_pypi_npm -o tests/result/multi_pypi_npm", "fosslight_dependency -p tests/test_multi_pypi_npm -o tests/result/multi_pypi_npm -f opossum" ] -def test_pypi_get_dependency(run_command): - for command in COMMANDS: +def test_ubuntu(run_command): + for command in UBUNTU_COMMANDS: return_code, stdout, stderr = run_command(command) assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" diff --git a/tox.ini b/tox.ini index 0c4f1434..170bcfb3 100644 --- a/tox.ini +++ b/tox.ini @@ -38,32 +38,12 @@ deps = commands = # Test for PEP8 pytest -v --flake8 - pytest -n auto - + pytest tests/ -k "test_ubuntu" [testenv:run_windows] deps = -r{toxinidir}\requirements-dev.txt commands = # Test for making excutable file - pyinstaller --onefile cli.py -n cli --additional-hooks-dir=hooks --add-binary "src\fosslight_dependency\third_party\askalono\askalono.exe;third_party\askalono" --add-binary "LICENSE;LICENSES" --add-binary "LICENSES\LicenseRef-3rd_party_licenses.txt;LICENSES" --collect-datas fosslight_util --hidden-import=_cffi_backend - # Test for Pypi - {toxinidir}\dist\cli.exe -p tests\test_pypi -o tests\result\pypi - # Test for Maven (with optional command) - {toxinidir}\dist\cli.exe -p tests\test_maven2 -o tests\result\maven2 -m maven - # Test for Gradle - {toxinidir}\dist\cli.exe -p tests\test_gradle\jib -o tests\result\gradle -m gradle - # Test for Gradle2 - fosslight_dependency -p tests\test_gradle2 -o tests\result\gradle2 -m gradle - # Test for Pub - {toxinidir}\dist\cli.exe -p tests\test_pub -o tests\result\pub - # Test for Android - {toxinidir}\dist\cli.exe -p tests\test_android\sunflower -o tests\result\android - # Test for opossum result - {toxinidir}\dist\cli.exe -p tests\test_pub -o tests\result\pub -f opossum - # Test for nuget (for packageReference) - {toxinidir}\dist\cli.exe -p tests\test_nuget -o tests\result\nuget1 - # Test for nuget2 (for packages.config) - {toxinidir}\dist\cli.exe -p tests\test_nuget2 -o tests\result\nuget2 - # Test for excluding path (scan only pub, exclude pypi) - {toxinidir}\dist\cli.exe -p tests\test_exclude -e requirements.txt -o tests\result\exclude + pyinstaller --onefile cli.py -n cli --additional-hooks-dir=hooks --add-binary=src\fosslight_dependency\third_party\askalono\askalono.exe:third_party\askalono --add-binary=LICENSE:LICENSES --add-binary=LICENSES\LicenseRef-3rd_party_licenses.txt:LICENSES --collect-datas fosslight_util --hidden-import=_cffi_backend + pytest tests\ -k "test_windows" From 7cb322d8a7dc67c3270d7f4d8c5ef839d619fc58 Mon Sep 17 00:00:00 2001 From: yongjunhong Date: Thu, 26 Sep 2024 13:49:33 +0900 Subject: [PATCH 05/17] generate windows test code Signed-off-by: yongjunhong --- tests/pytest/package_manager/test_android.py | 11 +++++++---- tests/pytest/package_manager/test_gradle.py | 17 +++++++++++++++++ tests/pytest/package_manager/test_maven.py | 13 +++++++++++++ tests/pytest/package_manager/test_nuget.py | 18 ++++++++++++++++++ tests/pytest/package_manager/test_pub.py | 19 +++++++++++++++++++ tests/pytest/package_manager/test_pypi.py | 13 +++++++++++++ tox.ini | 6 +++--- 7 files changed, 90 insertions(+), 7 deletions(-) diff --git a/tests/pytest/package_manager/test_android.py b/tests/pytest/package_manager/test_android.py index 8e632c45..112195fb 100644 --- a/tests/pytest/package_manager/test_android.py +++ b/tests/pytest/package_manager/test_android.py @@ -2,14 +2,17 @@ # -*- coding: utf-8 -*- # Copyright (c) 2021 LG Electronics Inc. # SPDX-License-Identifier: Apache-2.0 +import os.path UBUNTU_COMMANDS = [ "fosslight_dependency -p tests/test_android -o tests/result/android -m android" ] -WINDOW_COMMANDS = [ - "\dist\cli.exe -p tests\test_maven2 -o tests\result\maven2 -m maven" -] +DIST_PATH = os.path.join(os.path.abspath(os.sep), "dist", "cli.exe") +INPUT_PATH = os.path.join("tests", "test_android", "sunflower") +OUTPUT_PATH = os.path.join("tests", "result", "android") + +WINDOW_COMMANDS = [f"{DIST_PATH} -p {INPUT_PATH} -o {OUTPUT_PATH}"] def test_ubuntu(run_command): @@ -18,7 +21,7 @@ def test_ubuntu(run_command): assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" -def test_window(run_command): +def test_windows(run_command): for command in WINDOW_COMMANDS: return_code, stdout, stderr = run_command(command) assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" diff --git a/tests/pytest/package_manager/test_gradle.py b/tests/pytest/package_manager/test_gradle.py index a78e5f4a..184bdd94 100644 --- a/tests/pytest/package_manager/test_gradle.py +++ b/tests/pytest/package_manager/test_gradle.py @@ -2,14 +2,31 @@ # -*- coding: utf-8 -*- # Copyright (c) 2021 LG Electronics Inc. # SPDX-License-Identifier: Apache-2.0 +import os UBUNTU_COMMANDS = [ "fosslight_dependency -p tests/test_gradle/jib -o tests/result/gradle", "fosslight_dependency -p tests/test_gradle2 -o tests/result/gradle2" ] +DIST_PATH = os.path.join(os.path.abspath(os.sep), "dist", "cli.exe") +INPUT_PATH = os.path.join("tests", "test_gradle", "jib") +OUTPUT_PATH = os.path.join("tests", "result", "gradle") +INPUT_PATH2 = os.path.join("tests", "test_gradle2") +OUTPUT_PATH2 = os.path.join("tests", "result", "gradle2") + +WINDOW_COMMANDS = [ + f"{DIST_PATH} -p {INPUT_PATH} -o {OUTPUT_PATH} -m gradle", + f"{DIST_PATH} -p {INPUT_PATH2} -o {OUTPUT_PATH2} -m gradle", +] def test_ubuntu(run_command): for command in UBUNTU_COMMANDS: return_code, stdout, stderr = run_command(command) assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" + + +def test_windows(run_command): + for command in WINDOW_COMMANDS: + return_code, stdout, stderr = run_command(command) + assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" diff --git a/tests/pytest/package_manager/test_maven.py b/tests/pytest/package_manager/test_maven.py index 2bca205e..134d597e 100644 --- a/tests/pytest/package_manager/test_maven.py +++ b/tests/pytest/package_manager/test_maven.py @@ -2,14 +2,27 @@ # -*- coding: utf-8 -*- # Copyright (c) 2021 LG Electronics Inc. # SPDX-License-Identifier: Apache-2.0 +import os.path UBUNTU_COMMANDS = [ "fosslight_dependency -p tests/test_maven1/lombok.maven -o tests/result/maven1", "fosslight_dependency -p tests/test_maven2 -o tests/result/maven2" ] +DIST_PATH = os.path.join(os.path.abspath(os.sep), "dist", "cli.exe") +INPUT_PATH = os.path.join("tests", "test_maven2") +OUTPUT_PATH = os.path.join("tests", "result", "maven2") + +WINDOW_COMMANDS = [f"{DIST_PATH} -p {INPUT_PATH} -o {OUTPUT_PATH} -m maven"] + def test_ubuntu(run_command): for command in UBUNTU_COMMANDS: return_code, stdout, stderr = run_command(command) assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" + + +def test_windows(run_command): + for command in WINDOW_COMMANDS: + return_code, stdout, stderr = run_command(command) + assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" diff --git a/tests/pytest/package_manager/test_nuget.py b/tests/pytest/package_manager/test_nuget.py index 45ba789a..533167ea 100644 --- a/tests/pytest/package_manager/test_nuget.py +++ b/tests/pytest/package_manager/test_nuget.py @@ -2,14 +2,32 @@ # -*- coding: utf-8 -*- # Copyright (c) 2021 LG Electronics Inc. # SPDX-License-Identifier: Apache-2.0 +import os.path UBUNTU_COMMANDS = [ "fosslight_dependency -p tests/test_nuget -o tests/result/nuget1", "fosslight_dependency -p tests/test_nuget2 -o tests/result/nuget2" ] +DIST_PATH = os.path.join(os.path.abspath(os.sep), "dist", "cli.exe") +INPUT_PATH = os.path.join("tests", "test_nuget") +OUTPUT_PATH = os.path.join("tests", "result", "nuget1") +INPUT_PATH2 = os.path.join("tests", "test_nuget2") +OUTPUT_PATH2 = os.path.join("tests", "result", "nuget2") + +WINDOW_COMMANDS = [ + f"{DIST_PATH} -p {INPUT_PATH} -o {OUTPUT_PATH}", + f"{DIST_PATH} -p {INPUT_PATH2} -o {OUTPUT_PATH2}" +] + def test_ubuntu(run_command): for command in UBUNTU_COMMANDS: return_code, stdout, stderr = run_command(command) assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" + + +def test_windows(run_command): + for command in WINDOW_COMMANDS: + return_code, stdout, stderr = run_command(command) + assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" \ No newline at end of file diff --git a/tests/pytest/package_manager/test_pub.py b/tests/pytest/package_manager/test_pub.py index 9016980f..336a7040 100644 --- a/tests/pytest/package_manager/test_pub.py +++ b/tests/pytest/package_manager/test_pub.py @@ -2,14 +2,33 @@ # -*- coding: utf-8 -*- # Copyright (c) 2021 LG Electronics Inc. # SPDX-License-Identifier: Apache-2.0 +import os.path UBUNTU_COMMANDS = [ "fosslight_dependency -p tests/test_pub -o tests/result/pub", "fosslight_dependency -p tests/test_exclude -e requirements.txt -o tests/result/exclude" ] +DIST_PATH = os.path.join(os.path.abspath(os.sep), "dist", "cli.exe") +INPUT_PATH = os.path.join("tests", "test_pub") +OUTPUT_PATH = os.path.join("tests", "result", "pub") +INPUT_PATH2 = os.path.join("tests", "test_exclude") +OUTPUT_PATH2 = os.path.join("tests", "result", "exclude") + +WINDOW_COMMANDS = [ + f"{DIST_PATH} -p {INPUT_PATH} -o {OUTPUT_PATH}", + f"{DIST_PATH} -p {INPUT_PATH} -o {OUTPUT_PATH} -f opossum", + f"{DIST_PATH} -p {INPUT_PATH} -e requirements.txt -o {OUTPUT_PATH}" +] + def test_ubuntu(run_command): for command in UBUNTU_COMMANDS: return_code, stdout, stderr = run_command(command) assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" + + +def test_windows(run_command): + for command in WINDOW_COMMANDS: + return_code, stdout, stderr = run_command(command) + assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" diff --git a/tests/pytest/package_manager/test_pypi.py b/tests/pytest/package_manager/test_pypi.py index 7b91e9f8..ff2e5d6c 100644 --- a/tests/pytest/package_manager/test_pypi.py +++ b/tests/pytest/package_manager/test_pypi.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- # Copyright (c) 2021 LG Electronics Inc. # SPDX-License-Identifier: Apache-2.0 +import os.path UBUNTU_COMMANDS = [ "fosslight_dependency -p tests/test_pypi -o tests/result/pypi", @@ -9,8 +10,20 @@ "fosslight_dependency -p tests/test_multi_pypi_npm -o tests/result/multi_pypi_npm -f opossum" ] +DIST_PATH = os.path.join(os.path.abspath(os.sep), "dist", "cli.exe") +INPUT_PATH = os.path.join("tests", "test_pypi") +OUTPUT_PATH = os.path.join("tests", "result", "pypi") + +WINDOW_COMMANDS = [f"{DIST_PATH} -p {INPUT_PATH} -o {OUTPUT_PATH}"] + def test_ubuntu(run_command): for command in UBUNTU_COMMANDS: return_code, stdout, stderr = run_command(command) assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" + + +def test_windows(run_command): + for command in WINDOW_COMMANDS: + return_code, stdout, stderr = run_command(command) + assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" diff --git a/tox.ini b/tox.ini index 170bcfb3..cc4aaeee 100644 --- a/tox.ini +++ b/tox.ini @@ -42,8 +42,8 @@ commands = [testenv:run_windows] deps = - -r{toxinidir}\requirements-dev.txt + -r{toxinidir}/requirements-dev.txt commands = # Test for making excutable file - pyinstaller --onefile cli.py -n cli --additional-hooks-dir=hooks --add-binary=src\fosslight_dependency\third_party\askalono\askalono.exe:third_party\askalono --add-binary=LICENSE:LICENSES --add-binary=LICENSES\LicenseRef-3rd_party_licenses.txt:LICENSES --collect-datas fosslight_util --hidden-import=_cffi_backend - pytest tests\ -k "test_windows" + pyinstaller --onefile cli.py -n cli --additional-hooks-dir=hooks --add-binary=src/fosslight_dependency/third_party/askalono/askalono.exe:third_party/askalono --add-binary=LICENSE:LICENSES --add-binary=LICENSES/LicenseRef-3rd_party_licenses.txt:LICENSES --collect-datas fosslight_util --hidden-import=_cffi_backend + pytest tests/ -k "test_windows" From ba9f209d38c5d985fb992ab9d576357b29de5665 Mon Sep 17 00:00:00 2001 From: yongjunhong Date: Thu, 26 Sep 2024 14:37:40 +0900 Subject: [PATCH 06/17] Resolve not found exception Signed-off-by: yongjunhong --- tests/pytest/package_manager/test_android.py | 2 +- tests/pytest/package_manager/test_gradle.py | 3 ++- tests/pytest/package_manager/test_maven.py | 2 +- tests/pytest/package_manager/test_nuget.py | 2 +- tests/pytest/package_manager/test_pub.py | 2 +- tests/pytest/package_manager/test_pypi.py | 2 +- tox.ini | 1 + 7 files changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/pytest/package_manager/test_android.py b/tests/pytest/package_manager/test_android.py index 112195fb..482335f6 100644 --- a/tests/pytest/package_manager/test_android.py +++ b/tests/pytest/package_manager/test_android.py @@ -8,7 +8,7 @@ "fosslight_dependency -p tests/test_android -o tests/result/android -m android" ] -DIST_PATH = os.path.join(os.path.abspath(os.sep), "dist", "cli.exe") +DIST_PATH = os.path.join(os.environ.get("TOX_PATH"), "dist", "cli.exe") INPUT_PATH = os.path.join("tests", "test_android", "sunflower") OUTPUT_PATH = os.path.join("tests", "result", "android") diff --git a/tests/pytest/package_manager/test_gradle.py b/tests/pytest/package_manager/test_gradle.py index 184bdd94..f4632093 100644 --- a/tests/pytest/package_manager/test_gradle.py +++ b/tests/pytest/package_manager/test_gradle.py @@ -9,7 +9,7 @@ "fosslight_dependency -p tests/test_gradle2 -o tests/result/gradle2" ] -DIST_PATH = os.path.join(os.path.abspath(os.sep), "dist", "cli.exe") +DIST_PATH = os.path.join(os.environ.get("TOX_PATH"), "dist", "cli.exe") INPUT_PATH = os.path.join("tests", "test_gradle", "jib") OUTPUT_PATH = os.path.join("tests", "result", "gradle") INPUT_PATH2 = os.path.join("tests", "test_gradle2") @@ -20,6 +20,7 @@ f"{DIST_PATH} -p {INPUT_PATH2} -o {OUTPUT_PATH2} -m gradle", ] + def test_ubuntu(run_command): for command in UBUNTU_COMMANDS: return_code, stdout, stderr = run_command(command) diff --git a/tests/pytest/package_manager/test_maven.py b/tests/pytest/package_manager/test_maven.py index 134d597e..9b19fb25 100644 --- a/tests/pytest/package_manager/test_maven.py +++ b/tests/pytest/package_manager/test_maven.py @@ -9,7 +9,7 @@ "fosslight_dependency -p tests/test_maven2 -o tests/result/maven2" ] -DIST_PATH = os.path.join(os.path.abspath(os.sep), "dist", "cli.exe") +DIST_PATH = os.path.join(os.environ.get("TOX_PATH"), "dist", "cli.exe") INPUT_PATH = os.path.join("tests", "test_maven2") OUTPUT_PATH = os.path.join("tests", "result", "maven2") diff --git a/tests/pytest/package_manager/test_nuget.py b/tests/pytest/package_manager/test_nuget.py index 533167ea..cabafe9a 100644 --- a/tests/pytest/package_manager/test_nuget.py +++ b/tests/pytest/package_manager/test_nuget.py @@ -9,7 +9,7 @@ "fosslight_dependency -p tests/test_nuget2 -o tests/result/nuget2" ] -DIST_PATH = os.path.join(os.path.abspath(os.sep), "dist", "cli.exe") +DIST_PATH = os.path.join(os.environ.get("TOX_PATH"), "dist", "cli.exe") INPUT_PATH = os.path.join("tests", "test_nuget") OUTPUT_PATH = os.path.join("tests", "result", "nuget1") INPUT_PATH2 = os.path.join("tests", "test_nuget2") diff --git a/tests/pytest/package_manager/test_pub.py b/tests/pytest/package_manager/test_pub.py index 336a7040..97da9e2c 100644 --- a/tests/pytest/package_manager/test_pub.py +++ b/tests/pytest/package_manager/test_pub.py @@ -9,7 +9,7 @@ "fosslight_dependency -p tests/test_exclude -e requirements.txt -o tests/result/exclude" ] -DIST_PATH = os.path.join(os.path.abspath(os.sep), "dist", "cli.exe") +DIST_PATH = os.path.join(os.environ.get("TOX_PATH"), "dist", "cli.exe") INPUT_PATH = os.path.join("tests", "test_pub") OUTPUT_PATH = os.path.join("tests", "result", "pub") INPUT_PATH2 = os.path.join("tests", "test_exclude") diff --git a/tests/pytest/package_manager/test_pypi.py b/tests/pytest/package_manager/test_pypi.py index ff2e5d6c..80a4a4bc 100644 --- a/tests/pytest/package_manager/test_pypi.py +++ b/tests/pytest/package_manager/test_pypi.py @@ -10,7 +10,7 @@ "fosslight_dependency -p tests/test_multi_pypi_npm -o tests/result/multi_pypi_npm -f opossum" ] -DIST_PATH = os.path.join(os.path.abspath(os.sep), "dist", "cli.exe") +DIST_PATH = os.path.join(os.environ.get("TOX_PATH"), "dist", "cli.exe") INPUT_PATH = os.path.join("tests", "test_pypi") OUTPUT_PATH = os.path.join("tests", "result", "pypi") diff --git a/tox.ini b/tox.ini index cc4aaeee..3bc4a747 100644 --- a/tox.ini +++ b/tox.ini @@ -9,6 +9,7 @@ toxworkdir = {toxinidir}/tests/ install_command = pip install {opts} {packages} setenv = PYTHONPATH=. + TOX_PATH={toxinidir} allowlist_externals = {toxinidir}/dist/cli {toxinidir}\dist\cli.exe From 776c86ee22aefc89046ddf52a9eb266efe018428 Mon Sep 17 00:00:00 2001 From: yongjunhong Date: Thu, 26 Sep 2024 15:17:10 +0900 Subject: [PATCH 07/17] Change path separator Signed-off-by: yongjunhong Change path separator Signed-off-by: yongjunhong --- tox.ini | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tox.ini b/tox.ini index 3bc4a747..744e677c 100644 --- a/tox.ini +++ b/tox.ini @@ -43,8 +43,8 @@ commands = [testenv:run_windows] deps = - -r{toxinidir}/requirements-dev.txt + -r{toxinidir}\requirements-dev.txt commands = # Test for making excutable file - pyinstaller --onefile cli.py -n cli --additional-hooks-dir=hooks --add-binary=src/fosslight_dependency/third_party/askalono/askalono.exe:third_party/askalono --add-binary=LICENSE:LICENSES --add-binary=LICENSES/LicenseRef-3rd_party_licenses.txt:LICENSES --collect-datas fosslight_util --hidden-import=_cffi_backend - pytest tests/ -k "test_windows" + pyinstaller --onefile cli.py -n cli --additional-hooks-dir=hooks --add-binary=src\fosslight_dependency\third_party\askalono\askalono.exe:third_party\askalono --add-binary=LICENSE:LICENSES --add-binary=LICENSES\LicenseRef-3rd_party_licenses.txt:LICENSES --collect-datas fosslight_util --hidden-import=_cffi_backend + pytest tests\ -k "test_windows" From 9b6bb9a003cac873bad2bc7bd113a4ab4e39cf1f Mon Sep 17 00:00:00 2001 From: yongjunhong Date: Thu, 26 Sep 2024 15:53:21 +0900 Subject: [PATCH 08/17] Fix commands in tox Signed-off-by: yongjunhong --- tests/pytest/package_manager/test_cocoapods.py | 14 -------------- tests/pytest/package_manager/test_go.py | 0 tests/pytest/package_manager/test_swift.py | 0 tests/pytest/package_manager/test_unity.py | 0 tox.ini | 4 ++-- 5 files changed, 2 insertions(+), 16 deletions(-) delete mode 100644 tests/pytest/package_manager/test_cocoapods.py delete mode 100644 tests/pytest/package_manager/test_go.py delete mode 100644 tests/pytest/package_manager/test_swift.py delete mode 100644 tests/pytest/package_manager/test_unity.py diff --git a/tests/pytest/package_manager/test_cocoapods.py b/tests/pytest/package_manager/test_cocoapods.py deleted file mode 100644 index b5b00731..00000000 --- a/tests/pytest/package_manager/test_cocoapods.py +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# Copyright (c) 2021 LG Electronics Inc. -# SPDX-License-Identifier: Apache-2.0 - -UBUNTU_COMMANDS = [ - "fosslight_dependency -p tests/test_cocoapods -o tests/result/cocoapods -m cocoapods" -] - - -def test_ubuntu(run_command): - for command in UBUNTU_COMMANDS: - return_code, stdout, stderr = run_command(command) - assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" diff --git a/tests/pytest/package_manager/test_go.py b/tests/pytest/package_manager/test_go.py deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/pytest/package_manager/test_swift.py b/tests/pytest/package_manager/test_swift.py deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/pytest/package_manager/test_unity.py b/tests/pytest/package_manager/test_unity.py deleted file mode 100644 index e69de29b..00000000 diff --git a/tox.ini b/tox.ini index 744e677c..76a18e04 100644 --- a/tox.ini +++ b/tox.ini @@ -39,7 +39,7 @@ deps = commands = # Test for PEP8 pytest -v --flake8 - pytest tests/ -k "test_ubuntu" + pytest -k "test_ubuntu" tests/ [testenv:run_windows] deps = @@ -47,4 +47,4 @@ deps = commands = # Test for making excutable file pyinstaller --onefile cli.py -n cli --additional-hooks-dir=hooks --add-binary=src\fosslight_dependency\third_party\askalono\askalono.exe:third_party\askalono --add-binary=LICENSE:LICENSES --add-binary=LICENSES\LicenseRef-3rd_party_licenses.txt:LICENSES --collect-datas fosslight_util --hidden-import=_cffi_backend - pytest tests\ -k "test_windows" + pytest -k "test_windows" tests\ From 30f7c362177fa6584db5fe8759bb2f5912b2a72c Mon Sep 17 00:00:00 2001 From: yongjunhong Date: Thu, 26 Sep 2024 16:06:04 +0900 Subject: [PATCH 09/17] Add license information Signed-off-by: yongjunhong --- tests/pytest/conftest.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/pytest/conftest.py b/tests/pytest/conftest.py index 24e304dd..6264c121 100644 --- a/tests/pytest/conftest.py +++ b/tests/pytest/conftest.py @@ -1,3 +1,8 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2021 LG Electronics Inc. +# SPDX-License-Identifier: Apache-2.0 + import pytest import subprocess From b8c8c3f6cfe0a324c94a780916850993197eb4d8 Mon Sep 17 00:00:00 2001 From: yongjunhong Date: Thu, 26 Sep 2024 16:07:50 +0900 Subject: [PATCH 10/17] Add custom marker for window and ubuntu Signed-off-by: yongjunhong --- requirements.txt | 3 ++- tests/pytest/package_manager/test_android.py | 5 ++++- .../{test_carthage.py => test_cocoapods.py} | 4 +++- tests/pytest/package_manager/test_gradle.py | 3 +++ tests/pytest/package_manager/test_helm.py | 2 ++ tests/pytest/package_manager/test_maven.py | 5 ++++- tests/pytest/package_manager/test_npm.py | 2 ++ tests/pytest/package_manager/test_nuget.py | 5 ++++- tests/pytest/package_manager/test_pub.py | 5 ++++- tests/pytest/package_manager/test_pypi.py | 5 ++++- tox.ini | 9 +++++---- 11 files changed, 37 insertions(+), 11 deletions(-) rename tests/pytest/package_manager/{test_carthage.py => test_cocoapods.py} (75%) diff --git a/requirements.txt b/requirements.txt index 8b6fec93..ffa0bd07 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,4 +10,5 @@ requirements-parser defusedxml packageurl-python igraph -matplotlib \ No newline at end of file +matplotlib +pytest \ No newline at end of file diff --git a/tests/pytest/package_manager/test_android.py b/tests/pytest/package_manager/test_android.py index 482335f6..47d59ebc 100644 --- a/tests/pytest/package_manager/test_android.py +++ b/tests/pytest/package_manager/test_android.py @@ -2,7 +2,8 @@ # -*- coding: utf-8 -*- # Copyright (c) 2021 LG Electronics Inc. # SPDX-License-Identifier: Apache-2.0 -import os.path +import os +import pytest UBUNTU_COMMANDS = [ "fosslight_dependency -p tests/test_android -o tests/result/android -m android" @@ -15,12 +16,14 @@ WINDOW_COMMANDS = [f"{DIST_PATH} -p {INPUT_PATH} -o {OUTPUT_PATH}"] +@pytest.mark.ubuntu def test_ubuntu(run_command): for command in UBUNTU_COMMANDS: return_code, stdout, stderr = run_command(command) assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" +@pytest.mark.windows def test_windows(run_command): for command in WINDOW_COMMANDS: return_code, stdout, stderr = run_command(command) diff --git a/tests/pytest/package_manager/test_carthage.py b/tests/pytest/package_manager/test_cocoapods.py similarity index 75% rename from tests/pytest/package_manager/test_carthage.py rename to tests/pytest/package_manager/test_cocoapods.py index 04d5c30c..3b56fd3e 100644 --- a/tests/pytest/package_manager/test_carthage.py +++ b/tests/pytest/package_manager/test_cocoapods.py @@ -2,12 +2,14 @@ # -*- coding: utf-8 -*- # Copyright (c) 2021 LG Electronics Inc. # SPDX-License-Identifier: Apache-2.0 +import pytest UBUNTU_COMMANDS = [ - "fosslight_dependency -p tests/test_carthage -o tests/result/carthage -m carthage" + "fosslight_dependency -p tests/test_cocoapods -o tests/result/cocoapods -m cocoapods" ] +@pytest.mark.ubuntu def test_ubuntu(run_command): for command in UBUNTU_COMMANDS: return_code, stdout, stderr = run_command(command) diff --git a/tests/pytest/package_manager/test_gradle.py b/tests/pytest/package_manager/test_gradle.py index f4632093..9b55dcbf 100644 --- a/tests/pytest/package_manager/test_gradle.py +++ b/tests/pytest/package_manager/test_gradle.py @@ -3,6 +3,7 @@ # Copyright (c) 2021 LG Electronics Inc. # SPDX-License-Identifier: Apache-2.0 import os +import pytest UBUNTU_COMMANDS = [ "fosslight_dependency -p tests/test_gradle/jib -o tests/result/gradle", @@ -21,12 +22,14 @@ ] +@pytest.mark.ubuntu def test_ubuntu(run_command): for command in UBUNTU_COMMANDS: return_code, stdout, stderr = run_command(command) assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" +@pytest.mark.windows def test_windows(run_command): for command in WINDOW_COMMANDS: return_code, stdout, stderr = run_command(command) diff --git a/tests/pytest/package_manager/test_helm.py b/tests/pytest/package_manager/test_helm.py index 106c1f35..e8b26310 100644 --- a/tests/pytest/package_manager/test_helm.py +++ b/tests/pytest/package_manager/test_helm.py @@ -2,12 +2,14 @@ # -*- coding: utf-8 -*- # Copyright (c) 2021 LG Electronics Inc. # SPDX-License-Identifier: Apache-2.0 +import pytest UBUNTU_COMMANDS = [ "fosslight_dependency -p tests/test_helm -o tests/result/helm -m helm" ] +@pytest.mark.ubuntu def test_ubuntu(run_command): for command in UBUNTU_COMMANDS: return_code, stdout, stderr = run_command(command) diff --git a/tests/pytest/package_manager/test_maven.py b/tests/pytest/package_manager/test_maven.py index 9b19fb25..d7995cfb 100644 --- a/tests/pytest/package_manager/test_maven.py +++ b/tests/pytest/package_manager/test_maven.py @@ -2,7 +2,8 @@ # -*- coding: utf-8 -*- # Copyright (c) 2021 LG Electronics Inc. # SPDX-License-Identifier: Apache-2.0 -import os.path +import os +import pytest UBUNTU_COMMANDS = [ "fosslight_dependency -p tests/test_maven1/lombok.maven -o tests/result/maven1", @@ -16,12 +17,14 @@ WINDOW_COMMANDS = [f"{DIST_PATH} -p {INPUT_PATH} -o {OUTPUT_PATH} -m maven"] +@pytest.mark.ubuntu def test_ubuntu(run_command): for command in UBUNTU_COMMANDS: return_code, stdout, stderr = run_command(command) assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" +@pytest.mark.windows def test_windows(run_command): for command in WINDOW_COMMANDS: return_code, stdout, stderr = run_command(command) diff --git a/tests/pytest/package_manager/test_npm.py b/tests/pytest/package_manager/test_npm.py index e92ab1db..137fcf1d 100644 --- a/tests/pytest/package_manager/test_npm.py +++ b/tests/pytest/package_manager/test_npm.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- # Copyright (c) 2021 LG Electronics Inc. # SPDX-License-Identifier: Apache-2.0 +import pytest UBUNTU_COMMANDS = [ "fosslight_dependency -p tests/test_npm1 -o tests/result/npm1", @@ -9,6 +10,7 @@ ] +@pytest.mark.ubuntu def test_ubuntu(run_command): for command in UBUNTU_COMMANDS: return_code, stdout, stderr = run_command(command) diff --git a/tests/pytest/package_manager/test_nuget.py b/tests/pytest/package_manager/test_nuget.py index cabafe9a..72bc1fa5 100644 --- a/tests/pytest/package_manager/test_nuget.py +++ b/tests/pytest/package_manager/test_nuget.py @@ -2,7 +2,8 @@ # -*- coding: utf-8 -*- # Copyright (c) 2021 LG Electronics Inc. # SPDX-License-Identifier: Apache-2.0 -import os.path +import os +import pytest UBUNTU_COMMANDS = [ "fosslight_dependency -p tests/test_nuget -o tests/result/nuget1", @@ -21,12 +22,14 @@ ] +@pytest.mark.ubuntu def test_ubuntu(run_command): for command in UBUNTU_COMMANDS: return_code, stdout, stderr = run_command(command) assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" +@pytest.mark.windows def test_windows(run_command): for command in WINDOW_COMMANDS: return_code, stdout, stderr = run_command(command) diff --git a/tests/pytest/package_manager/test_pub.py b/tests/pytest/package_manager/test_pub.py index 97da9e2c..2d6f6fc4 100644 --- a/tests/pytest/package_manager/test_pub.py +++ b/tests/pytest/package_manager/test_pub.py @@ -2,7 +2,8 @@ # -*- coding: utf-8 -*- # Copyright (c) 2021 LG Electronics Inc. # SPDX-License-Identifier: Apache-2.0 -import os.path +import os +import pytest UBUNTU_COMMANDS = [ "fosslight_dependency -p tests/test_pub -o tests/result/pub", @@ -22,12 +23,14 @@ ] +@pytest.mark.ubuntu def test_ubuntu(run_command): for command in UBUNTU_COMMANDS: return_code, stdout, stderr = run_command(command) assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" +@pytest.mark.windows def test_windows(run_command): for command in WINDOW_COMMANDS: return_code, stdout, stderr = run_command(command) diff --git a/tests/pytest/package_manager/test_pypi.py b/tests/pytest/package_manager/test_pypi.py index 80a4a4bc..c147e6b7 100644 --- a/tests/pytest/package_manager/test_pypi.py +++ b/tests/pytest/package_manager/test_pypi.py @@ -2,7 +2,8 @@ # -*- coding: utf-8 -*- # Copyright (c) 2021 LG Electronics Inc. # SPDX-License-Identifier: Apache-2.0 -import os.path +import os +import pytest UBUNTU_COMMANDS = [ "fosslight_dependency -p tests/test_pypi -o tests/result/pypi", @@ -17,12 +18,14 @@ WINDOW_COMMANDS = [f"{DIST_PATH} -p {INPUT_PATH} -o {OUTPUT_PATH}"] +@pytest.mark.ubuntu def test_ubuntu(run_command): for command in UBUNTU_COMMANDS: return_code, stdout, stderr = run_command(command) assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" +@pytest.mark.windows def test_windows(run_command): for command in WINDOW_COMMANDS: return_code, stdout, stderr = run_command(command) diff --git a/tox.ini b/tox.ini index 76a18e04..8db09f9f 100644 --- a/tox.ini +++ b/tox.ini @@ -16,6 +16,9 @@ allowlist_externals = [pytest] filterwarnings = ignore::DeprecationWarning +markers = + ubuntu: Test for Ubuntu + windows: Test for Windows [flake8] max-line-length = 130 @@ -37,9 +40,7 @@ commands = deps = -r{toxinidir}/requirements-dev.txt commands = - # Test for PEP8 - pytest -v --flake8 - pytest -k "test_ubuntu" tests/ + pytest -m "ubuntu" [testenv:run_windows] deps = @@ -47,4 +48,4 @@ deps = commands = # Test for making excutable file pyinstaller --onefile cli.py -n cli --additional-hooks-dir=hooks --add-binary=src\fosslight_dependency\third_party\askalono\askalono.exe:third_party\askalono --add-binary=LICENSE:LICENSES --add-binary=LICENSES\LicenseRef-3rd_party_licenses.txt:LICENSES --collect-datas fosslight_util --hidden-import=_cffi_backend - pytest -k "test_windows" tests\ + pytest -m "windows" From 36952e7a6d7c98525dfb7f56d038565c4851aebc Mon Sep 17 00:00:00 2001 From: yongjunhong Date: Thu, 26 Sep 2024 16:42:35 +0900 Subject: [PATCH 11/17] Add flake8 test Signed-off-by: yongjunhong --- tests/pytest/conftest.py | 1 - tox.ini | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pytest/conftest.py b/tests/pytest/conftest.py index 6264c121..9750d0ca 100644 --- a/tests/pytest/conftest.py +++ b/tests/pytest/conftest.py @@ -2,7 +2,6 @@ # -*- coding: utf-8 -*- # Copyright (c) 2021 LG Electronics Inc. # SPDX-License-Identifier: Apache-2.0 - import pytest import subprocess diff --git a/tox.ini b/tox.ini index 8db09f9f..75361b8e 100644 --- a/tox.ini +++ b/tox.ini @@ -49,3 +49,4 @@ commands = # Test for making excutable file pyinstaller --onefile cli.py -n cli --additional-hooks-dir=hooks --add-binary=src\fosslight_dependency\third_party\askalono\askalono.exe:third_party\askalono --add-binary=LICENSE:LICENSES --add-binary=LICENSES\LicenseRef-3rd_party_licenses.txt:LICENSES --collect-datas fosslight_util --hidden-import=_cffi_backend pytest -m "windows" + pytest -v --flake8 From 8a66741d68a8f49cfc10da692542bf1e0e8c9946 Mon Sep 17 00:00:00 2001 From: yongjunhong Date: Sun, 29 Sep 2024 21:56:29 +0900 Subject: [PATCH 12/17] Add blank line Signed-off-by: yongjunhong --- tests/pytest/package_manager/test_nuget.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pytest/package_manager/test_nuget.py b/tests/pytest/package_manager/test_nuget.py index 72bc1fa5..0024e655 100644 --- a/tests/pytest/package_manager/test_nuget.py +++ b/tests/pytest/package_manager/test_nuget.py @@ -33,4 +33,4 @@ def test_ubuntu(run_command): def test_windows(run_command): for command in WINDOW_COMMANDS: return_code, stdout, stderr = run_command(command) - assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" \ No newline at end of file + assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" From adc3862e06292cde6ecfb9c328d59f7adb17d34b Mon Sep 17 00:00:00 2001 From: yongjunhong Date: Sun, 29 Sep 2024 23:10:37 +0900 Subject: [PATCH 13/17] Refactor tests Signed-off-by: yongjunhong --- tests/pytest/conftest.py | 40 ++++++++++++++--- tests/pytest/package_manager/test_android.py | 33 +++++++------- .../pytest/package_manager/test_cocoapods.py | 18 ++++---- tests/pytest/package_manager/test_gradle.py | 41 ++++++++---------- tests/pytest/package_manager/test_helm.py | 18 ++++---- tests/pytest/package_manager/test_maven.py | 35 +++++++-------- tests/pytest/package_manager/test_npm.py | 20 +++++---- tests/pytest/package_manager/test_nuget.py | 36 ++++++++-------- tests/pytest/package_manager/test_pub.py | 43 +++++++++---------- tests/pytest/package_manager/test_pypi.py | 37 ++++++++-------- 10 files changed, 176 insertions(+), 145 deletions(-) diff --git a/tests/pytest/conftest.py b/tests/pytest/conftest.py index 9750d0ca..69641f17 100644 --- a/tests/pytest/conftest.py +++ b/tests/pytest/conftest.py @@ -2,13 +2,39 @@ # -*- coding: utf-8 -*- # Copyright (c) 2021 LG Electronics Inc. # SPDX-License-Identifier: Apache-2.0 +import os +import shutil import pytest -import subprocess +set_up_directories = [ + "tests/result/android", + "tests/result/cocoapods", + "tests/result/exclude", + "tests/result/gradle", + "tests/result/gradle2", + "tests/result/helm", + "tests/result/maven1", + "tests/result/maven2", + "tests/result/multi_pypi_npm", + "tests/result/npm1", + "tests/result/npm2", + "tests/result/nuget1", + "tests/result/nuget2", + "tests/result/pub", + "tests/result/pypi", +] -@pytest.fixture -def run_command(): - def _run_command(command): - result = subprocess.run(command, shell=True, capture_output=True, text=True) - return result.returncode, result.stdout, result.stderr - return _run_command +remove_directories = set_up_directories + + +@pytest.fixture(scope="session", autouse=True) +def setup_test_result_dir_and_teardown(): + print("==============setup==============") + for directory in set_up_directories: + os.makedirs(directory, exist_ok=True) + + yield + + print("==============tearDown==============") + for directory in remove_directories: + shutil.rmtree(directory) diff --git a/tests/pytest/package_manager/test_android.py b/tests/pytest/package_manager/test_android.py index 47d59ebc..e36b7cc0 100644 --- a/tests/pytest/package_manager/test_android.py +++ b/tests/pytest/package_manager/test_android.py @@ -4,27 +4,28 @@ # SPDX-License-Identifier: Apache-2.0 import os import pytest - -UBUNTU_COMMANDS = [ - "fosslight_dependency -p tests/test_android -o tests/result/android -m android" -] +import subprocess DIST_PATH = os.path.join(os.environ.get("TOX_PATH"), "dist", "cli.exe") -INPUT_PATH = os.path.join("tests", "test_android", "sunflower") -OUTPUT_PATH = os.path.join("tests", "result", "android") - -WINDOW_COMMANDS = [f"{DIST_PATH} -p {INPUT_PATH} -o {OUTPUT_PATH}"] +@pytest.mark.parametrize("input_path, output_path, extra_args", [ + ("tests/test_android", "tests/result/android", "-m android") +]) @pytest.mark.ubuntu -def test_ubuntu(run_command): - for command in UBUNTU_COMMANDS: - return_code, stdout, stderr = run_command(command) - assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" +def test_ubuntu(input_path, output_path, extra_args): + command = f"fosslight_dependency -p {input_path} -o {output_path} {extra_args}" + result = subprocess.run(command, shell=True, capture_output=True, text=True) + assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}" + assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}" +@pytest.mark.parametrize("input_path, output_path", [ + (os.path.join("tests", "test_android", "sunflower"), os.path.join("tests", "result", "android")) +]) @pytest.mark.windows -def test_windows(run_command): - for command in WINDOW_COMMANDS: - return_code, stdout, stderr = run_command(command) - assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" +def test_windows(input_path, output_path): + command = f"{DIST_PATH} -p {input_path} -o {output_path}" + result = subprocess.run(command, shell=True, capture_output=True, text=True) + assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}" + assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}" diff --git a/tests/pytest/package_manager/test_cocoapods.py b/tests/pytest/package_manager/test_cocoapods.py index 3b56fd3e..4e518758 100644 --- a/tests/pytest/package_manager/test_cocoapods.py +++ b/tests/pytest/package_manager/test_cocoapods.py @@ -2,15 +2,17 @@ # -*- coding: utf-8 -*- # Copyright (c) 2021 LG Electronics Inc. # SPDX-License-Identifier: Apache-2.0 +import os import pytest - -UBUNTU_COMMANDS = [ - "fosslight_dependency -p tests/test_cocoapods -o tests/result/cocoapods -m cocoapods" -] +import subprocess +@pytest.mark.parametrize("input_path, output_path, extra_args", [ + ("tests/test_cocoapods", "tests/result/cocoapods", "-m cocoapods") +]) @pytest.mark.ubuntu -def test_ubuntu(run_command): - for command in UBUNTU_COMMANDS: - return_code, stdout, stderr = run_command(command) - assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" +def test_ubuntu(input_path, output_path, extra_args): + command = f"fosslight_dependency -p {input_path} -o {output_path} {extra_args}" + result = subprocess.run(command, shell=True, capture_output=True, text=True) + assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}" + assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}" diff --git a/tests/pytest/package_manager/test_gradle.py b/tests/pytest/package_manager/test_gradle.py index 9b55dcbf..7173cff3 100644 --- a/tests/pytest/package_manager/test_gradle.py +++ b/tests/pytest/package_manager/test_gradle.py @@ -4,33 +4,30 @@ # SPDX-License-Identifier: Apache-2.0 import os import pytest - -UBUNTU_COMMANDS = [ - "fosslight_dependency -p tests/test_gradle/jib -o tests/result/gradle", - "fosslight_dependency -p tests/test_gradle2 -o tests/result/gradle2" -] +import subprocess DIST_PATH = os.path.join(os.environ.get("TOX_PATH"), "dist", "cli.exe") -INPUT_PATH = os.path.join("tests", "test_gradle", "jib") -OUTPUT_PATH = os.path.join("tests", "result", "gradle") -INPUT_PATH2 = os.path.join("tests", "test_gradle2") -OUTPUT_PATH2 = os.path.join("tests", "result", "gradle2") - -WINDOW_COMMANDS = [ - f"{DIST_PATH} -p {INPUT_PATH} -o {OUTPUT_PATH} -m gradle", - f"{DIST_PATH} -p {INPUT_PATH2} -o {OUTPUT_PATH2} -m gradle", -] +@pytest.mark.parametrize("input_path, output_path", [ + ("tests/test_gradle/jib", "tests/result/gradle"), + ("tests/test_gradle2", "tests/result/gradle2") +]) @pytest.mark.ubuntu -def test_ubuntu(run_command): - for command in UBUNTU_COMMANDS: - return_code, stdout, stderr = run_command(command) - assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" +def test_ubuntu(input_path, output_path): + command = f"fosslight_dependency -p {input_path} -o {output_path}" + result = subprocess.run(command, shell=True, capture_output=True, text=True) + assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}" + assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}" +@pytest.mark.parametrize("input_path, output_path", [ + (os.path.join("tests", "test_gradle", "jib"), os.path.join("tests", "result", "gradle")), + (os.path.join("tests", "test_gradle2"), os.path.join("tests", "result", "gradle2")) +]) @pytest.mark.windows -def test_windows(run_command): - for command in WINDOW_COMMANDS: - return_code, stdout, stderr = run_command(command) - assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" +def test_windows(input_path, output_path): + command = f"{DIST_PATH} -p {input_path} -o {output_path} -m gradle" + result = subprocess.run(command, shell=True, capture_output=True, text=True) + assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}" + assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}" diff --git a/tests/pytest/package_manager/test_helm.py b/tests/pytest/package_manager/test_helm.py index e8b26310..1a4fd0f7 100644 --- a/tests/pytest/package_manager/test_helm.py +++ b/tests/pytest/package_manager/test_helm.py @@ -2,15 +2,17 @@ # -*- coding: utf-8 -*- # Copyright (c) 2021 LG Electronics Inc. # SPDX-License-Identifier: Apache-2.0 +import os import pytest - -UBUNTU_COMMANDS = [ - "fosslight_dependency -p tests/test_helm -o tests/result/helm -m helm" -] +import subprocess +@pytest.mark.parametrize("input_path, output_path, extra_args", [ + ("tests/test_helm", "tests/result/helm", "-m helm") +]) @pytest.mark.ubuntu -def test_ubuntu(run_command): - for command in UBUNTU_COMMANDS: - return_code, stdout, stderr = run_command(command) - assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" +def test_ubuntu(input_path, output_path, extra_args): + command = f"fosslight_dependency -p {input_path} -o {output_path} {extra_args}" + result = subprocess.run(command, shell=True, capture_output=True, text=True) + assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}" + assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}" diff --git a/tests/pytest/package_manager/test_maven.py b/tests/pytest/package_manager/test_maven.py index d7995cfb..2892e3ec 100644 --- a/tests/pytest/package_manager/test_maven.py +++ b/tests/pytest/package_manager/test_maven.py @@ -4,28 +4,29 @@ # SPDX-License-Identifier: Apache-2.0 import os import pytest - -UBUNTU_COMMANDS = [ - "fosslight_dependency -p tests/test_maven1/lombok.maven -o tests/result/maven1", - "fosslight_dependency -p tests/test_maven2 -o tests/result/maven2" -] +import subprocess DIST_PATH = os.path.join(os.environ.get("TOX_PATH"), "dist", "cli.exe") -INPUT_PATH = os.path.join("tests", "test_maven2") -OUTPUT_PATH = os.path.join("tests", "result", "maven2") - -WINDOW_COMMANDS = [f"{DIST_PATH} -p {INPUT_PATH} -o {OUTPUT_PATH} -m maven"] +@pytest.mark.parametrize("input_path, output_path", [ + ("tests/test_maven1/lombok.maven", "tests/result/maven1"), + ("tests/test_maven2", "tests/result/maven2") +]) @pytest.mark.ubuntu -def test_ubuntu(run_command): - for command in UBUNTU_COMMANDS: - return_code, stdout, stderr = run_command(command) - assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" +def test_ubuntu(input_path, output_path): + command = f"fosslight_dependency -p {input_path} -o {output_path}" + result = subprocess.run(command, shell=True, capture_output=True, text=True) + assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}" + assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}" +@pytest.mark.parametrize("input_path, output_path", [ + (os.path.join("tests", "test_maven2"), os.path.join("tests", "result", "maven2")) +]) @pytest.mark.windows -def test_windows(run_command): - for command in WINDOW_COMMANDS: - return_code, stdout, stderr = run_command(command) - assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" +def test_windows(input_path, output_path): + command = f"{DIST_PATH} -p {input_path} -o {output_path} -m maven" + result = subprocess.run(command, shell=True, capture_output=True, text=True) + assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}" + assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}" diff --git a/tests/pytest/package_manager/test_npm.py b/tests/pytest/package_manager/test_npm.py index 137fcf1d..b9914001 100644 --- a/tests/pytest/package_manager/test_npm.py +++ b/tests/pytest/package_manager/test_npm.py @@ -2,16 +2,18 @@ # -*- coding: utf-8 -*- # Copyright (c) 2021 LG Electronics Inc. # SPDX-License-Identifier: Apache-2.0 +import os import pytest - -UBUNTU_COMMANDS = [ - "fosslight_dependency -p tests/test_npm1 -o tests/result/npm1", - "fosslight_dependency -p tests/test_npm2 -o tests/result/npm2 -m npm" -] +import subprocess +@pytest.mark.parametrize("input_path, output_path, extra_args", [ + ("tests/test_npm1", "tests/result/npm1", ""), + ("tests/test_npm2", "tests/result/npm2", "-m npm") +]) @pytest.mark.ubuntu -def test_ubuntu(run_command): - for command in UBUNTU_COMMANDS: - return_code, stdout, stderr = run_command(command) - assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" +def test_ubuntu(input_path, output_path, extra_args): + command = f"fosslight_dependency -p {input_path} -o {output_path} {extra_args}" + result = subprocess.run(command, shell=True, capture_output=True, text=True) + assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}" + assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}" diff --git a/tests/pytest/package_manager/test_nuget.py b/tests/pytest/package_manager/test_nuget.py index 0024e655..f0e26c56 100644 --- a/tests/pytest/package_manager/test_nuget.py +++ b/tests/pytest/package_manager/test_nuget.py @@ -4,6 +4,7 @@ # SPDX-License-Identifier: Apache-2.0 import os import pytest +import subprocess UBUNTU_COMMANDS = [ "fosslight_dependency -p tests/test_nuget -o tests/result/nuget1", @@ -11,26 +12,27 @@ ] DIST_PATH = os.path.join(os.environ.get("TOX_PATH"), "dist", "cli.exe") -INPUT_PATH = os.path.join("tests", "test_nuget") -OUTPUT_PATH = os.path.join("tests", "result", "nuget1") -INPUT_PATH2 = os.path.join("tests", "test_nuget2") -OUTPUT_PATH2 = os.path.join("tests", "result", "nuget2") - -WINDOW_COMMANDS = [ - f"{DIST_PATH} -p {INPUT_PATH} -o {OUTPUT_PATH}", - f"{DIST_PATH} -p {INPUT_PATH2} -o {OUTPUT_PATH2}" -] +@pytest.mark.parametrize("input_path, output_path", [ + ("tests/test_nuget", "tests/result/nuget1"), + ("tests/test_nuget2", "tests/result/nuget2") +]) @pytest.mark.ubuntu -def test_ubuntu(run_command): - for command in UBUNTU_COMMANDS: - return_code, stdout, stderr = run_command(command) - assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" +def test_ubuntu(input_path, output_path): + command = f"fosslight_dependency -p {input_path} -o {output_path}" + result = subprocess.run(command, shell=True, capture_output=True, text=True) + assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}" + assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}" +@pytest.mark.parametrize("input_path, output_path", [ + (os.path.join("tests", "test_nuget"), os.path.join("tests", "result", "nuget1")), + (os.path.join("tests", "test_nuget2"), os.path.join("tests", "result", "nuget2")) +]) @pytest.mark.windows -def test_windows(run_command): - for command in WINDOW_COMMANDS: - return_code, stdout, stderr = run_command(command) - assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" +def test_windows(input_path, output_path): + command = f"{DIST_PATH} -p {input_path} -o {output_path}" + result = subprocess.run(command, shell=True, capture_output=True, text=True) + assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}" + assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}" diff --git a/tests/pytest/package_manager/test_pub.py b/tests/pytest/package_manager/test_pub.py index 2d6f6fc4..d436177e 100644 --- a/tests/pytest/package_manager/test_pub.py +++ b/tests/pytest/package_manager/test_pub.py @@ -4,34 +4,31 @@ # SPDX-License-Identifier: Apache-2.0 import os import pytest - -UBUNTU_COMMANDS = [ - "fosslight_dependency -p tests/test_pub -o tests/result/pub", - "fosslight_dependency -p tests/test_exclude -e requirements.txt -o tests/result/exclude" -] +import subprocess DIST_PATH = os.path.join(os.environ.get("TOX_PATH"), "dist", "cli.exe") -INPUT_PATH = os.path.join("tests", "test_pub") -OUTPUT_PATH = os.path.join("tests", "result", "pub") -INPUT_PATH2 = os.path.join("tests", "test_exclude") -OUTPUT_PATH2 = os.path.join("tests", "result", "exclude") - -WINDOW_COMMANDS = [ - f"{DIST_PATH} -p {INPUT_PATH} -o {OUTPUT_PATH}", - f"{DIST_PATH} -p {INPUT_PATH} -o {OUTPUT_PATH} -f opossum", - f"{DIST_PATH} -p {INPUT_PATH} -e requirements.txt -o {OUTPUT_PATH}" -] +@pytest.mark.parametrize("input_path, output_path", [ + ("tests/test_pub", "tests/result/pub"), + ("tests/test_exclude -e requirements.txt", "tests/result/exclude") +]) @pytest.mark.ubuntu -def test_ubuntu(run_command): - for command in UBUNTU_COMMANDS: - return_code, stdout, stderr = run_command(command) - assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" +def test_ubuntu(input_path, output_path): + command = f"fosslight_dependency -p {input_path} -o {output_path}" + result = subprocess.run(command, shell=True, capture_output=True, text=True) + assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}" + assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}" +@pytest.mark.parametrize("input_path, output_path, extra_args", [ + (os.path.join("tests", "test_pub"), os.path.join("tests", "result", "pub"), ""), + (os.path.join("tests", "test_pub"), os.path.join("tests", "result", "pub"), "-f opossum"), + (os.path.join("tests", "test_exclude") + " -e requirements.txt", os.path.join("tests", "result", "exclude"), "") +]) @pytest.mark.windows -def test_windows(run_command): - for command in WINDOW_COMMANDS: - return_code, stdout, stderr = run_command(command) - assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" +def test_windows(input_path, output_path, extra_args): + command = f"{DIST_PATH} -p {input_path} -o {output_path} {extra_args}" + result = subprocess.run(command, shell=True, capture_output=True, text=True) + assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}" + assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}" diff --git a/tests/pytest/package_manager/test_pypi.py b/tests/pytest/package_manager/test_pypi.py index c147e6b7..7c67c227 100644 --- a/tests/pytest/package_manager/test_pypi.py +++ b/tests/pytest/package_manager/test_pypi.py @@ -4,29 +4,30 @@ # SPDX-License-Identifier: Apache-2.0 import os import pytest - -UBUNTU_COMMANDS = [ - "fosslight_dependency -p tests/test_pypi -o tests/result/pypi", - "fosslight_dependency -p tests/test_multi_pypi_npm -o tests/result/multi_pypi_npm", - "fosslight_dependency -p tests/test_multi_pypi_npm -o tests/result/multi_pypi_npm -f opossum" -] +import subprocess DIST_PATH = os.path.join(os.environ.get("TOX_PATH"), "dist", "cli.exe") -INPUT_PATH = os.path.join("tests", "test_pypi") -OUTPUT_PATH = os.path.join("tests", "result", "pypi") - -WINDOW_COMMANDS = [f"{DIST_PATH} -p {INPUT_PATH} -o {OUTPUT_PATH}"] +@pytest.mark.parametrize("input_path, output_path, extra_args", [ + ("tests/test_pypi", "tests/result/pypi", ""), + ("tests/test_multi_pypi_npm", "tests/result/multi_pypi_npm", ""), + ("tests/test_multi_pypi_npm", "tests/result/multi_pypi_npm", "-f opossum") +]) @pytest.mark.ubuntu -def test_ubuntu(run_command): - for command in UBUNTU_COMMANDS: - return_code, stdout, stderr = run_command(command) - assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" +def test_ubuntu(input_path, output_path, extra_args): + command = f"fosslight_dependency -p {input_path} -o {output_path} {extra_args}" + result = subprocess.run(command, shell=True, capture_output=True, text=True) + assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}" + assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}" +@pytest.mark.parametrize("input_path, output_path", [ + (os.path.join("tests", "test_pypi"), os.path.join("tests", "result", "pypi")) +]) @pytest.mark.windows -def test_windows(run_command): - for command in WINDOW_COMMANDS: - return_code, stdout, stderr = run_command(command) - assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" +def test_windows(input_path, output_path): + command = f"{DIST_PATH} -p {input_path} -o {output_path}" + result = subprocess.run(command, shell=True, capture_output=True, text=True) + assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}" + assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}" From 91ca53d08832bd4ccd6280167171b93d129a0def Mon Sep 17 00:00:00 2001 From: yongjunhong Date: Sun, 29 Sep 2024 23:11:51 +0900 Subject: [PATCH 14/17] Remove comma Signed-off-by: yongjunhong --- tests/pytest/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pytest/conftest.py b/tests/pytest/conftest.py index 69641f17..0638be86 100644 --- a/tests/pytest/conftest.py +++ b/tests/pytest/conftest.py @@ -21,7 +21,7 @@ "tests/result/nuget1", "tests/result/nuget2", "tests/result/pub", - "tests/result/pypi", + "tests/result/pypi" ] remove_directories = set_up_directories From f02c3651ced423d2d16fa6126d848033d7150b4f Mon Sep 17 00:00:00 2001 From: yongjunhong Date: Wed, 2 Oct 2024 11:47:42 +0900 Subject: [PATCH 15/17] Remove shell option Signed-off-by: yongjunhong --- tests/pytest/package_manager/test_android.py | 4 ++-- tests/pytest/package_manager/test_cocoapods.py | 2 +- tests/pytest/package_manager/test_gradle.py | 4 ++-- tests/pytest/package_manager/test_helm.py | 2 +- tests/pytest/package_manager/test_maven.py | 4 ++-- tests/pytest/package_manager/test_npm.py | 2 +- tests/pytest/package_manager/test_nuget.py | 4 ++-- tests/pytest/package_manager/test_pub.py | 4 ++-- tests/pytest/package_manager/test_pypi.py | 4 ++-- 9 files changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/pytest/package_manager/test_android.py b/tests/pytest/package_manager/test_android.py index e36b7cc0..d20f0e70 100644 --- a/tests/pytest/package_manager/test_android.py +++ b/tests/pytest/package_manager/test_android.py @@ -15,7 +15,7 @@ @pytest.mark.ubuntu def test_ubuntu(input_path, output_path, extra_args): command = f"fosslight_dependency -p {input_path} -o {output_path} {extra_args}" - result = subprocess.run(command, shell=True, capture_output=True, text=True) + result = subprocess.run(command, capture_output=True, text=True) assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}" assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}" @@ -26,6 +26,6 @@ def test_ubuntu(input_path, output_path, extra_args): @pytest.mark.windows def test_windows(input_path, output_path): command = f"{DIST_PATH} -p {input_path} -o {output_path}" - result = subprocess.run(command, shell=True, capture_output=True, text=True) + result = subprocess.run(command, capture_output=True, text=True) assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}" assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}" diff --git a/tests/pytest/package_manager/test_cocoapods.py b/tests/pytest/package_manager/test_cocoapods.py index 4e518758..dcf4f82d 100644 --- a/tests/pytest/package_manager/test_cocoapods.py +++ b/tests/pytest/package_manager/test_cocoapods.py @@ -13,6 +13,6 @@ @pytest.mark.ubuntu def test_ubuntu(input_path, output_path, extra_args): command = f"fosslight_dependency -p {input_path} -o {output_path} {extra_args}" - result = subprocess.run(command, shell=True, capture_output=True, text=True) + result = subprocess.run(command, capture_output=True, text=True) assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}" assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}" diff --git a/tests/pytest/package_manager/test_gradle.py b/tests/pytest/package_manager/test_gradle.py index 7173cff3..132bfa81 100644 --- a/tests/pytest/package_manager/test_gradle.py +++ b/tests/pytest/package_manager/test_gradle.py @@ -16,7 +16,7 @@ @pytest.mark.ubuntu def test_ubuntu(input_path, output_path): command = f"fosslight_dependency -p {input_path} -o {output_path}" - result = subprocess.run(command, shell=True, capture_output=True, text=True) + result = subprocess.run(command, capture_output=True, text=True) assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}" assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}" @@ -28,6 +28,6 @@ def test_ubuntu(input_path, output_path): @pytest.mark.windows def test_windows(input_path, output_path): command = f"{DIST_PATH} -p {input_path} -o {output_path} -m gradle" - result = subprocess.run(command, shell=True, capture_output=True, text=True) + result = subprocess.run(command, capture_output=True, text=True) assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}" assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}" diff --git a/tests/pytest/package_manager/test_helm.py b/tests/pytest/package_manager/test_helm.py index 1a4fd0f7..b47031a6 100644 --- a/tests/pytest/package_manager/test_helm.py +++ b/tests/pytest/package_manager/test_helm.py @@ -13,6 +13,6 @@ @pytest.mark.ubuntu def test_ubuntu(input_path, output_path, extra_args): command = f"fosslight_dependency -p {input_path} -o {output_path} {extra_args}" - result = subprocess.run(command, shell=True, capture_output=True, text=True) + result = subprocess.run(command, capture_output=True, text=True) assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}" assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}" diff --git a/tests/pytest/package_manager/test_maven.py b/tests/pytest/package_manager/test_maven.py index 2892e3ec..30450b6e 100644 --- a/tests/pytest/package_manager/test_maven.py +++ b/tests/pytest/package_manager/test_maven.py @@ -16,7 +16,7 @@ @pytest.mark.ubuntu def test_ubuntu(input_path, output_path): command = f"fosslight_dependency -p {input_path} -o {output_path}" - result = subprocess.run(command, shell=True, capture_output=True, text=True) + result = subprocess.run(command, capture_output=True, text=True) assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}" assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}" @@ -27,6 +27,6 @@ def test_ubuntu(input_path, output_path): @pytest.mark.windows def test_windows(input_path, output_path): command = f"{DIST_PATH} -p {input_path} -o {output_path} -m maven" - result = subprocess.run(command, shell=True, capture_output=True, text=True) + result = subprocess.run(command, capture_output=True, text=True) assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}" assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}" diff --git a/tests/pytest/package_manager/test_npm.py b/tests/pytest/package_manager/test_npm.py index b9914001..a4d68d6a 100644 --- a/tests/pytest/package_manager/test_npm.py +++ b/tests/pytest/package_manager/test_npm.py @@ -14,6 +14,6 @@ @pytest.mark.ubuntu def test_ubuntu(input_path, output_path, extra_args): command = f"fosslight_dependency -p {input_path} -o {output_path} {extra_args}" - result = subprocess.run(command, shell=True, capture_output=True, text=True) + result = subprocess.run(command, capture_output=True, text=True) assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}" assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}" diff --git a/tests/pytest/package_manager/test_nuget.py b/tests/pytest/package_manager/test_nuget.py index f0e26c56..b29ec2e1 100644 --- a/tests/pytest/package_manager/test_nuget.py +++ b/tests/pytest/package_manager/test_nuget.py @@ -21,7 +21,7 @@ @pytest.mark.ubuntu def test_ubuntu(input_path, output_path): command = f"fosslight_dependency -p {input_path} -o {output_path}" - result = subprocess.run(command, shell=True, capture_output=True, text=True) + result = subprocess.run(command, capture_output=True, text=True) assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}" assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}" @@ -33,6 +33,6 @@ def test_ubuntu(input_path, output_path): @pytest.mark.windows def test_windows(input_path, output_path): command = f"{DIST_PATH} -p {input_path} -o {output_path}" - result = subprocess.run(command, shell=True, capture_output=True, text=True) + result = subprocess.run(command, capture_output=True, text=True) assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}" assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}" diff --git a/tests/pytest/package_manager/test_pub.py b/tests/pytest/package_manager/test_pub.py index d436177e..65b3f420 100644 --- a/tests/pytest/package_manager/test_pub.py +++ b/tests/pytest/package_manager/test_pub.py @@ -16,7 +16,7 @@ @pytest.mark.ubuntu def test_ubuntu(input_path, output_path): command = f"fosslight_dependency -p {input_path} -o {output_path}" - result = subprocess.run(command, shell=True, capture_output=True, text=True) + result = subprocess.run(command, capture_output=True, text=True) assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}" assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}" @@ -29,6 +29,6 @@ def test_ubuntu(input_path, output_path): @pytest.mark.windows def test_windows(input_path, output_path, extra_args): command = f"{DIST_PATH} -p {input_path} -o {output_path} {extra_args}" - result = subprocess.run(command, shell=True, capture_output=True, text=True) + result = subprocess.run(command, capture_output=True, text=True) assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}" assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}" diff --git a/tests/pytest/package_manager/test_pypi.py b/tests/pytest/package_manager/test_pypi.py index 7c67c227..c923e820 100644 --- a/tests/pytest/package_manager/test_pypi.py +++ b/tests/pytest/package_manager/test_pypi.py @@ -17,7 +17,7 @@ @pytest.mark.ubuntu def test_ubuntu(input_path, output_path, extra_args): command = f"fosslight_dependency -p {input_path} -o {output_path} {extra_args}" - result = subprocess.run(command, shell=True, capture_output=True, text=True) + result = subprocess.run(command, capture_output=True, text=True) assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}" assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}" @@ -28,6 +28,6 @@ def test_ubuntu(input_path, output_path, extra_args): @pytest.mark.windows def test_windows(input_path, output_path): command = f"{DIST_PATH} -p {input_path} -o {output_path}" - result = subprocess.run(command, shell=True, capture_output=True, text=True) + result = subprocess.run(command, capture_output=True, text=True) assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}" assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}" From 48d68c9d2ed39f9b687949b1bc42f2f4363b2045 Mon Sep 17 00:00:00 2001 From: yongjunhong Date: Wed, 2 Oct 2024 16:22:25 +0900 Subject: [PATCH 16/17] Add shell option in ubuntu tests Signed-off-by: yongjunhong --- tests/pytest/package_manager/test_android.py | 2 +- tests/pytest/package_manager/test_cocoapods.py | 2 +- tests/pytest/package_manager/test_gradle.py | 2 +- tests/pytest/package_manager/test_helm.py | 2 +- tests/pytest/package_manager/test_maven.py | 2 +- tests/pytest/package_manager/test_npm.py | 2 +- tests/pytest/package_manager/test_nuget.py | 2 +- tests/pytest/package_manager/test_pub.py | 2 +- tests/pytest/package_manager/test_pypi.py | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/pytest/package_manager/test_android.py b/tests/pytest/package_manager/test_android.py index d20f0e70..52cd5474 100644 --- a/tests/pytest/package_manager/test_android.py +++ b/tests/pytest/package_manager/test_android.py @@ -15,7 +15,7 @@ @pytest.mark.ubuntu def test_ubuntu(input_path, output_path, extra_args): command = f"fosslight_dependency -p {input_path} -o {output_path} {extra_args}" - result = subprocess.run(command, capture_output=True, text=True) + result = subprocess.run(command, shell=True, capture_output=True, text=True) assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}" assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}" diff --git a/tests/pytest/package_manager/test_cocoapods.py b/tests/pytest/package_manager/test_cocoapods.py index dcf4f82d..4e518758 100644 --- a/tests/pytest/package_manager/test_cocoapods.py +++ b/tests/pytest/package_manager/test_cocoapods.py @@ -13,6 +13,6 @@ @pytest.mark.ubuntu def test_ubuntu(input_path, output_path, extra_args): command = f"fosslight_dependency -p {input_path} -o {output_path} {extra_args}" - result = subprocess.run(command, capture_output=True, text=True) + result = subprocess.run(command, shell=True, capture_output=True, text=True) assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}" assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}" diff --git a/tests/pytest/package_manager/test_gradle.py b/tests/pytest/package_manager/test_gradle.py index 132bfa81..35e16c11 100644 --- a/tests/pytest/package_manager/test_gradle.py +++ b/tests/pytest/package_manager/test_gradle.py @@ -16,7 +16,7 @@ @pytest.mark.ubuntu def test_ubuntu(input_path, output_path): command = f"fosslight_dependency -p {input_path} -o {output_path}" - result = subprocess.run(command, capture_output=True, text=True) + result = subprocess.run(command, shell=True, capture_output=True, text=True) assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}" assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}" diff --git a/tests/pytest/package_manager/test_helm.py b/tests/pytest/package_manager/test_helm.py index b47031a6..1a4fd0f7 100644 --- a/tests/pytest/package_manager/test_helm.py +++ b/tests/pytest/package_manager/test_helm.py @@ -13,6 +13,6 @@ @pytest.mark.ubuntu def test_ubuntu(input_path, output_path, extra_args): command = f"fosslight_dependency -p {input_path} -o {output_path} {extra_args}" - result = subprocess.run(command, capture_output=True, text=True) + result = subprocess.run(command, shell=True, capture_output=True, text=True) assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}" assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}" diff --git a/tests/pytest/package_manager/test_maven.py b/tests/pytest/package_manager/test_maven.py index 30450b6e..58f26ab3 100644 --- a/tests/pytest/package_manager/test_maven.py +++ b/tests/pytest/package_manager/test_maven.py @@ -16,7 +16,7 @@ @pytest.mark.ubuntu def test_ubuntu(input_path, output_path): command = f"fosslight_dependency -p {input_path} -o {output_path}" - result = subprocess.run(command, capture_output=True, text=True) + result = subprocess.run(command, shell=True, capture_output=True, text=True) assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}" assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}" diff --git a/tests/pytest/package_manager/test_npm.py b/tests/pytest/package_manager/test_npm.py index a4d68d6a..b9914001 100644 --- a/tests/pytest/package_manager/test_npm.py +++ b/tests/pytest/package_manager/test_npm.py @@ -14,6 +14,6 @@ @pytest.mark.ubuntu def test_ubuntu(input_path, output_path, extra_args): command = f"fosslight_dependency -p {input_path} -o {output_path} {extra_args}" - result = subprocess.run(command, capture_output=True, text=True) + result = subprocess.run(command, shell=True, capture_output=True, text=True) assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}" assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}" diff --git a/tests/pytest/package_manager/test_nuget.py b/tests/pytest/package_manager/test_nuget.py index b29ec2e1..c46f3628 100644 --- a/tests/pytest/package_manager/test_nuget.py +++ b/tests/pytest/package_manager/test_nuget.py @@ -21,7 +21,7 @@ @pytest.mark.ubuntu def test_ubuntu(input_path, output_path): command = f"fosslight_dependency -p {input_path} -o {output_path}" - result = subprocess.run(command, capture_output=True, text=True) + result = subprocess.run(command, shell=True, capture_output=True, text=True) assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}" assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}" diff --git a/tests/pytest/package_manager/test_pub.py b/tests/pytest/package_manager/test_pub.py index 65b3f420..a4a3e900 100644 --- a/tests/pytest/package_manager/test_pub.py +++ b/tests/pytest/package_manager/test_pub.py @@ -16,7 +16,7 @@ @pytest.mark.ubuntu def test_ubuntu(input_path, output_path): command = f"fosslight_dependency -p {input_path} -o {output_path}" - result = subprocess.run(command, capture_output=True, text=True) + result = subprocess.run(command, shell=True, capture_output=True, text=True) assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}" assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}" diff --git a/tests/pytest/package_manager/test_pypi.py b/tests/pytest/package_manager/test_pypi.py index c923e820..2b63fe82 100644 --- a/tests/pytest/package_manager/test_pypi.py +++ b/tests/pytest/package_manager/test_pypi.py @@ -17,7 +17,7 @@ @pytest.mark.ubuntu def test_ubuntu(input_path, output_path, extra_args): command = f"fosslight_dependency -p {input_path} -o {output_path} {extra_args}" - result = subprocess.run(command, capture_output=True, text=True) + result = subprocess.run(command, shell=True, capture_output=True, text=True) assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}" assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}" From 4271610b1bbc1f4a68213ce5c2c1b1395dfc95d5 Mon Sep 17 00:00:00 2001 From: yongjunhong Date: Thu, 3 Oct 2024 18:35:54 +0900 Subject: [PATCH 17/17] Remove useless library in requirements.txt Signed-off-by: yongjunhong --- requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index ffa0bd07..a29061c1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,4 +11,3 @@ defusedxml packageurl-python igraph matplotlib -pytest \ No newline at end of file