Skip to content

Commit

Permalink
Refactor existing tox test to pytest (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
ena-isme authored Oct 6, 2024
1 parent 2c34332 commit e4219af
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 6 deletions.
28 changes: 28 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Android binary analysis script
# SPDX-FileCopyrightText: Copyright 2023 LG Electronics Inc.
# SPDX-License-Identifier: Apache-2.0

import os
import subprocess
import pytest


@pytest.fixture
def android_src_path():
return os.getenv("ANDROID_SRC_PATH")


@pytest.fixture
def android_build_log():
return os.getenv("ANDROID_BUILD_LOG")


@pytest.fixture
def run_command():
def _run_command(command):
result = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
success = result.returncode == 0
return success, result.stdout.decode('utf-8'), result.stderr.decode('utf-8')
return _run_command
44 changes: 44 additions & 0 deletions test/test_tox.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Android binary analysis script
# SPDX-FileCopyrightText: Copyright 2023 LG Electronics Inc.
# SPDX-License-Identifier: Apache-2.0


import os
import pytest


@pytest.mark.run
def test_fosslight_android(run_command, android_src_path, android_build_log):

# given
assert android_src_path, "android_src_path is not set."
assert android_build_log, "android_build_log is not set."

# when
command = f"fosslight_android -s {android_src_path} -a {android_build_log} -m"
success, stdout, stderr = run_command(command)

# then
assert success is True, f"fosslight_android test_run failed. stderr: {stderr}"


@pytest.mark.release
def test_release_environment(run_command):

# given
test_result, _, _ = run_command("rm -rf test_result")
os.makedirs("test_result", exist_ok=True)

# when
help_result, _, _ = run_command("fosslight_android -h")
ok_result, _, _ = run_command("fosslight_android -b test/binary.txt -n test/NOTICE.html -c ok")
nok_result, _, _ = run_command("fosslight_android -b test/binary.txt -n test/NOTICE.html -c nok")
divide_result, _, _ = run_command("fosslight_android -d test/needtoadd-notice.html")

# then
assert help_result is True, "Help command failed"
assert ok_result is True, "OK command failed"
assert nok_result is True, "NOK command failed"
assert divide_result is True, "Divide command failed"
15 changes: 9 additions & 6 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,29 @@ ignore = C901

[pytest]
filterwarnings = ignore::DeprecationWarning
markers =
run: Test for local environment
release: Test for CI environment

[testenv]
install_command = pip install {opts} {packages}

setenv =
ANDROID_SRC_PATH = {[main]android_src_path}
ANDROID_BUILD_LOG = {[main]android_build_log}

[testenv:test_run]
changedir = test

setenv =
PYTHONPATH=.

commands =
fosslight_android -s {[main]android_src_path} -a {[main]android_build_log} -m
pytest -m run

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

commands =
pytest -v --flake8 --ignore=script
fosslight_android -h
fosslight_android -b test/binary.txt -n test/NOTICE.html -c ok
fosslight_android -b test/binary.txt -n test/NOTICE.html -c nok
fosslight_android -d test/needtoadd-notice.html
pytest -v --flake8 --ignore=script -m release

0 comments on commit e4219af

Please sign in to comment.