Skip to content

Commit

Permalink
spdx3: write_snippet: fix the presentation of line and byte ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislaw committed Jan 9, 2024
1 parent 8050fd9 commit a07dfd5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/spdx_tools/spdx3/model/positive_integer_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ def __init__(
end: int,
):
check_types_and_set_values(self, locals())

def __str__(self):
return f"{self.begin}:{self.end}"
25 changes: 25 additions & 0 deletions tests/spdx3/writer/tag_value/test_write_snippet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import io

from spdx_tools.spdx3.model.positive_integer_range import PositiveIntegerRange
from spdx_tools.spdx3.model.software import Snippet
from spdx_tools.spdx3.writer.console.software.snippet_writer import write_snippet


def test_render_creation_info():
snippet = Snippet(
spdx_id="SPDXRef-Snippet",
byte_range=PositiveIntegerRange(0, 3),
line_range=PositiveIntegerRange(1, 2),
)
output_str = io.StringIO()
write_snippet(snippet, text_output=output_str)

assert (
output_str.getvalue()
== """\
## Snippet
SPDXID: SPDXRef-Snippet
byte_range: 0:3
line_range: 1:2
"""
)

0 comments on commit a07dfd5

Please sign in to comment.