-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor existing tox test to pytest (#24)
- Loading branch information
Showing
3 changed files
with
81 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters