Expand tagging tests.

This commit is contained in:
Devan Goodwin 2009-07-25 12:39:22 -03:00
parent 69a108dfad
commit 0de5290258
7 changed files with 52 additions and 26 deletions

View file

@ -17,7 +17,7 @@
import sys
import os.path
from spacewalk.releng.cli import CLI
from tito.cli import CLI
if __name__ == "__main__":
CLI().main()

View file

@ -32,11 +32,11 @@ TEST_SCRIPT_DIR = os.path.abspath(os.path.dirname(sys.argv[0]))
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/"))
os.environ['TITO_SRC_DIR'] = SRC_DIR
os.environ['PYTHONPATH'] = SRC_DIR
os.environ['TITO_SRC_BIN_DIR'] = SRC_BIN_DIR
if __name__ == '__main__':
print("Running tito tests.")
print("Running tito tests against: %s" % SRC_DIR)
import nose
nose.main()

View file

@ -579,7 +579,7 @@ class Builder(object):
# file we're building off. (note that this is a temp copy of the
# spec) Swap out the actual release for one that includes the git
# SHA1 we're building for our test package:
setup_specfile_script = "test-setup-specfile.pl"
setup_specfile_script = get_script_path("test-setup-specfile.pl")
cmd = "%s %s %s %s-%s %s" % \
(
setup_specfile_script,

View file

@ -419,6 +419,9 @@ class TagModule(BaseCliModule):
default=False,
help=("Don't automatically create a changelog "
"entry for this tag if none is found"))
self.parser.add_option("--accept-auto-changelog", action="store_true",
default=False,
help=("Automatically accept the generated changelog."))
def main(self):
BaseCliModule.main(self)
@ -471,9 +474,9 @@ class InitModule(BaseCliModule):
# write out tito.props
out_f = open(filename, 'w')
out_f.write("[globalconfig]\n")
out_f.write("default_builder = %s\n" % DEFAULT_BUILDER)
out_f.write("default_builder = %s\n" % 'tito.builder.Builder')
out_f.write(
"default_tagger = %s\n" % DEFAULT_TAGGER)
"default_tagger = %s\n" % 'tito.tagger.VersionTagger')
out_f.close()
print(" - wrote %s" % GLOBAL_BUILD_PROPS_FILENAME)

View file

@ -20,9 +20,6 @@ import os.path
import sys
import commands
#SCRIPT_DIR = os.path.abspath(os.path.join(os.path.dirname(
# os.path.abspath(sys.argv[0])), "../"))
DEFAULT_BUILD_DIR = "/tmp/spacewalk-build"
@ -202,7 +199,7 @@ def create_tgz(git_root, prefix, commit, relative_dir, rel_eng_dir,
os.chdir(os.path.abspath(git_root))
timestamp = get_commit_timestamp(commit)
timestamp_script = "tar-fixup-stamp-comment.pl"
timestamp_script = get_script_path("tar-fixup-stamp-comment.pl")
#if not os.path.exists(timestamp_script):
# error_out("Unable to locate required script: %s" % timestamp_script)
@ -262,3 +259,15 @@ def normalize_class_name(name):
return name
def get_script_path(scriptname):
"""
Hack to accomodate functional tests running from source, rather than
requiring tito to actually be installed. This variable is only set by
test scripts, normally we assume scripts are on PATH.
"""
# TODO: Would be nice to get rid of this hack.
scriptpath = scriptname # assume on PATH by default
if 'TITO_SRC_BIN_DIR' in os.environ:
bin_dir = os.environ['TITO_SRC_BIN_DIR']
scriptpath = os.path.join(bin_dir, scriptname)
return scriptpath

View file

@ -60,6 +60,7 @@ class VersionTagger(object):
self.git_user, self.git_email))
self._no_auto_changelog = False
self._accept_auto_changelog = False
def run(self, options):
"""
@ -73,6 +74,8 @@ class VersionTagger(object):
" 'tito tag' will accomplish the same thing.")
if options.no_auto_changelog:
self._no_auto_changelog=True
if options.accept_auto_changelog:
self._accept_auto_changelog=True
self._tag_release()
def _tag_release(self):
@ -152,11 +155,12 @@ class VersionTagger(object):
os.write(fd, "\n")
editor = 'vi'
if "EDITOR" in os.environ:
editor = os.environ["EDITOR"]
subprocess.call([editor, name])
if not self._accept_auto_changelog:
# Give the user a chance to edit the generated changelog:
editor = 'vi'
if "EDITOR" in os.environ:
editor = os.environ["EDITOR"]
subprocess.call([editor, name])
os.lseek(fd, 0, 0)
file = os.fdopen(fd)
@ -231,7 +235,7 @@ class VersionTagger(object):
if release:
bump_type = "bump-release"
script_path = "bump-version.pl"
script_path = get_script_path("bump-version.pl")
cmd = "%s %s --specfile %s" % \
(script_path, bump_type, self.spec_file)
run_command(cmd)

View file

@ -32,6 +32,7 @@ TEST_DIR = '/tmp/titotests/'
SINGLE_GIT = os.path.join(TEST_DIR, 'single.git')
#MULTI_GIT = os.path.join(TEST_DIR, 'multi.git')
TEST_PKG_NAME = 'tito-test-pkg'
TEST_SPEC = """
Name: tito-test-pkg
Version: 0.0.1
@ -70,17 +71,21 @@ def tito(argstring):
if 'TITO_SRC_BIN_DIR' in os.environ:
bin_dir = os.environ['TITO_SRC_BIN_DIR']
tito_path = os.path.join(bin_dir, 'tito')
run_command("%s %s" % (tito_path, argstring))
(status, output) = commands.getstatusoutput("%s %s" % (tito_path,
argstring))
if status > 0:
print output
raise Exception()
def cleanup_test_git_repos():
def cleanup_temp_git():
""" Delete the test directory if it exists. """
if os.path.exists(TEST_DIR):
#error_out("Test Git repo already exists: %s" % TEST_DIR)
run_command('rm -rf %s' % TEST_DIR)
def create_test_git_repo(multi_project=False):
def create_temp_git(multi_project=False):
""" Create a test git repository. """
cleanup_test_git_repos()
cleanup_temp_git()
run_command('mkdir -p %s' % TEST_DIR)
run_command('mkdir -p %s' % SINGLE_GIT)
@ -108,9 +113,8 @@ def create_test_git_repo(multi_project=False):
class TaggerTests(unittest.TestCase):
def setUp(self):
create_test_git_repo()
create_temp_git()
# Probably already there but just to make sure:
os.chdir(SINGLE_GIT)
self.assertFalse(os.path.exists(os.path.join(SINGLE_GIT, "rel-eng")))
tito("init")
@ -122,10 +126,16 @@ class TaggerTests(unittest.TestCase):
def tearDown(self):
os.chdir('/tmp') # anywhere but the git repo were about to delete
cleanup_test_git_repos()
cleanup_temp_git()
def test_tag_new_package(self):
#tito("tag")
pass
def test_initial_tag_keep_version(self):
""" Create an initial package tag with --keep-version. """
tito("tag --keep-version --accept-auto-changelog --debug")
check_tag_exists("%s-0.0.1-1" % TEST_PKG_NAME, offline=True)
def test_initial_tag(self):
""" Test creating an initial tag. """
tito("tag --accept-auto-changelog --debug")
check_tag_exists("%s-0.0.2-1" % TEST_PKG_NAME, offline=True)