BBD Hands-on with Python. Practical Hands-on Workshop about "Behaviour Driven Development", implementing the Game "CodeBreaker" on Python 2.7 as Example
BBD Hands-on with Python. Practical Hands-on Workshop about "Behaviour Driven Development", implementing the Game "CodeBreaker" on Python 2.7 as Example.
BarCamp Hannover, 2014-06-22, 14:45 Room "GfK"
Lecturer: Rolf Hemmerling
Similar to BBD Hands-on with Python. Practical Hands-on Workshop about "Behaviour Driven Development", implementing the Game "CodeBreaker" on Python 2.7 as Example
Similar to BBD Hands-on with Python. Practical Hands-on Workshop about "Behaviour Driven Development", implementing the Game "CodeBreaker" on Python 2.7 as Example (20)
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
BBD Hands-on with Python. Practical Hands-on Workshop about "Behaviour Driven Development", implementing the Game "CodeBreaker" on Python 2.7 as Example
1. 2015-03-28 - 2015-03-29 BDD Hands-on with Python 1
BBD Hands-on with Python
Practical Hands-on Workshop about
"Behaviour Driven Development", implementing
the Game "CodeBreaker" on Python 2.7 as
Example
PythonCamp Cologne, 2015-03-28 - 2015-03-29
Lecturer: Rolf Hemmerling
Slides: http://www.slideshare.net/hemmerling/
License: Creative Commons - Attribution-ShareAlike 4.0 Generic (
http://www.creativecommons.org/licenses/by-sa/4.0/ )
2. 2015-03-28 - 2015-03-29 BDD Hands-on with Python 2
Agenda
1. CodeBreaker – The Game
2. Gherkin – The BDD Language
3. GUI Design Process
4. Coding..
5. PEP8 Compliance
6. Setup by distutils, Installation by setup.py, Publication on
GitHub, Test & Correction
7. Project Feedback
8. Project Roadmap
9. Resources
3. 2015-03-28 - 2015-03-29 BDD Hands-on with Python 3
1 CodeBreaker – The Game
● Goal: You have to guess a 4-digit secret number
● Howto: You get hints after each guess
● "+" = Right Number at right place
● "-" = Right number, but wrong place
● End of Game: If you got the right number
Example:
Secret Number = "1134"
Guess = "5115"
Hint = "+-"
4. 2015-03-28 - 2015-03-29 BDD Hands-on with Python 4
2.1 Gherkin – The BDD Language
Feature: code-breaker starts game
As a code-breaker
I want to start a game
So that I can break the code
@StartGame
Scenario: start game
Given I am not yet playing
When I start a new game
Then I should see "Welcome to Codebreaker!"
And I should see "Enter guess:"
5. 2015-03-28 - 2015-03-29 BDD Hands-on with Python 5
2.2 Gherkin – The BDD Language
Feature: code-breaker submits guess
Scenario Outline: submit guess
Given the secret code is "<code>"
When I guess "<guess>"
Then the mark should be "<mark>"
Scenarios: no matches
| code | guess | mark |
| 1234 | 5555 | |
Scenarios: 1 number correct
| code | guess | mark |
| 1234 | 1555 | + |
| 1234 | 2555 | - |
6. 2015-03-28 - 2015-03-29 BDD Hands-on with Python 6
2.3 BDD Process, Step #1
.feature File BDD source File
code
Native language Executable test
code
7. 2015-03-28 - 2015-03-29 BDD Hands-on with Python 7
2.4 BDD Process, Step 2..n
.feature BDD Application
Source Code Source Code
Native Executable Executable
language test code application
code
executable complies
specification
.feature BDD Application
Source Code Source Code
Native Executable Executable
language test code application
code
executable complies
specification
8. 2015-03-28 - 2015-03-29 BDD Hands-on with Python 8
3.1 GUI Design Process - Tools
# GUI Designer The generated code
Name Platform GUI
Framwork
Screen
Layout
Class Runtime License Ok?
1 page Tcl/Tk Tkinter Grid Yes Yes
2 ptkgb Python Tkinter Grid Yes Python megawidgets
(pmw)
MIT Yes
3 ptkgen Python Tkinter Grid No tkgen GPL 2.1 Yes
4 pygubu Python TkInter Grid Yes pygubu GPL 3 Yes
5 QT Creator Python QT, PyQT Grid Yes PyQT, QT GPL 2 or 3 Yes
6 rapyd Python Tkinter Grid Yes rpErrorHandler.py Public
Domain?
Not yet
6 SpecTCL Python Tkinter Grid Yes Yes
7 tk_happy Python Tkinter Place Yes Yes
9 Visual Python
Tkinter IDE
1v1.6
.NET Tkinter Place No No
9. 2015-03-28 - 2015-03-29 BDD Hands-on with Python 9
● If the code by GUI designers needs a runtime, what is
the runtime's license ( GPL, LGPL, MIT, public
domain,..)?
● Efficent naming - When selecting names for GUI
designer objects, think of Python naming conventions!
– Class => CamelCode
– Class method / function => Lowercase & underscore
– Variable
● Global variable => Capitals only
● Local variable => Lowercase & underscore
3.2 GUI Design Process - Practice
10. 2015-03-28 - 2015-03-29 BDD Hands-on with Python 10
1. Domain expert of the customer and software developer
● Creation of BDD documents
2. Software developer
➢ Auto-generation of a basic script
– PowerShell.exe -ExecutionPolicy Unrestricted
➢ behave my.feature 2>&1 >my.py
➢ Make the script runable ( avoid $FF in the file )
➢ Implement a step
➢ Implement steps with variables
➢ Implement steps with regular expressions
➢ Test-driven Implementation of the application, using PyUnit
4 Coding...
11. 2015-03-28 - 2015-03-29 BDD Hands-on with Python 11
3 Domain expert of the customer and software developer
● Integration test of the application
● Presentation and roll-out of the application
● Project feedback
4 Coding...
12. 2015-03-28 - 2015-03-29 BDD Hands-on with Python 12
● Most GUI designers create code which
● Doesn´t complie with PEP8...
● Isn't passed by codecheckers ( PyLint.. ) without much warnings...
● Often doesn´t meet the Python naming conventions,
– By the tool
– Or by user's wrong choice when using the tool!
● Love it or leave it!
● If you must complete the generated code files, manually
– If you know that you will or can never use the GUI designer again, then you
might once modify the code to make it PEP8 / PyLint compliant
● Else ( PyQT => Class derivation ) .. accept the code as it is
● Yet another project for the GUI designer: Modify the code generator... :-)
5 PEP8 Compliance
14. 2015-03-28 - 2015-03-29 BDD Hands-on with Python 14
cd /<dev_root>
setup sdist
REM "<dev_root>/dist/codebreaker-1.0.zip" is created
cd dist
unzip codebreaker-1.0.zip
setup install
REM The directory "<dev_root>/build" is created
cd /<dev_root>
setup.py bdist_wininst
REM "<dev_root>/dist/codebreaker-1.0.win32.exe" is created
6.2.1 Installation by setup.py
15. 2015-03-28 - 2015-03-29 BDD Hands-on with Python 15
setup install
c:Python27Lib
c:Python27Libside-packages
c:Python27Scripts
6.2.2 Installation by setup.py
16. 2015-03-28 - 2015-03-29 BDD Hands-on with Python 16
virtualenv c:UsersPublicpython
setup.py install –prefix="c:UsersPublicpython"
c:UsersPublicpythonLibsite-packages
c:UsersPublicpythonLibsite-packagescodebreaker_package
c:UsersPublicpythonLibsite-packagesScripts
c:UsersPublicpythonScript
set_pythonhome.bat
set path=%path%;c:userspublicpythonScripts
set pythonhome=c:userspublicpython
set_pythonpath.bat
set path=%path%;c:userspublicpythonScripts
set pythonpath=c:userspublicpythonScripts;c:userspublicpythonLib;c:userspublicpythonLibsite-
packages
6.2.3 Installation by setup.py
17. 2015-03-28 - 2015-03-29 BDD Hands-on with Python 17
REM Test
cd userspublic
codebreaker
codebreaker -i page
REM Correction
cd c:Python27Scripts
ren pygubu.pyw pygubu-script.py
copy con pygubu.bat
Pygubu-script.py
^z
6.3 Test & Correction
18. 2015-03-28 - 2015-03-29 BDD Hands-on with Python 18
C:Users>codebreaker.bat
C:Users>codebreaker-script.py
Running Python sys.version_info(major=2, minor=7, micro=6, releaselevel='final',
serial=0) on 'win32'
Traceback (most recent call last):
File "C:Python27Scriptscodebreaker-script.py", line 31, in <module>
import codebreaker
File "C:Python27libsite-packagescodebreaker.py", line 31, in <module>
from codebreaker_package.cb import main as cb_main
File "C:Python27libsite-packagescodebreaker_packagecb.py", line 36, in <m
odule>
from pygubu_codebreaker import main as pygubu_main
File "C:Python27libsite-packagescodebreaker_packagepygubu_codebreaker.py"
, line 33, in <module>
import pygubu
File "C:Python27Scriptspygubu.pyw", line 43, in <module>
print("Pygubu: v. %s" % (pygubu.__version__,))
AttributeError: 'module' object has no attribute '__version__'
6.4 Pygubu Module - Problem
File
"C:Python27Scriptspy
gubu.pyw", line 43, in
<module>
19. 2015-03-28 - 2015-03-29 BDD Hands-on with Python 19
.gitignore
.pypirc
*.zip
*.exe
*.rpm
build
bin
dist
6.5 Publication on GitHub
20. 2015-03-28 - 2015-03-29 BDD Hands-on with Python 20
7 Project Feedback
● If BDD is intended to describe business logic, what to do with UI messages?
● BDD does not help to describe business algorithms ( in opposite to UML,
BPMN )
● Tricky "Scenarios: matches with duplicates"
● TDD & Unittests => helpful
● I felt helpless with BDD
● Behave produces much output garbage
● Integration with IDEs, with information filtering would be helpful
● Setup implementation
● revealed errorous naming of script file of a dependant module ( Pygubu )
● Distutils doesnt' handle requirements ( requires=["required_module"] ) as
promised
21. 2015-03-28 - 2015-03-29 BDD Hands-on with Python 21
8 Roadmap
● Webserver-based versions ( Bottle, CherryPy, Django, Genshi, Gunicorn,
Plone/Zope, Pocco "Flask", Pylons Project "Pyramid", Python Paste,
Tornado )
● Further GUI-based versions ( Kivy, wxPython, PyGTK.. ),
● Online-service based versions ( Heroku, PythonAnywhere,..)
● Module for the ERP systems Tryton / OpenERP
● Implementation for other installers ( i.e. Setuptools / Easy Install )
22. 2015-03-28 - 2015-03-29 BDD Hands-on with Python 22
9 Resources
● Book
● David Chelimsky, Dave Astels, Bryan Helmkamp, Dan North, Zach
Dennis, Aslak Hellesoy: "The RSpec Book: Behaviour Driven
Development with RSpec, Cucumber, and Friends", ISBN 1934356379
● Rolf Hemmerling's webpage, also about BDD
http://www.hemmerling.com/doku.php/en/specbyex.html
● Rolf Hemmerling's webpage, also about GUI designers
http://www.hemmerling.com/doku.php/en/python.html
● Rolf Hemmerling's Slides http://www.slideshare.net/hemmerling/