File: test_annotation.py

package info (click to toggle)
python-spdx-tools 0.8.3-4
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 5,084 kB
  • sloc: python: 18,675; xml: 12,553; sh: 46; makefile: 6
file content (50 lines) | stat: -rw-r--r-- 1,762 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# SPDX-FileCopyrightText: 2023 spdx contributors
#
# SPDX-License-Identifier: Apache-2.0

from datetime import datetime
from unittest import mock

import pytest

from spdx_tools.spdx.model import Annotation, AnnotationType


@mock.patch("spdx_tools.spdx.model.Actor", autospec=True)
def test_correct_initialization(actor):
    annotation = Annotation("id", AnnotationType.OTHER, actor, datetime(2022, 1, 1), "comment")
    assert annotation.spdx_id == "id"
    assert annotation.annotation_type == AnnotationType.OTHER
    assert annotation.annotator == actor
    assert annotation.annotation_date == datetime(2022, 1, 1)
    assert annotation.annotation_comment == "comment"


@mock.patch("spdx_tools.spdx.model.Actor", autospec=True)
def test_wrong_type_in_spdx_id(actor):
    with pytest.raises(TypeError):
        Annotation(42, AnnotationType.OTHER, actor, datetime(2022, 1, 1), "comment")


@mock.patch("spdx_tools.spdx.model.Actor", autospec=True)
def test_wrong_type_in_annotation_type(actor):
    with pytest.raises(TypeError):
        Annotation("id", 42, actor, datetime(2022, 1, 1), "comment")


@mock.patch("spdx_tools.spdx.model.Actor", autospec=True)
def test_wrong_type_in_annotator(actor):
    with pytest.raises(TypeError):
        Annotation("id", AnnotationType.OTHER, 42, datetime(2022, 1, 1), "comment")


@mock.patch("spdx_tools.spdx.model.Actor", autospec=True)
def test_wrong_type_in_annotation_date(actor):
    with pytest.raises(TypeError):
        Annotation("id", AnnotationType.OTHER, actor, 42, "comment")


@mock.patch("spdx_tools.spdx.model.Actor", autospec=True)
def test_wrong_type_in_annotation_comment(actor):
    with pytest.raises(TypeError):
        Annotation("id", AnnotationType.OTHER, actor, datetime(2022, 1, 1), 42)