Skip to content

Commit

Permalink
[refactor] move test data from data/formats to data
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 13, 2023
1 parent 85e8783 commit 0138e9c
Show file tree
Hide file tree
Showing 15 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/install_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: Run tests
run: pytest
- name: Run CLI
run: pyspdxtools -i ./tests/spdx/data/formats/SPDXJSONExample-v2.3.spdx.json
run: pyspdxtools -i ./tests/spdx/data/SPDXJSONExample-v2.3.spdx.json

- name: Install optional dependencies
run: python -m pip install networkx
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,32 +64,32 @@ instead of `bin`.
* Use `pyspdxtools -i <filename>` where `<filename>` is the location of the file. The input format is inferred automatically from the file ending.

* If you are using a source distribution, try running:
`pyspdxtools -i tests/data/formats/SPDXJSONExample-v2.3.spdx.json`
`pyspdxtools -i tests/data/SPDXJSONExample-v2.3.spdx.json`

2. **CONVERTING** (for converting one format to another):

* Use `pyspdxtools -i <input_file> -o <output_file>` where `<input_file>` is the location of the file to be converted
and `<output_file>` is the location of the output file. The input and output formats are inferred automatically from the file endings.

* If you are using a source distribution, try running:
`pyspdxtools -i tests/data/formats/SPDXJSONExample-v2.3.spdx.json -o output.tag`
`pyspdxtools -i tests/data/SPDXJSONExample-v2.3.spdx.json -o output.tag`

* If you want to skip the validation process, provide the `--novalidation` flag, like so:
`pyspdxtools -i tests/data/formats/SPDXJSONExample-v2.3.spdx.json -o output.tag --novalidation`
`pyspdxtools -i tests/data/SPDXJSONExample-v2.3.spdx.json -o output.tag --novalidation`
(use this with caution: note that undetected invalid documents may lead to unexpected behavior of the tool)

* For help use `pyspdxtools --help`

3. **GRAPH GENERATION** (optional feature)

* This feature generates a graph representing all elements in the SPDX document and their connections based on the provided
relationships. The graph can be rendered to a picture. Below is an example for the file `tests/data/formats/SPDXJSONExample-v2.3.spdx.json`:
relationships. The graph can be rendered to a picture. Below is an example for the file `tests/data/SPDXJSONExample-v2.3.spdx.json`:
![SPDXJSONExample-v2.3.spdx.png](assets/SPDXJSONExample-v2.3.spdx.png)
* Make sure you install the optional dependencies `networkx` and `pygraphviz`. To do so run `pip install ".[graph_generation]"`.
* Use `pyspdxtools -i <input_file> --graph -o <output_file>` where `<output_file>` is an output file name with valid format for `pygraphviz` (check
the documentation [here](https://pygraphviz.github.io/documentation/stable/reference/agraph.html#pygraphviz.AGraph.draw)).
* If you are using a source distribution, try running
`pyspdxtools -i tests/data/formats/SPDXJSONExample-v2.3.spdx.json --graph -o SPDXJSONExample-v2.3.spdx.png` to generate
`pyspdxtools -i tests/data/SPDXJSONExample-v2.3.spdx.json --graph -o SPDXJSONExample-v2.3.spdx.png` to generate
a png with an overview of the structure of the example file.

## Library usage
Expand Down
File renamed without changes.
File renamed without changes.
8 changes: 2 additions & 6 deletions tests/spdx/parser/all_formats/test_parse_from_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ def test_parse_from_file_not_found(self, parser, format_name, extension):

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}"
)
os.path.join(os.path.dirname(__file__), f"../../data/SPDX{format_name}Example-v2.3.spdx{extension}")
)
assert type(doc) == Document
assert len(doc.annotations) == 5
Expand All @@ -48,9 +46,7 @@ def test_parse_from_file_with_2_3_example(self, parser, format_name, extension):

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}"
)
os.path.join(os.path.dirname(__file__), f"../../data/SPDX{format_name}Example-v2.2.spdx{extension}")
)
assert type(doc) == Document
assert len(doc.annotations) == 5
Expand Down
2 changes: 1 addition & 1 deletion tests/spdx/parser/rdf/test_license_expression_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_license_expression_parser():

def test_license_expression_parser_with_coupled_licenses():
doc = rdf_parser.parse_from_file(
os.path.join(os.path.dirname(__file__), "../../data/formats/SPDXRdfExample-v2.3.spdx.rdf.xml")
os.path.join(os.path.dirname(__file__), "../../data/SPDXRdfExample-v2.3.spdx.rdf.xml")
)

packages_by_spdx_id = {package.spdx_id: package for package in doc.packages}
Expand Down
2 changes: 1 addition & 1 deletion tests/spdx/test_graph_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_generate_graph_from_spdx(
edges_count: int,
relationship_node_keys: List[str],
) -> None:
document = parse_file(str(Path(__file__).resolve().parent.parent / "spdx" / "data" / "formats" / file_name))
document = parse_file(str(Path(__file__).resolve().parent.parent / "spdx" / "data" / file_name))
graph = generate_relationship_graph_from_spdx(document)

assert document.creation_info.spdx_id in graph.nodes()
Expand Down

0 comments on commit 0138e9c

Please sign in to comment.