From 0dd9400aa339eeeef85d30828b7960ea5de77954 Mon Sep 17 00:00:00 2001 From: Yuriy Taraday Date: Tue, 5 Jul 2011 18:08:41 +0400 Subject: Various fixes for test running. Made sampledata.sh fail if one step fails. Made run_tests.py use all files related to its dir. Add check whether data is loaded and server is started. --- bin/sampledata.sh | 2 +- keystone/test/run_tests.py | 52 +++++++++++++++++++++++++++------------------- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/bin/sampledata.sh b/bin/sampledata.sh index bec2d0c5..689e8077 100755 --- a/bin/sampledata.sh +++ b/bin/sampledata.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash -e # vim: tabstop=4 shiftwidth=4 softtabstop=4 # Copyright 2010 United States Government as represented by the diff --git a/keystone/test/run_tests.py b/keystone/test/run_tests.py index b1292fc4..190f632d 100644 --- a/keystone/test/run_tests.py +++ b/keystone/test/run_tests.py @@ -1,26 +1,36 @@ +import os import subprocess import time if __name__ == '__main__': - #remove pre-existing test databases - subprocess.call(['rm', 'keystone.db']) - subprocess.call(['rm', 'keystone.token.db']) + test_dir = os.path.dirname(__file__) - # populate the test database - subprocess.call(['../../bin/sampledata.sh']) - - # run the keystone server - server = subprocess.Popen(['../../bin/keystone']) - - # blatent hack. - time.sleep(3) - - # run tests - subprocess.call(['python', 'unit/test_keystone.py']) - - #kill the keystone server - server.kill() - - # remove test databases - subprocess.call(['rm', 'keystone.db']) - subprocess.call(['rm', 'keystone.token.db']) + #remove pre-existing test databases + subprocess.call(['rm', os.path.join(test_dir, 'keystone.db')]) + subprocess.call(['rm', os.path.join(test_dir, 'keystone.token.db')]) + + # populate the test database + subprocess.check_call([os.path.join(test_dir, '../../bin/sampledata.sh')]) + + try: + # run the keystone server + server = subprocess.Popen([os.path.join(test_dir, + '../../bin/keystone')]) + + # blatent hack. + time.sleep(3) + if server.poll() is not None: + print >>sys.stderr, 'Failed to start server' + sys.exit(-1) + + try: + # run tests + subprocess.check_call(['python', + os.path.join(test_dir, 'unit/test_keystone.py')]) + finally: + #kill the keystone server + server.kill() + finally: + # remove test databases + subprocess.call(['rm', os.path.join(test_dir, 'keystone.db')]) + subprocess.call(['rm', os.path.join(test_dir, 'keystone.token.db')]) -- cgit