Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[issue-402] change write_document() to write_document_to_file() #576

Merged
merged 1 commit into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)