Merge 28ce92c0c4
into 128e9ba59f
This commit is contained in:
commit
ca88f886b1
6 changed files with 18 additions and 119 deletions
16
Jenkinsfile
vendored
Normal file
16
Jenkinsfile
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
pipeline {
|
||||
agent none
|
||||
stages {
|
||||
stage('Build') {
|
||||
agent {
|
||||
docker {
|
||||
image 'python:2-alpine'
|
||||
}
|
||||
}
|
||||
steps {
|
||||
sh 'python -m py_compile sources/helloWorld.py'
|
||||
stash(name: 'compiled-results', includes: 'sources/*.py*')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
18
README.md
18
README.md
|
@ -1,18 +0,0 @@
|
|||
# simple-python-pyinstaller-app
|
||||
|
||||
This repository is for the
|
||||
[Build a Python app with PyInstaller](https://jenkins.io/doc/tutorials/build-a-python-app-with-pyinstaller/)
|
||||
tutorial in the [Jenkins User Documentation](https://jenkins.io/doc/).
|
||||
|
||||
The repository contains a simple Python application which is a command line tool "add2vals" that outputs the addition of two values. If at least one of the
|
||||
values is a string, "add2vals" treats both values as a string and instead
|
||||
concatenates the values. The "add2" function in the "calc" library (which
|
||||
"add2vals" imports) is accompanied by a set of unit tests. These are tested with pytest to check that this function works as expected and the results are saved
|
||||
to a JUnit XML report.
|
||||
|
||||
The delivery of the "add2vals" tool through PyInstaller converts this tool into
|
||||
a standalone executable file for Linux, which you can download through Jenkins
|
||||
and execute at the command line on Linux machines without Python.
|
||||
|
||||
The `jenkins` directory contains an example of the `Jenkinsfile` (i.e. Pipeline)
|
||||
you'll be creating yourself during the tutorial.
|
|
@ -1,25 +0,0 @@
|
|||
'''
|
||||
A simple command line tool that takes 2 values and adds them together using
|
||||
the calc.py library's 'add2' function.
|
||||
'''
|
||||
|
||||
import sys
|
||||
import calc
|
||||
|
||||
argnumbers = len(sys.argv) - 1
|
||||
|
||||
if argnumbers == 2 :
|
||||
print("")
|
||||
print("The result is " + str(calc.add2(str(sys.argv[1]), str(sys.argv[2]))))
|
||||
print("")
|
||||
sys.exit(0)
|
||||
|
||||
if argnumbers != 2 :
|
||||
print("")
|
||||
print("You entered " + str(argnumbers) + " value/s.")
|
||||
print("")
|
||||
print("Usage: 'add2vals X Y' where X and Y are individual values.")
|
||||
print(" If add2vals is not in your path, usage is './add2vals X Y'.")
|
||||
print(" If unbundled, usage is 'python add2vals.py X Y'.")
|
||||
print("")
|
||||
sys.exit(1)
|
|
@ -1,28 +0,0 @@
|
|||
'''
|
||||
The 'calc' library contains the 'add2' function that takes 2 values and adds
|
||||
them together. If either value is a string (or both of them are) 'add2' ensures
|
||||
they are both strings, thereby resulting in a concatenated result.
|
||||
NOTE: If a value submitted to the 'add2' function is a float, it must be done so
|
||||
in quotes (i.e. as a string).
|
||||
'''
|
||||
|
||||
# If 'value' is not an integer, convert it to a float and failing that, a string.
|
||||
def conv(value):
|
||||
try:
|
||||
return int(value)
|
||||
except ValueError:
|
||||
try:
|
||||
return float(value)
|
||||
except ValueError:
|
||||
return str(value)
|
||||
|
||||
# The 'add2' function itself
|
||||
def add2(arg1, arg2):
|
||||
# Convert 'arg1' and 'arg2' to their appropriate types
|
||||
arg1conv = conv(arg1)
|
||||
arg2conv = conv(arg2)
|
||||
# If either 'arg1' or 'arg2' is a string, ensure they're both strings.
|
||||
if isinstance(arg1conv, str) or isinstance(arg2conv, str):
|
||||
arg1conv = str(arg1conv)
|
||||
arg2conv = str(arg2conv)
|
||||
return arg1conv + arg2conv
|
2
sources/helloWorld.py
Normal file
2
sources/helloWorld.py
Normal file
|
@ -0,0 +1,2 @@
|
|||
print("Hello world!")
|
||||
print("Adding more code")
|
|
@ -1,48 +0,0 @@
|
|||
import unittest
|
||||
import calc
|
||||
|
||||
class TestCalc(unittest.TestCase):
|
||||
"""
|
||||
Test the add function from the calc library
|
||||
"""
|
||||
|
||||
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()
|
Loading…
Reference in a new issue