Skip to content

Commit de10f1f

Browse files
committed
Add Jenkinsfile for IBM i builds
Cherry-pick test updates from upstream f4afa50. This ensures that test.py will return a failing return code when a test fails instead of giving a false positive.
1 parent 2c4cfc3 commit de10f1f

File tree

2 files changed

+73
-46
lines changed

2 files changed

+73
-46
lines changed

IBM_DB/ibm_db/tests.py

+29-46
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,40 @@
11
import os
2+
from os.path import basename, join
23
import sys
34
import unittest
4-
if sys.version_info >= (3, ):
5-
from io import StringIO
6-
else:
7-
from cStringIO import StringIO
8-
import re
95
import glob
106
import config
7+
import importlib
118

12-
class IbmDbTest(unittest.TestCase):
13-
14-
slash = '/'
15-
16-
# Currently, this function serves no purpose.
17-
# However, this function has to be defined if the
18-
# unittest.TestCase is inherited in the given class.
19-
# For future reference, this function is called
20-
# everytime a test is ran in this testsuite.
21-
def setUp(self):
22-
pass
9+
# Test runner for ibm_db. Normally one could use something like:
10+
#
11+
# Run all in the tests directory:
12+
# python -m unittest discover -v -s tests
13+
#
14+
# Run all tests matching specified pattern or specific test:
15+
# python -m unittest discover -v -s tests -p 'test_*FetchAssocSelect*.py'
16+
# python -m unittest discover -v -s tests -p test_006_ConnPassingOpts.py
17+
#
18+
# However, for running all the tests, we need to ensure that test_000_PrepareDb
19+
# is run first to set up the database. Possibly this could be moved to a
20+
# separate task which is run by itself prior to running any tests, which
21+
# would simplify things a bit.
2322

24-
# This function gets a list of all the test files located
25-
# in the current_dir/config.test_dir directory.
26-
def getFileList(self):
27-
if (sys.platform[0:3] == 'win'):
28-
self.slash = '\\'
29-
dir = config.test_dir + self.slash
30-
if (os.environ.get("SINGLE_PYTHON_TEST", None)):
31-
testfile = dir + os.environ.get("SINGLE_PYTHON_TEST", None)
32-
filelist = glob.glob(testfile)
33-
else:
34-
filelist = glob.glob(dir + "test_*.py")
35-
36-
for i in range(0, len(filelist)):
37-
filelist[i] = filelist[i].replace('.py', '')
38-
filelist[i] = filelist[i].replace(config.test_dir + self.slash, '')
39-
filelist.sort()
40-
return filelist
41-
42-
# This function is called to run all the tests.
43-
def runTest(self):
44-
filelist = self.getFileList();
23+
# Override standard test-loading behavior
24+
def load_tests(loader, tests, pattern):
4525
suite = unittest.TestSuite()
4626

47-
sys.path = [os.path.dirname(os.path.abspath(__file__)) + self.slash + config.test_dir] + sys.path[0:]
27+
test_glob = os.environ.get("SINGLE_PYTHON_TEST", "test_*.py")
28+
files = glob.glob(join(config.test_dir, test_glob))
29+
tests = [ basename(_).replace('.py', '') for _ in files ]
30+
tests.sort()
31+
32+
for test in tests:
33+
mod = importlib.import_module(test)
34+
suite.addTest(mod.IbmDbTestCase(test))
4835

49-
for i in range(0, len(filelist)):
50-
exec("import %s" % filelist[i])
51-
testFuncName = filelist[i].replace(config.test_dir + self.slash, '')
52-
exec("suite.addTest(%s.IbmDbTestCase(testFuncName))" % filelist[i])
53-
54-
unittest.TextTestRunner(verbosity=2).run(suite)
36+
return suite
5537

56-
obj = IbmDbTest()
57-
suite = obj.runTest()
38+
if __name__ == '__main__':
39+
sys.path.insert(0, config.test_dir)
40+
unittest.main(verbosity=2)

Jenkinsfile

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
pipeline {
2+
agent {
3+
node {
4+
label 'ibmi'
5+
}
6+
}
7+
8+
environment {
9+
// OBJECT_MODE = '64'
10+
// CC = 'gcc'
11+
// CXX = 'g++'
12+
CFLAGS="-DPASE"
13+
}
14+
15+
stages {
16+
stage('setup') {
17+
steps {
18+
dir("IBM_DB/ibm_db") {
19+
sh 'python3 -m venv --clear .venv'
20+
}
21+
}
22+
}
23+
24+
stage('build') {
25+
steps {
26+
dir("IBM_DB/ibm_db") {
27+
sh '. .venv/bin/activate; pip install .'
28+
}
29+
}
30+
}
31+
32+
stage('test') {
33+
environment {
34+
DATABASE = credentials('database-creds')
35+
}
36+
steps {
37+
dir("IBM_DB/ibm_db") {
38+
sh label: 'setting up config', script:"perl -p -e \"s|sample|*LOCAL|; s|db2inst1|$DATABASE_USR|; s|'password'|'$DATABASE_PSW'|; \" config.py.sample > config.py"
39+
sh '. .venv/bin/activate; python tests.py'
40+
}
41+
}
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)