2010-05-24 11:26:22 -03:00
|
|
|
#
|
|
|
|
# Copyright (c) 2008-2010 Red Hat, Inc.
|
|
|
|
#
|
|
|
|
# This software is licensed to you under the GNU General Public License,
|
|
|
|
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
|
|
|
|
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
|
|
|
|
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
|
|
|
|
# along with this software; if not, see
|
|
|
|
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
|
|
|
|
#
|
|
|
|
# Red Hat trademarks are not licensed under GPLv2. No permission is
|
|
|
|
# granted to use or replicate Red Hat trademarks that are incorporated
|
|
|
|
# in this software or its documentation.
|
|
|
|
|
2014-01-02 15:20:52 -04:00
|
|
|
import os
|
2020-10-06 21:46:42 +02:00
|
|
|
import sys
|
2014-01-02 15:20:52 -04:00
|
|
|
import shutil
|
2010-05-24 11:26:22 -03:00
|
|
|
import tempfile
|
2014-01-02 15:20:52 -04:00
|
|
|
import unittest
|
2010-05-24 11:26:22 -03:00
|
|
|
|
|
|
|
from tito.cli import CLI
|
|
|
|
from tito.common import run_command
|
|
|
|
|
|
|
|
# NOTE: No Name in test spec file as we re-use it for several packages.
|
|
|
|
# Name must be written first.
|
2020-10-06 21:46:42 +02:00
|
|
|
TEST_SPEC_3 = """
|
|
|
|
%{!?python3_sitelib: %define python3_sitelib %(%{__python3} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}
|
|
|
|
|
|
|
|
Version: 0.0.1
|
|
|
|
Release: 1%{?dist}
|
|
|
|
Summary: Tito test package.
|
|
|
|
URL: https://example.com
|
|
|
|
Group: Applications/Internet
|
|
|
|
License: GPLv2
|
|
|
|
BuildRoot: %{_tmppath}/%{name}-root-%(%{__id_u} -n)
|
|
|
|
BuildArch: noarch
|
|
|
|
BuildRequires: python3-devel
|
|
|
|
BuildRequires: python3-setuptools
|
|
|
|
Source0: %{name}-%{version}.tar.gz
|
|
|
|
|
|
|
|
%description
|
|
|
|
Nobody cares.
|
|
|
|
|
|
|
|
%prep
|
|
|
|
#nothing to do here
|
|
|
|
%setup -q -n %{name}-%{version}
|
|
|
|
|
|
|
|
%build
|
|
|
|
%{__python3} setup.py build
|
|
|
|
|
|
|
|
%install
|
|
|
|
rm -rf $RPM_BUILD_ROOT
|
|
|
|
%{__python3} setup.py install -O1 --skip-build --root $RPM_BUILD_ROOT
|
|
|
|
rm -f $RPM_BUILD_ROOT%{python3_sitelib}/*egg-info/requires.txt
|
|
|
|
|
|
|
|
%clean
|
|
|
|
rm -rf %{buildroot}
|
|
|
|
|
|
|
|
%files
|
|
|
|
%defattr(-,root,root)
|
|
|
|
#%dir %{python3_sitelib}/%{name}
|
|
|
|
%{python3_sitelib}/%{name}-*.egg-info
|
|
|
|
|
|
|
|
%changelog
|
|
|
|
"""
|
|
|
|
|
|
|
|
# NOTE: No Name in test spec file as we re-use it for several packages.
|
|
|
|
# Name must be written first.
|
|
|
|
TEST_SPEC_2 = """
|
2010-05-24 11:26:22 -03:00
|
|
|
%{!?python_sitelib: %define python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}
|
|
|
|
|
|
|
|
Version: 0.0.1
|
|
|
|
Release: 1%{?dist}
|
|
|
|
Summary: Tito test package.
|
|
|
|
URL: https://example.com
|
|
|
|
Group: Applications/Internet
|
|
|
|
License: GPLv2
|
|
|
|
BuildRoot: %{_tmppath}/%{name}-root-%(%{__id_u} -n)
|
|
|
|
BuildArch: noarch
|
|
|
|
BuildRequires: python-devel
|
|
|
|
BuildRequires: python-setuptools
|
|
|
|
Source0: %{name}-%{version}.tar.gz
|
|
|
|
|
|
|
|
%description
|
|
|
|
Nobody cares.
|
|
|
|
|
|
|
|
%prep
|
|
|
|
#nothing to do here
|
|
|
|
%setup -q -n %{name}-%{version}
|
|
|
|
|
|
|
|
%build
|
|
|
|
%{__python} setup.py build
|
|
|
|
|
|
|
|
%install
|
|
|
|
rm -rf $RPM_BUILD_ROOT
|
|
|
|
%{__python} setup.py install -O1 --skip-build --root $RPM_BUILD_ROOT
|
|
|
|
rm -f $RPM_BUILD_ROOT%{python_sitelib}/*egg-info/requires.txt
|
|
|
|
|
|
|
|
%clean
|
|
|
|
rm -rf %{buildroot}
|
|
|
|
|
|
|
|
%files
|
|
|
|
%defattr(-,root,root)
|
|
|
|
#%dir %{python_sitelib}/%{name}
|
|
|
|
%{python_sitelib}/%{name}-*.egg-info
|
|
|
|
|
|
|
|
%changelog
|
|
|
|
"""
|
|
|
|
|
|
|
|
TEST_SETUP_PY = """
|
|
|
|
from setuptools import setup, find_packages
|
|
|
|
|
|
|
|
setup(
|
|
|
|
name="%s",
|
|
|
|
version='1.0',
|
|
|
|
description='tito test project',
|
|
|
|
author='Nobody Knows',
|
|
|
|
author_email='tito@example.com',
|
|
|
|
url='http://rm-rf.ca/tito',
|
|
|
|
license='GPLv2+',
|
|
|
|
|
|
|
|
package_dir={
|
|
|
|
'%s': 'src/',
|
|
|
|
},
|
|
|
|
packages = find_packages('src'),
|
|
|
|
include_package_data = True,
|
|
|
|
|
|
|
|
classifiers = [
|
|
|
|
'License :: OSI Approved :: GNU General Public License (GPL)',
|
|
|
|
'Development Status :: 2 - Pre-Alpha',
|
|
|
|
'Environment :: Console',
|
|
|
|
'Intended Audience :: Developers',
|
|
|
|
'Intended Audience :: Information Technology',
|
|
|
|
'Programming Language :: Python'
|
|
|
|
],
|
|
|
|
)
|
|
|
|
"""
|
|
|
|
|
|
|
|
TEST_PYTHON_SRC = """
|
|
|
|
class Empty(object):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
|
2011-12-05 14:37:07 -05:00
|
|
|
|
2010-05-24 11:26:22 -03:00
|
|
|
def tito(argstring):
|
|
|
|
""" Run Tito from source with given arguments. """
|
2010-05-24 23:16:49 -03:00
|
|
|
return CLI().main(argstring.split(' '))
|
2010-05-24 11:26:22 -03:00
|
|
|
|
2011-12-05 14:37:07 -05:00
|
|
|
|
2010-05-24 11:26:22 -03:00
|
|
|
class TitoGitTestFixture(unittest.TestCase):
|
|
|
|
"""
|
|
|
|
Fixture providing setup/teardown and utilities for all tests requiring
|
|
|
|
an actual git repository.
|
|
|
|
"""
|
|
|
|
def setUp(self):
|
2011-12-05 14:37:07 -05:00
|
|
|
# Create a temporary directory for our test git repository:
|
2010-05-24 11:26:22 -03:00
|
|
|
self.repo_dir = tempfile.mkdtemp("-titotest")
|
|
|
|
print
|
|
|
|
print
|
|
|
|
print("Testing in: %s" % self.repo_dir)
|
|
|
|
print
|
|
|
|
|
|
|
|
# Initialize the repo:
|
2014-03-08 22:25:35 +00:00
|
|
|
os.chdir(self.repo_dir)
|
|
|
|
run_command('git init')
|
2010-05-24 11:26:22 -03:00
|
|
|
|
|
|
|
# Next we tito init:
|
|
|
|
tito("init")
|
2015-04-26 14:10:11 +02:00
|
|
|
run_command('echo "offline = true" >> .tito/tito.props')
|
|
|
|
run_command('git add .tito/tito.props')
|
2014-03-08 22:25:35 +00:00
|
|
|
run_command("git commit -m 'set offline in tito.props'")
|
2010-05-24 11:26:22 -03:00
|
|
|
|
2014-01-02 15:20:52 -04:00
|
|
|
def tearDown(self):
|
2014-03-11 11:27:19 -03:00
|
|
|
run_command('chmod -R u+rw %s' % self.repo_dir)
|
2014-01-02 15:20:52 -04:00
|
|
|
pass
|
|
|
|
|
2013-11-12 12:16:12 -04:00
|
|
|
def write_file(self, path, contents):
|
|
|
|
out_f = open(path, 'w')
|
|
|
|
out_f.write(contents)
|
|
|
|
out_f.close()
|
|
|
|
|
2014-01-13 16:29:38 -04:00
|
|
|
def create_project_from_spec(self, pkg_name, config,
|
|
|
|
pkg_dir='', spec=None):
|
2014-01-02 15:20:52 -04:00
|
|
|
"""
|
|
|
|
Create a sample tito project and copy the given test spec file over.
|
|
|
|
"""
|
|
|
|
full_pkg_dir = os.path.join(self.repo_dir, pkg_dir)
|
|
|
|
run_command('mkdir -p %s' % full_pkg_dir)
|
|
|
|
os.chdir(full_pkg_dir)
|
|
|
|
|
|
|
|
shutil.copyfile(spec, os.path.join(full_pkg_dir, os.path.basename(spec)))
|
|
|
|
|
2014-01-13 16:29:38 -04:00
|
|
|
# Write the config object we were given out to the project repo:
|
python 2.4 (rhel 5) does not support 'with...as' syntax
resolves from a73c90cb...
Using Python 2.4
Using nose 0.1
Running tito tests against: /home/sandbox/src
EEEE.Warning: spacewalk.releng.* namespace in tito.props is obsolete. Use tito.* instead.
Warning: spacewalk.releng.* namespace in tito.props is obsolete. Use tito.* instead.
..............................F...........
======================================================================
ERROR: Failure: SyntaxError (invalid syntax (fixture.py, line 159))
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib/python2.4/site-packages/nose/loader.py", line 381, in loadTestsFromName
module = self.importer.importFromPath(
File "/usr/lib/python2.4/site-packages/nose/importer.py", line 39, in importFromPath
return self.importFromDir(dir_path, fqname)
File "/usr/lib/python2.4/site-packages/nose/importer.py", line 86, in importFromDir
mod = load_module(part_fqname, fh, filename, desc)
File "/home/sandbox/test/functional/fetch_tests.py", line 27, in ?
from fixture import TitoGitTestFixture, tito
File "/home/sandbox/test/functional/fixture.py", line 159
with open(os.path.join(full_pkg_dir, 'tito.props'), 'w') \
^
SyntaxError: invalid syntax
2014-02-27 20:27:08 +00:00
|
|
|
configfile = open(os.path.join(full_pkg_dir, 'tito.props'), 'w')
|
|
|
|
config.write(configfile)
|
|
|
|
configfile.close()
|
2014-01-02 15:20:52 -04:00
|
|
|
|
2014-05-04 20:18:02 +01:00
|
|
|
def create_project(self, pkg_name, pkg_dir='', tag=True):
|
2010-05-24 11:26:22 -03:00
|
|
|
"""
|
|
|
|
Create a test project at the given location, assumed to be within
|
|
|
|
our test repo, but possibly within a sub-directory.
|
|
|
|
"""
|
2010-05-24 14:59:50 -03:00
|
|
|
full_pkg_dir = os.path.join(self.repo_dir, pkg_dir)
|
|
|
|
run_command('mkdir -p %s' % full_pkg_dir)
|
|
|
|
os.chdir(full_pkg_dir)
|
2010-05-24 11:26:22 -03:00
|
|
|
|
2011-12-05 14:37:07 -05:00
|
|
|
# TODO: Test project needs work, doesn't work in some scenarios
|
2010-05-24 11:26:22 -03:00
|
|
|
# like UpstreamBuilder:
|
2014-03-11 09:25:45 -03:00
|
|
|
self.write_file(os.path.join(full_pkg_dir, 'a.txt'), "BLERG\n")
|
2010-05-24 11:26:22 -03:00
|
|
|
|
|
|
|
# Write the test spec file:
|
2020-10-06 21:46:42 +02:00
|
|
|
spec = TEST_SPEC_3 if sys.version_info[0] == 3 else TEST_SPEC_2
|
2014-03-11 09:25:45 -03:00
|
|
|
self.write_file(os.path.join(full_pkg_dir, "%s.spec" % pkg_name),
|
2020-10-06 21:46:42 +02:00
|
|
|
"Name: %s\n%s" % (pkg_name, spec))
|
2010-05-24 11:26:22 -03:00
|
|
|
|
|
|
|
# Write test setup.py:
|
2014-03-11 09:25:45 -03:00
|
|
|
self.write_file(os.path.join(full_pkg_dir, "setup.py"),
|
|
|
|
TEST_SETUP_PY % (pkg_name, pkg_name))
|
2010-05-24 11:26:22 -03:00
|
|
|
|
|
|
|
# Write test source:
|
2010-05-24 14:59:50 -03:00
|
|
|
run_command('mkdir -p %s' % os.path.join(full_pkg_dir, "src"))
|
2014-03-11 09:25:45 -03:00
|
|
|
self.write_file(os.path.join(full_pkg_dir, "src", "module.py"),
|
|
|
|
TEST_PYTHON_SRC)
|
2010-05-24 11:26:22 -03:00
|
|
|
|
2010-05-24 14:59:50 -03:00
|
|
|
files = [os.path.join(pkg_dir, 'a.txt'),
|
|
|
|
os.path.join(pkg_dir, 'setup.py'),
|
|
|
|
os.path.join(pkg_dir, '%s.spec' % pkg_name),
|
|
|
|
os.path.join(pkg_dir, 'src/module.py')
|
|
|
|
]
|
2014-03-08 22:25:35 +00:00
|
|
|
run_command('git add %s' % ' '.join(files))
|
|
|
|
run_command("git commit -m 'initial commit'")
|
2010-05-24 11:26:22 -03:00
|
|
|
|
2014-05-04 20:18:02 +01:00
|
|
|
if tag:
|
|
|
|
tito('tag --keep-version --debug --accept-auto-changelog')
|