mirror of
https://github.com/rpm-software-management/tito.git
synced 2025-02-23 20:22:46 +00:00
Big test refactor.
Introduce unit test framework, disable functional test framework for now, but getting closer to something that's sensible.
This commit is contained in:
parent
698d9962ba
commit
e5e98bc098
8 changed files with 94 additions and 77 deletions
4
HACKING
Normal file
4
HACKING
Normal file
|
@ -0,0 +1,4 @@
|
|||
To run all tests, install the python-nose package and from the root of the
|
||||
project:
|
||||
|
||||
nosetests
|
|
@ -1 +0,0 @@
|
|||
blah blah blah
|
|
@ -1 +0,0 @@
|
|||
omg omg omg
|
|
@ -1 +0,0 @@
|
|||
bbq bbq bbq
|
|
@ -1,29 +0,0 @@
|
|||
Name: tito-test-pkg
|
||||
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
|
||||
|
||||
%description
|
||||
Nobody cares.
|
||||
|
||||
%prep
|
||||
#nothing to do here
|
||||
|
||||
%build
|
||||
#nothing to do here
|
||||
|
||||
%install
|
||||
rm -rf $RPM_BUILD_ROOT
|
||||
|
||||
%clean
|
||||
rm -rf %{buildroot}
|
||||
|
||||
%files
|
||||
%defattr(-,root,root)
|
||||
|
||||
%changelog
|
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (c) 2008-2009 Red Hat, Inc.
|
||||
#
|
||||
|
@ -13,7 +12,9 @@
|
|||
# granted to use or replicate Red Hat trademarks that are incorporated
|
||||
# in this software or its documentation.
|
||||
"""
|
||||
Executes all tests.
|
||||
Functional Tests for Tito's Tagger Module
|
||||
|
||||
NOTE: These tests require a makeshift git repository created in /tmp.
|
||||
"""
|
||||
|
||||
import sys
|
||||
|
@ -22,24 +23,51 @@ import os.path
|
|||
|
||||
import unittest
|
||||
|
||||
# Make sure we run from the source:
|
||||
TEST_SCRIPT_DIR = os.path.abspath(os.path.dirname(sys.argv[0]))
|
||||
print TEST_SCRIPT_DIR
|
||||
SRC_DIR = os.path.normpath(os.path.join(TEST_SCRIPT_DIR, "../src/"))
|
||||
SRC_BIN_DIR = os.path.abspath(os.path.join(TEST_SCRIPT_DIR, "../bin/"))
|
||||
|
||||
import spacewalk.releng.cli # prevents a circular import
|
||||
from spacewalk.releng.common import *
|
||||
import tito.cli # prevents a circular import
|
||||
from tito.common import *
|
||||
|
||||
# A location where we can safely create a test git repository.
|
||||
# WARNING: This location will be destroyed if present.
|
||||
TEST_DIR = '/tmp/titotests/'
|
||||
SINGLE_GIT = os.path.join(TEST_DIR, 'single-project')
|
||||
MULTI_GIT = os.path.join(TEST_DIR, 'multi-project')
|
||||
SINGLE_GIT = os.path.join(TEST_DIR, 'single.git')
|
||||
#MULTI_GIT = os.path.join(TEST_DIR, 'multi.git')
|
||||
|
||||
TEST_SPEC = """
|
||||
Name: tito-test-pkg
|
||||
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
|
||||
|
||||
%description
|
||||
Nobody cares.
|
||||
|
||||
%prep
|
||||
#nothing to do here
|
||||
|
||||
%build
|
||||
#nothing to do here
|
||||
|
||||
%install
|
||||
rm -rf $RPM_BUILD_ROOT
|
||||
|
||||
%clean
|
||||
rm -rf %{buildroot}
|
||||
|
||||
%files
|
||||
%defattr(-,root,root)
|
||||
|
||||
%changelog
|
||||
"""
|
||||
|
||||
def tito(argstring):
|
||||
""" Run the tito script from source with given arguments. """
|
||||
run_command("%s/%s %s" % (SRC_BIN_DIR, 'tito', argstring))
|
||||
print sys.argv[0]
|
||||
run_command("%s %s" % ('tito', argstring))
|
||||
|
||||
def cleanup_test_git_repos():
|
||||
""" Delete the test directory if it exists. """
|
||||
|
@ -53,31 +81,32 @@ def create_test_git_repo(multi_project=False):
|
|||
|
||||
run_command('mkdir -p %s' % TEST_DIR)
|
||||
run_command('mkdir -p %s' % SINGLE_GIT)
|
||||
run_command('mkdir -p %s' % MULTI_GIT)
|
||||
|
||||
run_command('cp -R %s/* %s' % (os.path.join(TEST_SCRIPT_DIR,
|
||||
'fakegitfiles'), SINGLE_GIT))
|
||||
# run_command('mkdir -p %s' % MULTI_GIT)
|
||||
os.chdir(SINGLE_GIT)
|
||||
|
||||
# Write some files to the test git repo:
|
||||
filename = os.path.join(SINGLE_GIT, "a.txt")
|
||||
out_f = open(filename, 'w')
|
||||
out_f.write("BLERG")
|
||||
out_f.close()
|
||||
|
||||
# Write the test spec file:
|
||||
filename = os.path.join(SINGLE_GIT, "tito-test-pkg.spec")
|
||||
out_f = open(filename, 'w')
|
||||
out_f.write(TEST_SPEC)
|
||||
out_f.close()
|
||||
|
||||
run_command('git init')
|
||||
run_command('git add a.txt')
|
||||
run_command('git add b.txt')
|
||||
run_command('git add c.txt')
|
||||
#run_command('git add tito-test-pkg.spec')
|
||||
run_command('git add tito-test-pkg.spec')
|
||||
run_command('git commit -a -m "Initial commit."')
|
||||
|
||||
|
||||
class CliTests(unittest.TestCase):
|
||||
"""
|
||||
Contrarcy to class name, pure unit tests for utility methods used in cli
|
||||
module.
|
||||
"""
|
||||
def test_normalize_class_name(self):
|
||||
class TaggerTests(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
create_test_git_repo()
|
||||
|
||||
|
||||
class InitTests(unittest.TestCase):
|
||||
|
||||
def test_init(self):
|
||||
# Probably already there but just to make sure:
|
||||
os.chdir(SINGLE_GIT)
|
||||
self.assertFalse(os.path.exists(os.path.join(SINGLE_GIT, "rel-eng")))
|
||||
|
@ -88,23 +117,8 @@ class InitTests(unittest.TestCase):
|
|||
self.assertTrue(os.path.exists(os.path.join(SINGLE_GIT, "rel-eng",
|
||||
"tito.props")))
|
||||
|
||||
|
||||
class TaggerTests(unittest.TestCase):
|
||||
|
||||
def test_tag_new_package(self):
|
||||
#tito("tag")
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print("Running tito tests.")
|
||||
|
||||
create_test_git_repo()
|
||||
|
||||
suites = [
|
||||
unittest.makeSuite(InitTests),
|
||||
unittest.makeSuite(TaggerTests),
|
||||
]
|
||||
# Now run the tests, order is important:
|
||||
suite = unittest.TestSuite(suites)
|
||||
unittest.TextTestRunner(verbosity=2).run(suite)
|
0
test/unit/__init__.py
Normal file
0
test/unit/__init__.py
Normal file
31
test/unit/common-tests.py
Normal file
31
test/unit/common-tests.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
#
|
||||
# Copyright (c) 2008-2009 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.
|
||||
|
||||
""" Pure unit tests for tito's common module. """
|
||||
|
||||
from tito.common import *
|
||||
|
||||
import unittest
|
||||
|
||||
class CommonTests(unittest.TestCase):
|
||||
|
||||
def test_normalize_class_name(self):
|
||||
""" Test old spacewalk.releng namespace is converted to tito. """
|
||||
self.assertEquals("tito.builder.Builder",
|
||||
normalize_class_name("tito.builder.Builder"))
|
||||
self.assertEquals("tito.builder.Builder",
|
||||
normalize_class_name("spacewalk.releng.builder.Builder"))
|
||||
self.assertEquals("tito.tagger.VersionTagger",
|
||||
normalize_class_name("spacewalk.releng.tagger.VersionTagger"))
|
||||
|
Loading…
Add table
Reference in a new issue