Skip to content

Commit

Permalink
[issue-402] change write_document() to write_document_to_file()
Browse files Browse the repository at this point in the history
Signed-off-by: Armin Tänzer <armin.taenzer@tngtech.com>
  • Loading branch information
armintaenzertng committed Apr 12, 2023
1 parent 780c94f commit 826b2c8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/spdx/writer/json/json_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
from spdx.validation.validation_message import ValidationMessage


def write_document(document: Document, file_name: str, validate: bool = True, converter: DocumentConverter = None):
def write_document_to_file(
document: Document, file_name: str, validate: bool = True, converter: DocumentConverter = None
):
"""
Serializes the provided document to json and writes it to a file with the provided name. Unless validate is set
to False, validates the document before serialization. Unless a DocumentConverter instance is provided,
Expand Down
2 changes: 1 addition & 1 deletion src/spdx/writer/write_anything.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
def write_file(document: Document, file_name: str, validate: bool = True):
output_format = file_name_to_format(file_name)
if output_format == FileFormat.JSON:
json_writer.write_document(document, file_name, validate)
json_writer.write_document_to_file(document, file_name, validate)
elif output_format == FileFormat.YAML:
yaml_writer.write_document_to_file(document, file_name, validate)
elif output_format == FileFormat.XML:
Expand Down
8 changes: 4 additions & 4 deletions tests/spdx/writer/json/test_json_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import pytest

from spdx.writer.json.json_writer import write_document
from spdx.writer.json.json_writer import write_document_to_file
from tests.spdx.fixtures import document_fixture


Expand All @@ -19,7 +19,7 @@ def temporary_file_path() -> str:

def test_write_json(temporary_file_path: str):
document = document_fixture()
write_document(document, temporary_file_path, validate=True)
write_document_to_file(document, temporary_file_path, validate=True)

with open(temporary_file_path) as written_file:
written_json = json.load(written_file)
Expand All @@ -35,12 +35,12 @@ def test_document_is_validated():
document.creation_info.spdx_id = "InvalidId"

with pytest.raises(ValueError) as error:
write_document(document, "dummy_path")
write_document_to_file(document, "dummy_path")
assert "Document is not valid" in error.value.args[0]


def test_document_validation_can_be_overridden(temporary_file_path: str):
document = document_fixture()
document.creation_info.spdx_id = "InvalidId"

write_document(document, temporary_file_path, validate=False)
write_document_to_file(document, temporary_file_path, validate=False)

0 comments on commit 826b2c8

Please sign in to comment.