diff --git a/.github/workflows/fedora-tox.yml b/.github/workflows/fedora-tox.yml index 823af2d..efab874 100644 --- a/.github/workflows/fedora-tox.yml +++ b/.github/workflows/fedora-tox.yml @@ -12,13 +12,28 @@ jobs: tox_test: name: Tox test steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Run Tox tests id: test uses: fedora-python/tox-github-action@main with: tox_env: ${{ matrix.tox_env }} - dnf_install: python3-rpm + dnf_install: > + asciidoc + createrepo_c + docbook-style-xsl + git + git + git-annex + libxslt + python3-bugzilla + python3-rpm + rpm-build + rpmdevtools + rsync + which strategy: matrix: tox_env: diff --git a/requirements.txt b/requirements.txt index d43de1b..a69c6bc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ blessed +requests diff --git a/test/unit/__init__.py b/test/unit/__init__.py index f3e7f74..4d1b797 100644 --- a/test/unit/__init__.py +++ b/test/unit/__init__.py @@ -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 = patch("tito.cli.DEFAULT_BUILD_DIR", titodir) 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', 'you@example.com'], 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): diff --git a/test/unit/pep8_tests.py b/test/unit/pep8_tests.py index a844c34..cffbc41 100644 --- a/test/unit/pep8_tests.py +++ b/test/unit/pep8_tests.py @@ -32,9 +32,11 @@ except ImportError: import unittest +from unit.fixture import TitoUnitTestFixture, REPO_DIR +from unit import skip_if_tox + from tito.compat import * # NOQA from tito.compat import StringIO, redirect_stdout -from unit.fixture import TitoUnitTestFixture, REPO_DIR class TestPep8(TitoUnitTestFixture): @@ -94,6 +96,8 @@ class TestPep8(TitoUnitTestFixture): class UglyHackishTest(TitoUnitTestFixture): def setUp(self): + # These tests give false-positives for .tox/ directory + skip_if_tox() TitoUnitTestFixture.setUp(self) os.chdir(REPO_DIR) diff --git a/test/unit/tagger_tests.py b/test/unit/tagger_tests.py index 18dd94b..dfb3943 100644 --- a/test/unit/tagger_tests.py +++ b/test/unit/tagger_tests.py @@ -1,10 +1,11 @@ +import os import unittest from unittest import mock from datetime import datetime from tito.tagger import VersionTagger from tito.compat import PY2, RawConfigParser -from unit import is_epel6, skip_if_rpmbuild +from unit import is_epel6, skip_if_rpmbuild, srcdir if is_epel6: import unittest2 as unittest else: @@ -22,6 +23,7 @@ def strftime_mock(s): class TestVersionTagger(unittest.TestCase): def setUp(self): skip_if_rpmbuild() + os.chdir(srcdir) self.config = RawConfigParser() @mock.patch("tito.tagger.main.strftime", strftime_mock) diff --git a/tox.ini b/tox.ini index 438fb94..c965e8b 100644 --- a/tox.ini +++ b/tox.ini @@ -20,7 +20,11 @@ skipsdist = True deps = -rrequirements.txt coverage + pycodestyle pytest pytest-cov commands = python -m pytest -v {posargs} --cov-report term-missing --cov-branch --cov +setenv = + PYTHONPATH = ./src +syspaths = True