-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jan Kowalleck <[email protected]>
- Loading branch information
1 parent
39e0eb9
commit d6289db
Showing
9 changed files
with
124 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# encoding: utf-8 | ||
|
||
# This file is part of CycloneDX Python Lib | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# Copyright (c) OWASP Foundation. All Rights Reserved. | ||
|
||
|
||
from itertools import product | ||
from typing import Tuple | ||
from unittest import TestCase | ||
|
||
from ddt import data, ddt, named_data, unpack | ||
|
||
from cyclonedx.schema import OutputFormat, SchemaVersion | ||
from cyclonedx.validation import get_instance as get_validator | ||
|
||
UndefinedFormatVersion = {(OutputFormat.JSON, SchemaVersion.V1_1), (OutputFormat.JSON, SchemaVersion.V1_0), } | ||
|
||
|
||
@ddt | ||
class TestGetInstance(TestCase): | ||
|
||
@named_data(*([f'{f.name} {v.name}', f, v] | ||
for f, v | ||
in product(OutputFormat, SchemaVersion) | ||
if (f, v) not in UndefinedFormatVersion)) | ||
@unpack | ||
def test_as_expected(self, of: OutputFormat, sv: SchemaVersion) -> None: | ||
validator = get_validator(of, sv) | ||
self.assertIs(validator.output_format, of) | ||
self.assertIs(validator.schema_version, sv) | ||
|
||
@data( | ||
*(('foo', sv, (TypeError, "unexpected output_format: 'foo'")) for sv in SchemaVersion), | ||
*((f, v, (ValueError, f'unsupported schema_version: {v}')) for f, v in UndefinedFormatVersion) | ||
) | ||
@unpack | ||
def test_fails_on_wrong_args(self, of: OutputFormat, sv: SchemaVersion, raisesRegex: Tuple) -> None: | ||
with self.assertRaisesRegexp(*raisesRegex): | ||
get_validator(of, sv) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters