# Path: spdx/parsers/parse_anything.py
# def parse_file(fn):
# 
# Path: spdx/writers/write_anything.py
# def write_file(doc, fn):
# 
# Path: tests/utils_test.py
# def get_test_loc(test_path, test_data_dir=test_data_dir, debug=False, exists=True):
# def to_os_native_path(path):
# def strip_variable_text(rdf_text):
# def load_and_clean_rdf(location):
# def sort_nested(data):
# def check_rdf_scan(expected_file, result_file, regen=False):
# def load_and_clean_tv(location):
# def check_tv_scan(expected_file, result_file, regen=False):
# def load_and_clean_json(location):
# def check_json_scan(expected_file, result_file, regen=False):
# def load_and_clean_yaml(location):
# def check_yaml_scan(expected_file, result_file, regen=False):
# def load_and_clean_xml(location):
# def check_xml_scan(expected_file, result_file, regen=False):
#     def license_to_dict(cls, license):
#     def version_to_dict(cls, version):
#     def entity_to_dict(cls, entity):
#     def checksum_to_dict(cls, checksum):
#     def package_to_dict(cls, package):
#     def files_to_list(cls, files):
#     def ext_document_references_to_list(cls, ext_doc_refs):
#     def extracted_licenses_to_list(cls, extracted_licenses):
#     def annotations_to_list(cls, annotations):
#     def reviews_to_list(cls, reviews):
#     def snippets_to_list(cls, snippets):
#     def to_dict(cls, doc):
# class TestParserUtils(object):
#         CONJ_SEP = re.compile(' AND | and ')
#         DISJ_SEP = re.compile(' OR | or ')


import os
import pytest
from spdx.parsers import parse_anything
from spdx.writers import write_anything
from tests import utils_test
    "SPDXTagExample.tag-json",
    "SPDXSimpleTag.tag-rdf",
    "SPDXXmlExample.xml-rdf",
    "SPDXXmlExample.xml-tag",
    "SPDXJsonExample.json-rdf",
    "SPDXJsonExample.json-tag",
    "SPDXYamlExample.yaml-rdf",
    "SPDXYamlExample.yaml-tag",
    "SPDXRdfExample.rdf-rdf",
    "SPDXRdfExample.rdf-yaml",
    "SPDXRdfExample.rdf-xml",
    "SPDXRdfExample.rdf-json",
    "SPDXRdfExample.rdf-tag"
}

@pytest.mark.parametrize("out_format", ['rdf', 'yaml', 'xml', 'json', 'tag'])
@pytest.mark.parametrize("in_file", test_files, ids=lambda x: os.path.basename(x))
def test_write_anything(in_file, out_format, tmpdir):
    in_basename = os.path.basename(in_file)
    if in_basename == "SPDXSBOMExample.spdx.yml":
        # conversion of spdx2.2 is not yet done
        return
    doc, error = parse_anything.parse_file(in_file)

    assert not error
    result = utils_test.TestParserUtils.to_dict(doc)

    out_fn = os.path.join(tmpdir, "test." + out_format)
    write_anything.write_file(doc, out_fn)


# Path: spdx/parsers/parse_anything.py
# def parse_file(fn):
# 
# Path: spdx/writers/write_anything.py
# def write_file(doc, fn):
# 
# Path: tests/utils_test.py
# def get_test_loc(test_path, test_data_dir=test_data_dir, debug=False, exists=True):
# def to_os_native_path(path):
# def strip_variable_text(rdf_text):
# def load_and_clean_rdf(location):
# def sort_nested(data):
# def check_rdf_scan(expected_file, result_file, regen=False):
# def load_and_clean_tv(location):
# def check_tv_scan(expected_file, result_file, regen=False):
# def load_and_clean_json(location):
# def check_json_scan(expected_file, result_file, regen=False):
# def load_and_clean_yaml(location):
# def check_yaml_scan(expected_file, result_file, regen=False):
# def load_and_clean_xml(location):
# def check_xml_scan(expected_file, result_file, regen=False):
#     def license_to_dict(cls, license):
#     def version_to_dict(cls, version):
#     def entity_to_dict(cls, entity):
#     def checksum_to_dict(cls, checksum):
#     def package_to_dict(cls, package):
#     def files_to_list(cls, files):
#     def ext_document_references_to_list(cls, ext_doc_refs):
#     def extracted_licenses_to_list(cls, extracted_licenses):
#     def annotations_to_list(cls, annotations):
#     def reviews_to_list(cls, reviews):
#     def snippets_to_list(cls, snippets):
#     def to_dict(cls, doc):
# class TestParserUtils(object):
#         CONJ_SEP = re.compile(' AND | and ')
#         DISJ_SEP = re.compile(' OR | or ')


# Path: tests/test_write_anything.py
import os
import pytest
from spdx.parsers import parse_anything
from spdx.writers import write_anything
from tests import utils_test

    "SPDXTagExample.tag-json",
    "SPDXSimpleTag.tag-rdf",
    "SPDXXmlExample.xml-rdf",
    "SPDXXmlExample.xml-tag",
    "SPDXJsonExample.json-rdf",
    "SPDXJsonExample.json-tag",
    "SPDXYamlExample.yaml-rdf",
    "SPDXYamlExample.yaml-tag",
    "SPDXRdfExample.rdf-rdf",
    "SPDXRdfExample.rdf-yaml",
    "SPDXRdfExample.rdf-xml",
    "SPDXRdfExample.rdf-json",
    "SPDXRdfExample.rdf-tag"
}

@pytest.mark.parametrize("out_format", ['rdf', 'yaml', 'xml', 'json', 'tag'])
@pytest.mark.parametrize("in_file", test_files, ids=lambda x: os.path.basename(x))
def test_write_anything(in_file, out_format, tmpdir):
    in_basename = os.path.basename(in_file)
    if in_basename == "SPDXSBOMExample.spdx.yml":
        # conversion of spdx2.2 is not yet done
        return
    doc, error = parse_anything.parse_file(in_file)

    assert not error
    result = utils_test.TestParserUtils.to_dict(doc)

    out_fn = os.path.join(tmpdir, "test." + out_format)
    write_anything.write_file(doc, out_fn)


    doc2, error2 = parse_anything.parse_file(out_fn)