Skip to content

Commit

Permalink
cleanups and tets
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
  • Loading branch information
jkowalleck committed Sep 16, 2023
1 parent 4fd41a5 commit 4d9ca25
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 45 deletions.
25 changes: 11 additions & 14 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,21 @@ jobs:
run: poetry run tox -e flake8 -s false

static-code-analysis:
name: StaticCodingAnalysis (py${{ matrix.python-version}} ${{ matrix.toxenv-factor }})
name: StaticCodingAnalysis (py${{ matrix.python-version}} ${{ matrix.toxenv-factors }})
runs-on: ${{ matrix.os }}
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
include:
- # test with the locked dependencies
- # test with the latest dependencies
os: ubuntu-latest
python-version: '3.11'
toxenv-factor: 'locked'
toxenv-factors: 'current'
- # test with the lowest dependencies
os: ubuntu-latest
python-version: '3.7'
toxenv-factor: 'lowest'
toxenv-factors: 'lowest'
steps:
- name: Checkout
# see https://github.com/actions/checkout
Expand All @@ -87,10 +87,10 @@ jobs:
run: poetry install --no-root

- name: Run tox
run: poetry run tox -e mypy-${{ matrix.toxenv-factor }} -s false
run: poetry run tox -e mypy${{ matrix.toxenv-factors }} -s false

build-and-test:
name: Test (${{ matrix.os }} py${{ matrix.python-version }} ${{ matrix.toxenv-factor }})
name: Test (${{ matrix.os }} py${{ matrix.python-version }} ${{ matrix.toxenv-factors }})
runs-on: ${{ matrix.os }}
timeout-minutes: 15
env:
Expand All @@ -105,12 +105,9 @@ jobs:
- "3.9"
- "3.8"
- "3.7" # lowest supported
toxenv-factor: ['locked']
include:
- # test with the lowest dependencies
os: ubuntu-latest
python-version: '3.7'
toxenv-factor: 'lowest'
toxenv-factors:
- '-allExtras'
- '-noExtras'
steps:
- name: Disabled Git auto EOL CRLF transforms
run: |
Expand Down Expand Up @@ -150,12 +147,12 @@ jobs:
run: poetry build

- name: Run tox
run: poetry run tox -e py-${{ matrix.toxenv-factor }} -s false
run: poetry run tox -e py${{ matrix.toxenv-factors }} -s false

- name: Generate coverage reports
run: >
poetry run coverage report &&
poetry run coverage xml -o ${{ env.REPORTS_DIR }}/coverage-${{ matrix.os }}-${{ matrix.python-version }}-${{ matrix.toxenv-factor }}.xml &&
poetry run coverage xml -o ${{ env.REPORTS_DIR }}/coverage-${{ matrix.os }}-${{ matrix.python-version }}-${{ matrix.toxenv-factors }}.xml &&
poetry run coverage html -d ${{ env.REPORTS_DIR }}
- name: Artifact reports
Expand Down
3 changes: 1 addition & 2 deletions cyclonedx/validation/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from abc import ABC
from json import loads as json_loads
from typing import TYPE_CHECKING, Any, Never, Optional, Tuple
from typing import TYPE_CHECKING, Any, Optional, Tuple

from ..schema._res import BOM_JSON as _S_BOM, BOM_JSON_STRICT as _S_BOM_STRICT, JSF as _S_JSF, SPDX_JSON as _S_SPPDX
from . import MissingOptionalDependencyException, ValidationError, _BaseValidator
Expand All @@ -28,7 +28,6 @@
from jsonschema.exceptions import ValidationError as JsonValidationError # type: ignore
from jsonschema.validators import Draft7Validator # type: ignore
from referencing import Registry
from referencing.exceptions import NoSuchResource
from referencing.jsonschema import DRAFT7

if TYPE_CHECKING:
Expand Down
9 changes: 0 additions & 9 deletions deps.lowest.r

This file was deleted.

4 changes: 2 additions & 2 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from xmldiff.actions import MoveNode

from cyclonedx.output import SchemaVersion
from cyclonedx.schema import _RES_DIR as CDX_SCHEMA_DIRECTORY
from cyclonedx.schema._res import __DIR as CDX_SCHEMA_DIRECTORY
from cyclonedx.validation import MissingOptionalDependencyException
from cyclonedx.validation.json import JsonValidator

Expand Down Expand Up @@ -89,7 +89,7 @@ class BaseXmlTestCase(TestCase):

def assertValidAgainstSchema(self, bom_xml: str, schema_version: SchemaVersion) -> None:
# rework access
xsd_fn = os.path.join(CDX_SCHEMA_DIRECTORY, f'bom-{schema_version.name.replace("_", ".").replace("V", "")}.xsd')
xsd_fn = os.path.join(CDX_SCHEMA_DIRECTORY, f'bom-{schema_version.to_version()}.SNAPSHOT.xsd')
with open(xsd_fn) as xsd_fd:
xsd_doc = etree.parse(xsd_fd)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_schema__res.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ def _dp_files() -> Generator:
class SchemaRes(TestCase):

@idata(_dp_files())
def test_file_exists(self, file) -> None:
def test_file_exists(self, file: str) -> None:
self.assertTrue(isfile(file), file)
35 changes: 24 additions & 11 deletions tests/test_validation_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from ddt import data, ddt, idata, unpack

from cyclonedx.schema import SchemaVersion
from cyclonedx.validation import MissingOptionalDependencyException
from cyclonedx.validation.json import JsonStrictValidator, JsonValidator

from . import TESTDATA_DIRECTORY
Expand Down Expand Up @@ -55,22 +56,28 @@ def test_validate_no_none(self, schema_version: SchemaVersion, test_data_file: s
validator = JsonValidator(schema_version)
with open(join(RELEVANT_TESTDATA_DIRECTORY, schema_version.to_version(), test_data_file), 'r') as tdfh:
test_data = tdfh.read()
error = validator.validate_str(test_data)
self.assertIsNone(error)
try:
validation_error = validator.validate_str(test_data)
except MissingOptionalDependencyException:
self.skipTest('MissingOptionalDependencyException')
self.assertIsNone(validation_error)

@idata(_dp('invalid'))
@unpack
def test_validate_expected_error(self, schema_version: SchemaVersion, test_data_file: str) -> None:
validator = JsonValidator(schema_version)
with open(join(RELEVANT_TESTDATA_DIRECTORY, schema_version.to_version(), test_data_file), 'r') as tdfh:
test_data = tdfh.read()
error = validator.validate_str(test_data)
self.assertIsNotNone(error)
self.assertIsNotNone(error.data)
try:
validation_error = validator.validate_str(test_data)
except MissingOptionalDependencyException:
self.skipTest('MissingOptionalDependencyException')
self.assertIsNotNone(validation_error)
self.assertIsNotNone(validation_error.data)


@ddt
class TestJsonValidator(TestCase):
class TestJsonStrictValidator(TestCase):

@data(*UNSUPPORTED_SCHEMA_VERSIONS)
def test_throws_with_unsupported_schema_version(self, schema_version: SchemaVersion) -> None:
Expand All @@ -83,15 +90,21 @@ def test_validate_no_none(self, schema_version: SchemaVersion, test_data_file: s
validator = JsonStrictValidator(schema_version)
with open(join(RELEVANT_TESTDATA_DIRECTORY, schema_version.to_version(), test_data_file), 'r') as tdfh:
test_data = tdfh.read()
error = validator.validate_str(test_data)
self.assertIsNone(error)
try:
validation_error = validator.validate_str(test_data)
except MissingOptionalDependencyException:
self.skipTest('MissingOptionalDependencyException')
self.assertIsNone(validation_error)

@idata(_dp('invalid'))
@unpack
def test_validate_expected_error(self, schema_version: SchemaVersion, test_data_file: str) -> None:
validator = JsonStrictValidator(schema_version)
with open(join(RELEVANT_TESTDATA_DIRECTORY, schema_version.to_version(), test_data_file), 'r') as tdfh:
test_data = tdfh.read()
error = validator.validate_str(test_data)
self.assertIsNotNone(error)
self.assertIsNotNone(error.data)
try:
validation_error = validator.validate_str(test_data)
except MissingOptionalDependencyException:
self.skipTest('MissingOptionalDependencyException')
self.assertIsNotNone(validation_error)
self.assertIsNotNone(validation_error.data)
2 changes: 1 addition & 1 deletion tools/schema-downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from urllib.request import urlretrieve
import re

SOURCE_ROOT = 'https://raw.githubusercontent.com/CycloneDX/specification/1.4/schema/'
SOURCE_ROOT = 'https://raw.githubusercontent.com/CycloneDX/specification/master/schema/'
TARGET_ROOT = join(dirname(__file__), '..', 'cyclonedx', 'schema', '_res')

bom_xsd = {
Expand Down
10 changes: 5 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
minversion = 3.10
envlist =
flake8
mypy-{locked,lowest}
py{311,310,39,38,37}-{locked,lowest}
mypy-{current,lowest}
py{311,310,39,38,37}-{allExtras,noExtras}
isolated_build = True
skip_missing_interpreters = True
usedevelop = False
Expand All @@ -20,16 +20,16 @@ skip_install = True
whitelist_externals = poetry
commands_pre =
{envpython} --version
poetry install -v
lowest: poetry run pip install -U -r deps.lowest.r
!noExtras: poetry install -v --all-extras
noExtras: poetry install -v
poetry run pip freeze
commands =
poetry run coverage run --source=cyclonedx -m unittest discover -t . -s tests -v
setenv =
PYTHONHASHSEED=0
CDX_TEST_RECREATE_SNAPSHOTS={env:CDX_TEST_RECREATE_SNAPSHOTS:}

[testenv:mypy{,-locked,-lowest}]
[testenv:mypy{,-current,-lowest}]
commands =
# mypy config is in own file: `.mypy.ini`
!lowest: poetry run mypy
Expand Down

0 comments on commit 4d9ca25

Please sign in to comment.