Skip to content
Merged
Empty file added tests/__init__.py
Empty file.
53 changes: 53 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright (c) 2021 LG Electronics Inc.
# SPDX-License-Identifier: Apache-2.0
import os
import shutil

import pytest

from tests import constants
from fosslight_util.constant import FOSSLIGHT_SOURCE
from fosslight_util.oss_item import ScannerItem, FileItem, OssItem

set_up_directories = [
constants.TEST_RESULT_DIR,
os.path.join(constants.TEST_RESULT_DIR, "convert")
]
remove_directories = [constants.TEST_RESULT_DIR]


@pytest.fixture(scope="function", autouse=True)
def setup_test_result_dir_and_teardown():
print("==============setup==============")
for dir in set_up_directories:
os.makedirs(dir, exist_ok=True)

yield

print("==============tearDown==============")
for dir in remove_directories:
shutil.rmtree(dir)


@pytest.fixture
def scan_item():
scan_item = ScannerItem(FOSSLIGHT_SOURCE)
scan_item.set_cover_pathinfo('tests/test_excel_and_csv', '')
scan_item.set_cover_comment('This is a test comment')

file_item = FileItem('test_result/excel_and_csv')

oss_item = OssItem("test_name1", "1.0.0", "Apache-2.0", "https://abc.com")
oss_item.comment = "test_name comment"
file_item.oss_items.append(oss_item)

oss_item2 = OssItem("test_name2", "2.0.0", "MIT", "https://abc2.com")
file_item.oss_items.append(oss_item2)

oss_item3 = OssItem("test_name3", "1.0.0", "GPL-2.0,BSD-3-Clause", "https://abc3.com")
file_item.oss_items.append(oss_item3)
file_item.comment = "all test comment"

scan_item.append_file_items([file_item])

return scan_item
5 changes: 5 additions & 0 deletions tests/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright (c) 2021 LG Electronics Inc.
# SPDX-License-Identifier: Apache-2.0

TEST_RESULT_DIR = "test_result"
TEST_RESOURCES_DIR = "resources"
Empty file added tests/legacy/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 22 additions & 0 deletions tests/legacy/test_download.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2021 LG Electronics Inc.
# SPDX-License-Identifier: Apache-2.0
from fosslight_util.download import cli_download_and_extract


def main():
success, msg, _, _ = cli_download_and_extract("https://github.com/LGE-OSS/example",
"test_result/download/example",
"test_result/download_log/example")
if not success:
raise Exception(f"Download failed with git:{msg}")
success, msg, _, _ = cli_download_and_extract("https://pypi.org/project/filelock/3.4.1",
"test_result/download/filelock",
"test_result/download_log/filelock")
if not success:
raise Exception(f"Download failed with wget:{msg}")


if __name__ == '__main__':
main()
File renamed without changes.
File renamed without changes.
File renamed without changes.
35 changes: 35 additions & 0 deletions tests/legacy/test_opossum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2021 LG Electronics Inc.
# SPDX-License-Identifier: Apache-2.0
from fosslight_util.write_opossum import write_opossum
from fosslight_util.set_log import init_log
from fosslight_util.oss_item import ScannerItem, FileItem, OssItem
from fosslight_util.constant import FOSSLIGHT_SOURCE


def main():
logger, _result_log = init_log("test_result/excel/log_write_opossum.txt")
logger.warning("TESTING - Writing an opossum")

scan_item = ScannerItem(FOSSLIGHT_SOURCE)
scan_item.set_cover_pathinfo('tests/test_excel_and_csv', '')
scan_item.set_cover_comment('This is a test comment')

file_item = FileItem('test_result/excel_and_csv')
oss_item = OssItem("test_name", "1.0.0", "Apache-2.0", "https://abc.com")
oss_item.comment = "test_name comment"
file_item.oss_items.append(oss_item)
oss_item2 = OssItem("test_name", "2.0.0", "MIT", "https://abc2.com")
file_item.oss_items.append(oss_item2)
file_item.comment = "all test comment"

scan_item.append_file_items([file_item])

success, msg = write_opossum(
'test_result/opossum/FL-TEST_opossum.json', scan_item)
logger.warning("Result:" + str(success) + ", error_msg:" + msg)


if __name__ == '__main__':
main()
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ def main():
scan_item.set_cover_comment('This is a test comment')

file_item = FileItem('test_result/excel_and_csv')

oss_item = OssItem("test_name", "1.0.0", "Apache-2.0", "https://abc.com")
oss_item.comment = "test_name comment"
file_item.oss_items.append(oss_item)

oss_item2 = OssItem("test_name", "2.0.0", "MIT", "https://abc2.com")
file_item.oss_items.append(oss_item2)
file_item.comment = "all test comment"
Expand Down
18 changes: 18 additions & 0 deletions tests/legacy/test_spdx_licenses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2021 LG Electronics Inc.
# SPDX-License-Identifier: Apache-2.0
from fosslight_util.set_log import init_log
from fosslight_util.spdx_licenses import get_spdx_licenses_json


def main():
logger, _result_log = init_log("test_result/spdx_licenses/log_spdx_licenses.txt")
logger.warning("TESTING - Get spdx licenses")

success, error_msg, licenses = get_spdx_licenses_json()
logger.warning("Result:" + str(success) + ", error_msg:" + error_msg)


if __name__ == '__main__':
main()
20 changes: 20 additions & 0 deletions tests/legacy/test_text.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2021 LG Electronics Inc.
# SPDX-License-Identifier: Apache-2.0
import os
from fosslight_util.set_log import init_log
from fosslight_util.write_txt import write_txt_file


def main():
output_dir = "test_result/txt"
logger, _result_log = init_log(os.path.join(output_dir, "log.txt"))
logger.warning("TESTING - writing text file")
success, error_msg = write_txt_file(
os.path.join(output_dir, "test.txt"), "Testing - Writing text in a file.")
logger.warning("Result:" + str(success) + ", error_msg:"+error_msg)


if __name__ == '__main__':
main()
File renamed without changes.
File renamed without changes.
Binary file added tests/resources/FOSSLight-Report_sample.xlsx
Binary file not shown.
73 changes: 73 additions & 0 deletions tests/resources/after.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
same-oss:
- version: 0.0.0
source name or path:
- go.mod
license:
- BSD-3-Clause
download location: https://github.com/alecthomas/template
homepage: https://pkg.go.dev/github.com/alecthomas/template
comment: transitive, Cannot connect https://pkg.go.dev/github.com/alecthomas/[email protected],
get info from the latest version.
add-license-oss:
- version: 0.5.6
source name or path:
- go.mod
license:
- MPL-2.0
download location: https://github.com/hashicorp/go-retryablehttp
homepage: https://pkg.go.dev/github.com/hashicorp/go-retryablehttp
comment: transitive
- version: 0.5.3
source name or path:
- go.mod
license:
- MPL-2.0
download location: https://github.com/hashicorp/go-retryablehttp
homepage: https://pkg.go.dev/github.com/hashicorp/go-retryablehttp
comment: transitive
- version: 0.5.3
source name or path:
- go.mod
license:
- Apache-2.0
download location: https://github.com/hashicorp/go-retryablehttp
homepage: https://pkg.go.dev/github.com/hashicorp/go-retryablehttp
comment: transitive
- version: 0.5.4
source name or path:
- go.mod
license:
- Apache-2.0
download location: https://github.com/hashicorp/go-retryablehttp
homepage: https://pkg.go.dev/github.com/hashicorp/go-retryablehttp
comment: transitive
remove-version-oss:
- version: 1.0.1
source name or path:
- go.mod
license:
- MIT
- Apache-2.0
download location: https://github.com/konsorten/go-windows-terminal-sequences
homepage: https://pkg.go.dev/github.com/konsorten/go-windows-terminal-sequences
comment: transitive
new-test-oss:
- version: 1.0.1
source name or path:
- hi
license:
- MIT
- Apache-2.0
download location: https://github.com/new-test-oss/new-test-oss
homepage: https://github.com/new-test-oss/new-test-oss
new-test-oss2:
- version: 1.0.1
source name or path:
- hi2
license:
- MIT
- version: 1.0.2
source name or path:
- hi2
license:
- MIT
53 changes: 53 additions & 0 deletions tests/resources/before.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
same-oss:
- version: 0.0.0
source name or path:
- go.mod
license:
- BSD-3-Clause
download location: https://github.com/alecthomas/template
homepage: https://pkg.go.dev/github.com/alecthomas/template
comment: transitive, Cannot connect https://pkg.go.dev/github.com/alecthomas/[email protected],
get info from the latest version.
add-license-oss:
- version: 0.5.6
source name or path:
- go.mod
license:
- MPL-2.0
download location: https://github.com/hashicorp/go-retryablehttp
homepage: https://pkg.go.dev/github.com/hashicorp/go-retryablehttp
comment: transitive
- version: 0.5.6
source name or path:
- go.mod
license:
- MPL-2.0
- Apache-2.0
download location: https://github.com/hashicorp/go-retryablehttp
homepage: https://pkg.go.dev/github.com/hashicorp/go-retryablehttp
comment: transitive
remove-version-oss:
- version: 1.0.1
source name or path:
- go.mod
license:
- MIT
download location: https://github.com/konsorten/go-windows-terminal-sequences
homepage: https://pkg.go.dev/github.com/konsorten/go-windows-terminal-sequences
comment: transitive
- version: 2.0.1
source name or path:
- go.mod
license:
- MIT
download location: https://github.com/konsorten/go-windows-terminal-sequences
homepage: https://pkg.go.dev/github.com/konsorten/go-windows-terminal-sequences
del-test-oss:
- version: 1.0.1
source name or path:
- hi
license:
- MIT
- Apache-2.0
download location: https://github.com/del-test-oss/del-test-oss
homepage: https://github.com/del-test-oss/del-test-oss
49 changes: 34 additions & 15 deletions tests/test_download.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,22 +1,41 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2021 LG Electronics Inc.
# SPDX-License-Identifier: Apache-2.0

import os

import pytest

from fosslight_util.download import cli_download_and_extract
from tests import constants


def test_download_from_github():
# when
target_dir = os.path.join(constants.TEST_RESULT_DIR, "download/example")
success, _, _, _ = cli_download_and_extract("https://github.com/LGE-OSS/example",
target_dir,
"test_result/download_log/example")

# then
assert success is True
assert len(os.listdir(target_dir)) > 0


def main():
success, msg, _, _ = cli_download_and_extract("https://github.com/LGE-OSS/example",
"test_result/download/example",
"test_result/download_log/example")
if not success:
raise Exception(f"Download failed with git:{msg}")
success, msg, _, _ = cli_download_and_extract("https://pypi.org/project/filelock/3.4.1",
"test_result/download/filelock",
"test_result/download_log/filelock")
if not success:
raise Exception(f"Download failed with wget:{msg}")
@pytest.mark.parametrize("project_name, project_url",
[("filelock", "https://pypi.org/project/filelock/3.4.1"),
("dependency", "https://pypi.org/project/fosslight-dependency/3.0.5/"),
("jackson", "https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind/2.12.2"),
("pub", "https://pub.dev/packages/file/versions/5.2.1")])
def test_download_from_wget(project_name, project_url):
# given
target_dir = os.path.join(constants.TEST_RESULT_DIR,
os.path.join("download", project_name))
log_dir = os.path.join(constants.TEST_RESULT_DIR,
os.path.join("download_log" + project_name))

# when
success, _, _, _ = cli_download_and_extract(project_url, target_dir, log_dir)

if __name__ == '__main__':
main()
# then
assert success is True
assert len(os.listdir(target_dir)) > 0
Loading