-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: make the fedora-tox.yml working
This is tricky. Note the sys.path hack in test/unit/__init__.py where we intentionally use the Fedora's default Python libraries with a different Python version selected by Tox. Right now it means that we use, e.g., python3-rpm compiled for Python 3.12 (F39) with Python 3.7 (which probably works because Tox is executed as root in the tox container, overwriting the pre-compiled *.pyc files in container). Some tests need to be skipped in Tox, therefore the skip_if_tox() method. Also, the GitHub's action for 'git checkout' provides somewhat non-standard environment for Tito to work, hence the fix_tox_env() configuration method.
- Loading branch information
Showing
6 changed files
with
65 additions
and
4 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
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
blessed | ||
requests |
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 |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
|
||
import os | ||
import sys | ||
import subprocess | ||
|
||
from contextlib import contextmanager | ||
from unittest.mock import patch, MagicMock | ||
|
@@ -46,6 +47,34 @@ | |
titodirpatch.start() | ||
|
||
|
||
def fix_tox_env(): | ||
""" | ||
If we run in the fedora-tox environment, we need to do some configuration | ||
""" | ||
if "TOX_WORK_DIR" not in os.environ: | ||
return | ||
|
||
dirs = subprocess.check_output( | ||
"rpm -ql python3-libs | grep site-packages$", shell=True, | ||
encoding="utf-8") | ||
for site_dir in dirs.strip().split(): | ||
sys.path.append(site_dir) | ||
|
||
if os.path.exists(os.path.expanduser("~/.gitconfig")): | ||
return | ||
|
||
gconf = ['git', 'config', '--global'] | ||
subprocess.call(gconf + ['user.email', '[email protected]'], cwd="/tmp") | ||
subprocess.call(gconf + ['user.name', 'Your Name'], cwd="/tmp") | ||
subprocess.call(gconf + ['--add', 'safe.directory', '*'], cwd="/tmp") | ||
subprocess.call(gconf + ['init.defaultBranch', 'main'], cwd="/tmp") | ||
# tito tests need 'main' head, do it explicitly for github's checkout | ||
subprocess.call(['git', 'branch', 'main', 'origin/main']) | ||
|
||
|
||
fix_tox_env() | ||
|
||
|
||
def skip_if_rpmbuild(): | ||
""" some tests can't work during rpmbuild """ | ||
# don't do "isdir()", worktrees have .git as a plain file | ||
|
@@ -54,6 +83,12 @@ def skip_if_rpmbuild(): | |
skip("not supported for rpmbuild") | ||
|
||
|
||
def skip_if_tox(): | ||
""" some tests don't work nice with Tox """ | ||
if "TOX_WORK_DIR" in os.environ: | ||
skip("doesn't work in tox") | ||
|
||
|
||
class Capture(object): | ||
class Tee(object): | ||
def __init__(self, stream, silent): | ||
|
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
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
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