-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[issue-573] unify parse_from_file tests for all formats
Signed-off-by: Armin Tänzer <armin.taenzer@tngtech.com>
- Loading branch information
1 parent
bfcd5e2
commit 5feba30
Showing
10 changed files
with
2,089 additions
and
110 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# SPDX-FileCopyrightText: 2022 spdx contributors | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import os | ||
|
||
import pytest | ||
|
||
from spdx.model.document import Document | ||
from spdx.parser.json import json_parser | ||
from spdx.parser.rdf import rdf_parser | ||
from spdx.parser.tagvalue import tagvalue_parser | ||
from spdx.parser.xml import xml_parser | ||
from spdx.parser.yaml import yaml_parser | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"parser, format_name, extension", | ||
[ | ||
(json_parser, "JSON", ".json"), | ||
(xml_parser, "XML", ".xml"), | ||
(yaml_parser, "YAML", ".yaml"), | ||
(rdf_parser, "Rdf", ".rdf.xml"), | ||
(tagvalue_parser, "Tag", ""), | ||
], | ||
) | ||
class TestParseFromFile: | ||
def test_parse_from_file_not_found(self, parser, format_name, extension): | ||
with pytest.raises(FileNotFoundError) as err: | ||
wrong_file_path = os.path.join(os.path.dirname(__file__), f"hnjfkjsedhnflsiafg.spdx{extension}") | ||
parser.parse_from_file(wrong_file_path) | ||
|
||
assert err.value.args[1] == "No such file or directory" | ||
|
||
def test_parse_from_file_with_2_3_example(self, parser, format_name, extension): | ||
doc = parser.parse_from_file( | ||
os.path.join( | ||
os.path.dirname(__file__), f"../../data/formats/SPDX{format_name}Example-v2.3.spdx{extension}" | ||
) | ||
) | ||
assert type(doc) == Document | ||
assert len(doc.annotations) == 5 | ||
assert len(doc.files) == 5 | ||
assert len(doc.packages) == 4 | ||
assert len(doc.snippets) == 1 | ||
assert len(doc.relationships) == 13 | ||
assert len(doc.extracted_licensing_info) == 5 | ||
|
||
def test_parse_json_with_2_2_example(self, parser, format_name, extension): | ||
doc = parser.parse_from_file( | ||
os.path.join( | ||
os.path.dirname(__file__), f"../../data/formats/SPDX{format_name}Example-v2.2.spdx{extension}" | ||
) | ||
) | ||
assert type(doc) == Document | ||
assert len(doc.annotations) == 5 | ||
assert len(doc.files) == 4 | ||
assert len(doc.packages) == 4 | ||
assert len(doc.snippets) == 1 | ||
assert len(doc.relationships) == 11 | ||
assert len(doc.extracted_licensing_info) == 5 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters