Commit 0d25b91c authored by Thomas Dowrick's avatar Thomas Dowrick

Issue #13: Change generated project to add/multiply two numbers

parent dc4d92eb
......@@ -3,4 +3,3 @@
# confused with the software requirements, which are listed in
# doc/requirements.rst
numpy
six
......@@ -3,38 +3,25 @@
"""{{ cookiecutter.project_name }} tests"""
from {{ cookiecutter.pkg_name }}.ui.{{ cookiecutter.pkg_name }}_demo import run_demo
from {{ cookiecutter.pkg_name }}.algorithms import addition, multiplication
import six
# Pytest style
def test_using_pytest_{{ cookiecutter.pkg_name }}():
console = True
assert run_demo(console, "Hello World") == True
# Disable this test if root.mainloop is uncommented in
# run_demo()
def test_using_pytest_cookienewwithgitinit_withTK():
try:
import tkinter
try:
console=False
assert run_demo(console, "Hello World") == True
except tkinter.TclError:
six.print_("Got TCL error, probably no DISPLAY set, that's OK.")
assert True
except:
six.print_("Got another error (not TCL), that's not OK.")
assert False
except ModuleNotFoundError:
six.print_("Got module not found on tkinter, please check your python installation")
#we're not trying to test whether we have tkinter so this is ok
assert True
except ImportError:
six.print_("Got import error on tkinter, please check your python installation")
#we're not trying to test whether we have tkinter so this is ok
assert True
except:
assert False
x = 1
y = 2
verbose = False
multiply = False
expected_answer = 3
assert run_demo(x, y, multiply, verbose) == expected_answer
def test_addition():
assert addition.add_two_numbers(1, 2) == 3
def test_multiplication():
assert multiplication.multiply_two_numbers(2, 2) == 4
# coding=utf-8
""" Module for adding numbers. """
def add_two_numbers(input_x, input_y):
""" Add two numbers """
return input_x + input_y
# coding=utf-8
""" Module for multiplying numbers. """
def multiply_two_numbers(input_x, input_y):
""" Multiply two numbers """
return input_x * input_y
......@@ -13,24 +13,33 @@ def main(args=None):
parser = argparse.ArgumentParser(description='{{ cookiecutter.project_name }}')
parser.add_argument("-t", "--text",
required=False,
default="This is {{ cookiecutter.project_name }}",
type=str,
help="Text to display")
parser.add_argument("--console", required=False,
action='store_true',
help="If set, {{ cookiecutter.project_name }} "
"will not bring up a graphical user interface")
## ADD POSITIONAL ARGUMENTS
parser.add_argument("x",
type=int,
help="1st number")
parser.add_argument("y",
type=int,
help="2nd number")
# ADD OPTINAL ARGUMENTS
parser.add_argument("-m", "--multiply",
action="store_true",
help="Enable multiplication of inputs."
)
parser.add_argument("-v", "--verbose",
action="store_true",
help="Enable verbose output",
)
version_string = __version__
friendly_version_string = version_string if version_string else 'unknown'
parser.add_argument(
"-v", "--version",
"--version",
action='version',
version='{{ cookiecutter.project_name }} version ' + friendly_version_string)
args = parser.parse_args(args)
run_demo(args.console, args.text)
run_demo(args.x, args.y, args.multiply, args.verbose)
# coding=utf-8
"""Hello world demo module"""
import six
# Check if tkinter is available
try:
from tkinter import Tk, Label
except ImportError:
TK_AVAILABLE = False
else:
TK_AVAILABLE = True
def run_demo(console, text):
"""Show message"""
six.print_(text)
if not console and TK_AVAILABLE:
root = Tk()
label = Label(root, text=text)
label.pack()
#uncomment root.mainloop() to enter tk main loop.
#Delete any unit tests covering this section first
#though as they will not complete.
#root.mainloop()
return True
from {{ cookiecutter.pkg_name }}.algorithms import addition, multiplication
def run_demo(input_x, input_y, multiply, verbose):
""" Run the application """
if multiply:
result = multiplication.multiply_two_numbers(input_x, input_y)
else:
result = addition.add_two_numbers(input_x, input_y)
if verbose:
if multiply:
print("Calculating {} * {}".format(input_x, input_y))
else:
print("Calculating {} + {}".format(input_x, input_y))
print("Result is {}".format(result))
return result
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment