diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..b249e71 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,79 @@ +pipeline{ + agent any + stages { + stage('env') { + steps { + sh 'printenv' + } + } + + stage('Build') { + agent { + docker { + image 'python:3-alpine' + } + } + steps { + sh 'python -m py_compile sources/add2vals.py sources/calc.py' + } + } + stage('Test') { + + parallel { + stage('on centos') { + agent { + docker { + image 'qnib/pytest' + } + } + steps { + sh 'py.test --verbose --junit-xml test-reports/results.xml sources/test_calc.py || true' + } + post { + always { + junit 'test-reports/results.xml' + } + } + } + stage('on debian') { + agent { + docker { + image 'qnib/pytest' + } + } + steps { + sh 'py.test --verbose --junit-xml test-reports/results.xml sources/test_calc2.py || true' + } + post { + always { + junit 'test-reports/results.xml' + } + + } + } + + } + } + stage('Deliver') { + agent { + docker { + image 'cdrx/pyinstaller-linux:python2' + } + } + steps { + sh 'pyinstaller --onefile sources/add2vals.py' + input message: "Build stage finished.(click to preceded)" + + } + post { + success { + archiveArtifacts 'dist/add2vals' + githubNotify description: 'This is a shorted example', status: 'SUCCESS' + } + + } + } + } + + +} \ No newline at end of file diff --git a/sources/test_calc.py b/sources/test_calc.py index 130f9f7..fe0cbbf 100644 --- a/sources/test_calc.py +++ b/sources/test_calc.py @@ -5,28 +5,30 @@ class TestCalc(unittest.TestCase): """ Test the add function from the calc library """ + # def test_fail(self): + # self.assertFalse(True, msg="This is failed test") - def test_add_integers(self): - """ - Test that the addition of two integers returns the correct total - """ - result = calc.add2(1, 2) - self.assertEqual(result, 3) - - def test_add_floats(self): - """ - Test that the addition of two floats returns the correct result - """ - result = calc.add2('10.5', 2) - self.assertEqual(result, 12.5) - - def test_add_strings(self): - """ - Test the addition of two strings returns the two strings as one - concatenated string - """ - result = calc.add2('abc', 'def') - self.assertEqual(result, 'abcdef') + # def test_add_integers(self): + # """ + # Test that the addition of two integers returns the correct total + # """ + # result = calc.add2(1, 2) + # self.assertEqual(result, 3) + # + # def test_add_floats(self): + # """ + # Test that the addition of two floats returns the correct result + # """ + # result = calc.add2('10.5', 2) + # self.assertEqual(result, 12.5) + # + # def test_add_strings(self): + # """ + # Test the addition of two strings returns the two strings as one + # concatenated string + # """ + # result = calc.add2('abc', 'def') + # self.assertEqual(result, 'abcdef') def test_add_string_and_integer(self): """ diff --git a/sources/test_calc2.py b/sources/test_calc2.py new file mode 100644 index 0000000..28f53bc --- /dev/null +++ b/sources/test_calc2.py @@ -0,0 +1,50 @@ +import unittest +import calc + +class TestCalc(unittest.TestCase): + """ + Test the add function from the calc library + """ + # def test_fail(self): + # self.assertFalse(True, msg="This is failed test") + + def test_add_integers(self): + """ + Test that the addition of two integers returns the correct total + """ + result = calc.add2(1, 2) + self.assertEqual(result, 3) + + def test_add_floats(self): + """ + Test that the addition of two floats returns the correct result + """ + result = calc.add2('10.5', 2) + self.assertEqual(result, 12.5) + + def test_add_strings(self): + """ + Test the addition of two strings returns the two strings as one + concatenated string + """ + result = calc.add2('abc', 'def') + self.assertEqual(result, 'abcdef') + + # def test_add_string_and_integer(self): + # """ + # Test the addition of a string and an integer returns them as one + # concatenated string (in which the integer is converted to a string) + # """ + # result = calc.add2('abc', 3) + # self.assertEqual(result, 'abc3') + # + # def test_add_string_and_number(self): + # """ + # Test the addition of a string and a float returns them as one + # concatenated string (in which the float is converted to a string) + # """ + # result = calc.add2('abc', '5.5') + # self.assertEqual(result, 'abc5.5') + +if __name__ == '__main__': + unittest.main()