Skip to content
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
3 changes: 2 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ pytest-flake8
flake8==3.9.2
dataclasses
scanoss
importlib-metadata==4.12.0
importlib-metadata==4.12.0
pytest-xdist
87 changes: 87 additions & 0 deletions tests/test_tox.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2020 LG Electronics Inc.
# SPDX-License-Identifier: Apache-2.0
import os
import subprocess
import pytest
import shutil

remove_directories = ["test_scan", "test_scan2", "test_scan3"]


@pytest.fixture(scope="module", autouse=True)
def setup_test_result_dir():
print("==============setup==============")
for dir in remove_directories:
if os.path.exists(dir):
shutil.rmtree(dir)

yield


def run_command(command):
process = subprocess.run(command, shell=True, capture_output=True, text=True)
success = (process.returncode == 0)
return success, process.stdout if success else process.stderr


def test_run():
scan_success, _ = run_command("fosslight_source -p tests/test_files -j -m -o test_scan")
scan_exclude_success, _ = run_command("fosslight_source -p tests -e test_files/test cli_test.py -j -m -o test_scan2")
scan_files = os.listdir("test_scan")
scan2_files = os.listdir('test_scan2')

assert scan_success is True, "Test Run: Scan command failed"
assert scan_exclude_success is True, "Test Run: Exclude command failed"
assert len(scan_files) > 0, "Test Run: No scan files created in test_scan directory"
assert len(scan2_files) > 0, "Test Run: No scan files created in test_scan2 directory"


def test_help_command():
success, _ = run_command("fosslight_source -h")
assert success is True, "Test Release: Help command failed "


def test_scan_command():
success, _ = run_command("fosslight_source -p tests/test_files -o test_scan/scan_result.csv")
assert success is True, "Test Release: Failed to generate scan result CSV file"

assert os.path.exists("test_scan/scan_result.csv"), "Test Release: scan_result.csv file not generated"

with open("test_scan/scan_result.csv", 'r') as file:
content = file.read()

assert len(content) > 0, "Test Release: scan_result.csv is empty"
print(f"Content of scan_result.csv:\n{content}")


def test_exclude_command():
success, _ = run_command(
"fosslight_source -p tests -e test_files/test cli_test.py -j -m -o test_scan2/scan_exclude_result.csv"
)
assert success is True, "Test release: Exclude scan failded"

assert os.path.exists("test_scan2/scan_exclude_result.csv"), "Test Release: scan_exclude_result.csv file not generated"

with open("test_scan2/scan_exclude_result.csv", 'r') as file:
content = file.read()

assert len(content) > 0, "Test Release: scan_exclude_result.csv is empty"
print(f"Content of scan_exclude_result.csv:\n{content}")


def test_json_command():
success, _ = run_command("fosslight_source -p tests/test_files -m -j -o test_scan3/")
assert success is True, "Test release: Failed to generate JSON files"


def test_ls_test_scan3_command():
files_in_test_scan3 = os.listdir("test_scan3")
assert len(files_in_test_scan3) > 0, "Test Release: test_scan3 is empty"
print(f"Files in test_scan3: {files_in_test_scan3}")


def test_flake8():
success, _ = run_command("flake8 -j 4")
assert success is True, "Flake8: Style check failed"
21 changes: 7 additions & 14 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ allowlist_externals =
cat
rm
ls
pytest
setenv =
PYTHONPATH=.

Expand All @@ -25,29 +26,21 @@ deps =
-r{toxinidir}/requirements-dev.txt

commands =
rm -rf test_scan
fosslight_source -p tests/test_files -j -m -o test_scan
fosslight_source -p tests -e test_files/test cli_test.py -j -m -o test_scan2
pytest tests/test_tox.py::test_run --maxfail=1 --disable-warnings --cache-clear

[testenv:release]
deps =
-r{toxinidir}/requirements-dev.txt

commands =
fosslight_source -h

fosslight_source -p tests/test_files -o test_scan/scan_result.csv
cat test_scan/scan_result.csv

fosslight_source -p tests -e test_files/test cli_test.py -j -m -o test_scan2/scan_exclude_result.csv
cat test_scan2/scan_exclude_result.csv

fosslight_source -p tests/test_files -m -j -o test_scan3/
ls test_scan3/
pytest tests/test_tox.py::test_help_command tests/test_tox.py::test_scan_command \
tests/test_tox.py::test_exclude_command tests/test_tox.py::test_json_command \
--maxfail=1 --disable-warnings

python tests/cli_test.py
pytest -v --flake8

[testenv:flake8]
deps = flake8
commands = flake8
commands =
pytest tests/test_tox.py::test_flake8
Loading