Skip to content

Commit ba11f05

Browse files
pombredannekji22AyanSinhaMahapatra
committed
Test that additional license plugin works
This test can run only in the CI and use a new pytest marker. This requires isolation as it installs new license from a new location plugin. Co-authored-by: Kevin Ji <kyji1011@gmail.com> Co-authored-by: Ayan Sinha Mahapatra <ayansmahapatra@gmail.com> Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
1 parent ba9740b commit ba11f05

22 files changed

Lines changed: 309 additions & 84 deletions

azure-pipelines.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,17 @@ jobs:
8383
venv/bin/pytest -vvs --test-suite=all \
8484
tests/licensedcode/test_installed_license_detection.py
8585
86+
# this test runs in isolation because it modifies the actual
87+
# license index with additional licenses provided by a plugin
88+
# and we use the special --test-suite=plugins marker for these
89+
# tests
90+
additional_licenses_plugin: |
91+
venv/bin/pip install tests/licensedcode/data/additional_license_location_provider/plugin/licenses_to_install2
92+
venv/bin/scancode --reindex-licenses
93+
venv/bin/pytest -vvs --test-suite=plugins \
94+
tests/licensedcode/test_additional_license_location_provider.py
95+
96+
8697
- template: etc/ci/azure-posix.yml
8798
parameters:
8899
job_name: ubuntu18_cpython

conftest.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
################################################################################
3939
SLOW_TEST = 'scanslow'
4040
VALIDATION_TEST = 'scanvalidate'
41+
PLUGINS_TEST = 'scanplugins'
4142

4243

4344
def pytest_configure(config):
@@ -53,8 +54,14 @@ def pytest_configure(config):
5354
': Mark a ScanCode test as a validation test, super slow, long running test.',
5455
)
5556

57+
config.addinivalue_line(
58+
'markers',
59+
PLUGINS_TEST +
60+
': Mark a ScanCode test as a special CI test to tests installing additional plugins.',
61+
)
62+
5663

57-
TEST_SUITES = 'standard', 'all', 'validate'
64+
TEST_SUITES = ('standard', 'all', 'validate', 'plugins',)
5865

5966

6067
def pytest_addoption(parser):
@@ -72,9 +79,11 @@ def pytest_addoption(parser):
7279
help='Select which test suite to run: '
7380
'"standard" runs the standard test suite designed to run reasonably fast. '
7481
'"all" runs "standard" and "slow" (long running) tests. '
75-
'"validate" runs all the tests. '
82+
'"validate" runs all the tests, except the "plugins" tests. '
83+
'"plugins" runs special plugins tests. Needs extra setup, and is used only in the CI. '
7684
'Use the @pytest.mark.scanslow marker to mark a test as "slow" test. '
7785
'Use the @pytest.mark.scanvalidate marker to mark a test as a "validate" test.'
86+
'Use the @pytest.mark.scanplugins marker to mark a test as a "plugins" test.'
7887
)
7988

8089
################################################################################
@@ -87,13 +96,19 @@ def pytest_collection_modifyitems(config, items):
8796
test_suite = config.getvalue('test_suite')
8897
run_everything = test_suite == 'validate'
8998
run_slow_test = test_suite in ('all', 'validate')
99+
run_only_plugins = test_suite == 'plugins'
90100

91101
tests_to_run = []
92102
tests_to_skip = []
93103

94104
for item in items:
95105
is_validate = bool(item.get_closest_marker(VALIDATION_TEST))
96106
is_slow = bool(item.get_closest_marker(SLOW_TEST))
107+
is_plugins = bool(item.get_closest_marker(PLUGINS_TEST))
108+
109+
if is_plugins and not run_only_plugins:
110+
tests_to_skip.append(item)
111+
continue
97112

98113
if is_validate and not run_everything:
99114
tests_to_skip.append(item)

etc/ci/azure-posix-installed-external-license.yml

Lines changed: 0 additions & 38 deletions
This file was deleted.

etc/ci/azure-posix.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ parameters:
44
python_versions: []
55
test_suites: {}
66
python_architecture: x64
7-
install_packages: |
8-
venv/bin/python3 -m pip install --upgrade pip
9-
venv/bin/python3 -m pip install tests/licensedcode/data/example_external_licenses/licenses_to_install1
107

118
jobs:
129
- job: ${{ parameters.job_name }}
@@ -38,8 +35,5 @@ jobs:
3835
./configure --clean && ./configure --dev
3936
displayName: '${{ pyver }} - Configure'
4037
41-
- script: ${{ parameters.install_packages }}
42-
displayName: '${{ pyver }} - Install license'
43-
4438
- script: $(test_suite)
4539
displayName: '${{ pyver }} - $(test_suite_label) on ${{ parameters.job_name }}'

etc/ci/azure-win-installed-external-license.yml

Lines changed: 0 additions & 38 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
graft src
2+
graft thirdparty
3+
4+
include setup.*
5+
include *.rst
6+
include *LICENSE*
7+
include *NOTICE*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#
2+
# Copyright (c) nexB Inc. and others. All rights reserved.
3+
# ScanCode is a trademark of nexB Inc.
4+
# SPDX-License-Identifier: Apache-2.0
5+
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
6+
# See https://github.com/nexB/scancode-toolkit for support or download.
7+
# See https://aboutcode.org for more information about nexB OSS projects.
8+
#
9+
from os.path import abspath
10+
from os.path import dirname
11+
12+
from licensedcode.additional_license_location_provider import AdditionalLicenseLocationProviderPlugin
13+
14+
15+
class LicensesToInstall2Paths(AdditionalLicenseLocationProviderPlugin):
16+
def get_locations(self):
17+
curr_dir = dirname(abspath(__file__))
18+
locations = {
19+
'licenses_to_install2': curr_dir,
20+
}
21+
return locations
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is a test license EXAMPLE2 that must be installed into ScanCode Toolkit.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
key: example-installed-2
2+
short_name: Example Installed License 2
3+
name: Example Installed License 2
4+
category: Permissive
5+
owner: NexB
6+
spdx_license_key: LicenseRef-scancode-example-installed2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is a test rule EXAMPLE2 that must be installed into ScanCode Toolkit.

0 commit comments

Comments
 (0)