Skip to content

Commit e4219af

Browse files
authored
Refactor existing tox test to pytest (#24)
1 parent 2c34332 commit e4219af

File tree

3 files changed

+81
-6
lines changed

3 files changed

+81
-6
lines changed

test/conftest.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
# Android binary analysis script
4+
# SPDX-FileCopyrightText: Copyright 2023 LG Electronics Inc.
5+
# SPDX-License-Identifier: Apache-2.0
6+
7+
import os
8+
import subprocess
9+
import pytest
10+
11+
12+
@pytest.fixture
13+
def android_src_path():
14+
return os.getenv("ANDROID_SRC_PATH")
15+
16+
17+
@pytest.fixture
18+
def android_build_log():
19+
return os.getenv("ANDROID_BUILD_LOG")
20+
21+
22+
@pytest.fixture
23+
def run_command():
24+
def _run_command(command):
25+
result = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
26+
success = result.returncode == 0
27+
return success, result.stdout.decode('utf-8'), result.stderr.decode('utf-8')
28+
return _run_command

test/test_tox.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
# Android binary analysis script
4+
# SPDX-FileCopyrightText: Copyright 2023 LG Electronics Inc.
5+
# SPDX-License-Identifier: Apache-2.0
6+
7+
8+
import os
9+
import pytest
10+
11+
12+
@pytest.mark.run
13+
def test_fosslight_android(run_command, android_src_path, android_build_log):
14+
15+
# given
16+
assert android_src_path, "android_src_path is not set."
17+
assert android_build_log, "android_build_log is not set."
18+
19+
# when
20+
command = f"fosslight_android -s {android_src_path} -a {android_build_log} -m"
21+
success, stdout, stderr = run_command(command)
22+
23+
# then
24+
assert success is True, f"fosslight_android test_run failed. stderr: {stderr}"
25+
26+
27+
@pytest.mark.release
28+
def test_release_environment(run_command):
29+
30+
# given
31+
test_result, _, _ = run_command("rm -rf test_result")
32+
os.makedirs("test_result", exist_ok=True)
33+
34+
# when
35+
help_result, _, _ = run_command("fosslight_android -h")
36+
ok_result, _, _ = run_command("fosslight_android -b test/binary.txt -n test/NOTICE.html -c ok")
37+
nok_result, _, _ = run_command("fosslight_android -b test/binary.txt -n test/NOTICE.html -c nok")
38+
divide_result, _, _ = run_command("fosslight_android -d test/needtoadd-notice.html")
39+
40+
# then
41+
assert help_result is True, "Help command failed"
42+
assert ok_result is True, "OK command failed"
43+
assert nok_result is True, "NOK command failed"
44+
assert divide_result is True, "Divide command failed"

tox.ini

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,29 @@ ignore = C901
2121

2222
[pytest]
2323
filterwarnings = ignore::DeprecationWarning
24+
markers =
25+
run: Test for local environment
26+
release: Test for CI environment
2427

2528
[testenv]
2629
install_command = pip install {opts} {packages}
2730

31+
setenv =
32+
ANDROID_SRC_PATH = {[main]android_src_path}
33+
ANDROID_BUILD_LOG = {[main]android_build_log}
34+
2835
[testenv:test_run]
2936
changedir = test
3037

3138
setenv =
3239
PYTHONPATH=.
3340

3441
commands =
35-
fosslight_android -s {[main]android_src_path} -a {[main]android_build_log} -m
42+
pytest -m run
3643

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

4148
commands =
42-
pytest -v --flake8 --ignore=script
43-
fosslight_android -h
44-
fosslight_android -b test/binary.txt -n test/NOTICE.html -c ok
45-
fosslight_android -b test/binary.txt -n test/NOTICE.html -c nok
46-
fosslight_android -d test/needtoadd-notice.html
49+
pytest -v --flake8 --ignore=script -m release

0 commit comments

Comments
 (0)