|
| 1 | +# This file is part of CycloneDX Python Library |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +# |
| 15 | +# SPDX-License-Identifier: Apache-2.0 |
| 16 | +# Copyright (c) OWASP Foundation. All Rights Reserved. |
| 17 | + |
| 18 | +from unittest import TestCase |
| 19 | + |
| 20 | +from cyclonedx._internal.bom_ref import bom_ref_from_str |
| 21 | +from cyclonedx.model.bom_ref import BomRef |
| 22 | + |
| 23 | + |
| 24 | +class TestInternalBomRefFromStr(TestCase): |
| 25 | + |
| 26 | + def test_bomref_io(self) -> None: |
| 27 | + i = BomRef() |
| 28 | + o = bom_ref_from_str(i) |
| 29 | + self.assertIs(i, o) |
| 30 | + |
| 31 | + def test_none_optional_is_none(self) -> None: |
| 32 | + o = bom_ref_from_str(None, optional=True) |
| 33 | + self.assertIsNone(o) |
| 34 | + |
| 35 | + def test_none_mandatory_is_something(self) -> None: |
| 36 | + o = bom_ref_from_str(None, optional=False) |
| 37 | + self.assertIsInstance(o, BomRef) |
| 38 | + self.assertIsNone(o.value) |
| 39 | + |
| 40 | + def test_nothing_optional_is_none(self) -> None: |
| 41 | + o = bom_ref_from_str('', optional=True) |
| 42 | + self.assertIsNone(o) |
| 43 | + |
| 44 | + def test_nothing_mandatory_is_something(self) -> None: |
| 45 | + o = bom_ref_from_str('', optional=False) |
| 46 | + self.assertIsInstance(o, BomRef) |
| 47 | + self.assertIsNone(o.value) |
| 48 | + |
| 49 | + def test_something_optional(self) -> None: |
| 50 | + o = bom_ref_from_str('foobar', optional=True) |
| 51 | + self.assertIsInstance(o, BomRef) |
| 52 | + self.assertEqual('foobar', o.value) |
| 53 | + |
| 54 | + def test_something_mandatory(self) -> None: |
| 55 | + o = bom_ref_from_str('foobar', optional=False) |
| 56 | + self.assertIsInstance(o, BomRef) |
| 57 | + self.assertEqual('foobar', o.value) |
0 commit comments