Skip to content

Commit 40331ac

Browse files
stanislawarmintaenzertng
authored andcommitted
spdx3: element_writer: unindent creation information
Signed-off-by: Stanislav Pankevich <[email protected]>
1 parent eded3db commit 40331ac

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

src/spdx_tools/spdx3/writer/console/console.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ def write_value(tag: str, value: Optional[Union[bool, str, dict, list, Enum]], o
2222

2323
def write_and_possibly_indent(text: str, indent: bool, out: TextIO):
2424
if indent:
25-
out.write(f"\t{text}\n")
25+
out.write(f" {text}\n")
2626
else:
2727
out.write(f"{text}\n")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# SPDX-FileCopyrightText: 2024 spdx contributors
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
import io
5+
from datetime import datetime
6+
7+
from semantic_version import Version
8+
9+
from spdx_tools.spdx3.model import CreationInfo, ProfileIdentifierType, SpdxDocument
10+
from spdx_tools.spdx3.writer.console.spdx_document_writer import write_spdx_document
11+
12+
13+
def test_render_creation_info():
14+
fake_datetime = datetime(year=2024, month=1, day=1)
15+
spec_version = Version("3.0.0")
16+
creation_info = CreationInfo(
17+
spec_version=spec_version,
18+
created=fake_datetime,
19+
created_by=[],
20+
profile=[ProfileIdentifierType.SOFTWARE],
21+
)
22+
spdx_document = SpdxDocument(
23+
spdx_id="SPDXRef-FOO",
24+
name="BAR",
25+
element=[],
26+
root_element=[],
27+
creation_info=creation_info,
28+
)
29+
output_str = io.StringIO()
30+
write_spdx_document(spdx_document, text_output=output_str)
31+
32+
assert (
33+
output_str.getvalue()
34+
== """\
35+
## SPDX Document
36+
SPDXID: SPDXRef-FOO
37+
name: BAR
38+
# Creation Information
39+
specVersion: 3.0.0
40+
created: 2024-01-01T00:00:00Z
41+
profile: SOFTWARE
42+
data license: CC0-1.0
43+
elements:
44+
""" # noqa: W291 # elements: are printed with a space
45+
)

0 commit comments

Comments
 (0)