Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix testsuite #504

Merged
merged 13 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions .github/workflows/fedora-tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,37 @@ 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: >
asciidoc
createrepo_c
docbook-style-xsl
git
git
git-annex
libxslt
python3-bugzilla
python3-rpm
rpm-build
rpmdevtools
rsync
which
strategy:
matrix:
tox_env:
# sync with /tox.ini
- py36
- py37
- py310
- py311
- py312
- py313

# Use GitHub's Linux Docker host
runs-on: ubuntu-latest
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*$py.class
*.swp
*.swo
.noseids
*.patch
*#
*~
Expand All @@ -14,6 +13,8 @@ MANIFEST
dist
build
.build
.coverage
.test-titodir
titorc.5
titorc.5.xml
tito.8
Expand Down
7 changes: 3 additions & 4 deletions HACKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ an authoring environment, too.

To run all tests, install these packages:

* python-nose, python-pep8, python-mock (for epl-6 and fedora) and rpm-python
* python3-nose, python3-pep8, python3-mock (for epl-6 and fedora) , and rpm-python3
* pytest, python-pep8, python-mock (for epl-6 and fedora) and rpm-python
* pytest, python3-pep8, python3-mock (for epl-6 and fedora) , and rpm-python3
* createrepo_c
* git-annex

Expand All @@ -98,8 +98,7 @@ for python 2.4 - 2.7 (in case you don't have pip, install via yum python-pip pac

Then from the root of the project:

python ./runtests.py -vv
python3 ./runtests.py -vv
./runtests.sh


### Advanced
Expand Down
3 changes: 3 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pytest]
python_files = test/*.py test/*/*.py
pythonpath = src
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
blessed
requests
48 changes: 0 additions & 48 deletions runtests.py

This file was deleted.

10 changes: 10 additions & 0 deletions runtests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#! /bin/bash -e
cov=--cov
args=()
for arg; do
case $arg in
--no-cov) cov= ;;
*) args+=( "$arg" )
esac
done
PYTHONPATH=$PWD/src exec python3 -m pytest -vv $cov "${args[@]}"
8 changes: 4 additions & 4 deletions src/tito/builder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import shutil
import rpm
from pkg_resources import require
from distutils.version import LooseVersion as loose_version
from tempfile import mkdtemp

from tito.common import scl_to_rpm_option, get_latest_tagged_version, \
Expand All @@ -34,7 +33,8 @@
find_cheetah_template_file, render_cheetah, replace_spec_release, \
find_spec_like_file, warn_out, get_commit_timestamp, chdir, mkdir_p, \
find_git_root, info_out, munge_specfile, BUILDCONFIG_SECTION
from tito.compat import getstatusoutput, getoutput, urlparse, urlretrieve
from tito.compat import (getstatusoutput, getoutput, urlparse, urlretrieve,
Version)
from tito.exception import RunCommandException
from tito.exception import TitoException
from tito.config_object import ConfigObject
Expand Down Expand Up @@ -406,8 +406,8 @@ def __init__(self, name=None, tag=None, build_dir=None,

if self.config.has_section("requirements"):
if self.config.has_option("requirements", "tito"):
if loose_version(self.config.get("requirements", "tito")) > \
loose_version(require('tito')[0].version):
if Version(self.config.get("requirements", "tito")) > \
Version(require('tito')[0].version):
error_out([
"tito version %s or later is needed to build this project." %
self.config.get("requirements", "tito"),
Expand Down
4 changes: 0 additions & 4 deletions src/tito/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@
from tito.compat import RawConfigParser, getstatusoutput, getoutput
from tito.exception import TitoException

# Hack for Python 2.4, seems to require we import these so they get compiled
# before we try to dynamically import them based on a string name.
import tito.tagger # NOQA

PROGNAME = "tito"
TITO_PROPS = "tito.props"
RELEASERS_CONF_FILENAME = "releasers.conf"
Expand Down
7 changes: 7 additions & 0 deletions src/tito/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,20 @@
# in this software or its documentation.

# flake8: noqa
# pylint: disable=unused-import,deprecated-module,function-redefined

"""
Compatibility library for Python 2.4 up through Python 3.
"""
import os
import sys
import contextlib

try:
from packaging.version import Version
except ImportError:
from distutils.version import LooseVersion as Version

ENCODING = sys.getdefaultencoding()
PY2 = sys.version_info[0] == 2
if PY2:
Expand Down
5 changes: 5 additions & 0 deletions test/functional/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""
Tito testsuite - config for test/functional.
"""

from unit import titodirpatch # noqa: F401
17 changes: 7 additions & 10 deletions test/functional/build_gitannex_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
import tempfile
import sys
import shutil
from nose.plugins.skip import SkipTest
from os.path import join
from pytest import skip

from functional.fixture import TitoGitTestFixture, tito

from tito.compat import * # NOQA
from tito.compat import (getstatusoutput, RawConfigParser)
from tito.common import run_command
from tito.builder import GitAnnexBuilder

Expand All @@ -41,12 +41,9 @@ def setUp(self):
# Guess based on python version.
# Do not use anything based on uname in case we are in container.
# Do not use `lsb_release` to avoid dependencies.
if sys.version[0:3] == '2.4':
raise SkipTest('git-annex is not available in epel-5')

status, ga_version = getstatusoutput('rpm -q git-annex')
if status != 0:
raise SkipTest("git-annex is missing")
skip("git-annex is missing")

# Setup test config:
self.config = RawConfigParser()
Expand Down Expand Up @@ -82,12 +79,12 @@ def test_simple_build(self):
builder = GitAnnexBuilder(PKG_NAME, None, self.output_dir,
self.config, {}, {}, **{'offline': True})
builder.rpm()
self.assertEquals(1, len(list(builder.sources)))
self.assertEqual(1, len(list(builder.sources)))

self.assertEquals(2, len(builder.artifacts))
self.assertEquals(1, len(glob.glob(join(self.output_dir,
self.assertEqual(2, len(builder.artifacts))
self.assertEqual(1, len(glob.glob(join(self.output_dir,
"extsrc-0.0.2-1.*src.rpm"))))
self.assertEquals(1, len(glob.glob(join(self.output_dir, 'noarch',
self.assertEqual(1, len(glob.glob(join(self.output_dir, 'noarch',
"extsrc-0.0.2-1.*.noarch.rpm"))))
builder.cleanup()

Expand Down
6 changes: 5 additions & 1 deletion test/functional/build_tito_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,20 @@
from glob import glob
from os.path import join

from unit import skip_if_rpmbuild


class BuildTitoTests(unittest.TestCase):

@classmethod
def setUpClass(self):
'Run tito build before _all_ tests in this class.'
skip_if_rpmbuild()

self.output_dir = tempfile.mkdtemp("-titotestoutput")
os.chdir(os.path.abspath(join(__file__, '..', '..', '..')))
self.artifacts = tito(
'build --rpm --test --output=%s --offline --no-cleanup --debug' %
'build --rpm --rpmbuild-options=--without=check --output=%s --offline --no-cleanup --debug' %
self.output_dir
)

Expand Down
17 changes: 10 additions & 7 deletions test/functional/fetch_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@

from os.path import join

from tito.common import run_command
from tito.compat import * # NOQA
from functional.fixture import TitoGitTestFixture, tito
from unit import Capture, is_epel6, is_rawhide
from unit import Capture, is_epel6, is_rawhide, skip_if_rpmbuild

from tito.common import run_command
from tito.compat import RawConfigParser

if is_epel6:
import unittest2 as unittest
Expand Down Expand Up @@ -83,14 +84,16 @@ def tearDown(self):

def test_simple_build_no_tag(self):
# We have not tagged here. Build --rpm should just work:
skip_if_rpmbuild()

self.assertFalse(os.path.exists(
join(self.pkg_dir, '.tito/packages/extsrc')))

tito('build --rpm --output=%s --no-cleanup --debug --arg=source=%s ' %
(self.output_dir, self.source_filename))
self.assertEquals(1, len(glob.glob(join(self.output_dir,
self.assertEqual(1, len(glob.glob(join(self.output_dir,
"extsrc-0.0.2-1.*src.rpm"))))
self.assertEquals(1, len(glob.glob(join(self.output_dir,
self.assertEqual(1, len(glob.glob(join(self.output_dir,
"noarch/extsrc-0.0.2-1.*noarch.rpm"))))

def test_tag_rejected(self):
Expand All @@ -113,7 +116,7 @@ def test_with_releaser(self):
tito('release --debug yum-test --arg source=%s' %
self.source_filename)

self.assertEquals(1, len(glob.glob(join(yum_repo_dir,
self.assertEqual(1, len(glob.glob(join(yum_repo_dir,
"extsrc-0.0.2-1.*noarch.rpm"))))
self.assertEquals(1, len(glob.glob(join(yum_repo_dir,
self.assertEqual(1, len(glob.glob(join(yum_repo_dir,
"repodata/repomd.xml"))))
12 changes: 6 additions & 6 deletions test/functional/multiproject_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def test_template_version_tagger(self):
os.chdir(os.path.join(self.repo_dir, 'pkg3'))
tito('tag --debug --accept-auto-changelog')
new_ver = get_latest_tagged_version(TEST_PKG_3)
self.assertEquals("0.0.2-1", new_ver)
self.assertEqual("0.0.2-1", new_ver)

dest_file = os.path.join(self.repo_dir, 'pkg3', "version.txt")
self.assertTrue(os.path.exists(dest_file))
Expand Down Expand Up @@ -133,24 +133,24 @@ def test_release_tagger_use_release(self):
os.chdir(os.path.join(self.repo_dir, 'pkg2'))
tito('tag --debug --accept-auto-changelog --use-release 42')
new_ver = get_latest_tagged_version(TEST_PKG_2)
self.assertEquals(new_ver.split('-')[-1], "42")
self.assertEqual(new_ver.split('-')[-1], "42")

def test_release_tagger_use_version(self):
os.chdir(os.path.join(self.repo_dir, 'pkg2'))
start_ver = get_latest_tagged_version(TEST_PKG_2)
tito('tag --debug --accept-auto-changelog --use-version 1.3.37')
new_ver = get_latest_tagged_version(TEST_PKG_2)
self.assertFalse(release_bumped(start_ver, new_ver))
self.assertEquals(new_ver, "1.3.37-1")
self.assertEqual(new_ver, "1.3.37-1")

def test_build_tgz(self):
os.chdir(os.path.join(self.repo_dir, 'pkg1'))
artifacts = tito('build --tgz')
self.assertEquals(1, len(artifacts))
self.assertEquals('%s-0.0.1.tar.gz' % TEST_PKG_1,
self.assertEqual(1, len(artifacts))
self.assertEqual('%s-0.0.1.tar.gz' % TEST_PKG_1,
os.path.basename(artifacts[0]))

def test_build_rpm(self):
os.chdir(os.path.join(self.repo_dir, 'pkg1'))
artifacts = tito('build --rpm')
self.assertEquals(3, len(artifacts))
self.assertEqual(3, len(artifacts))
Loading
Loading