[CentralOH] 2013-10-28 會議 Scribbles 落書/惡文?

jep200404 at columbus.rr.com jep200404 at columbus.rr.com
Tue Oct 29 18:30:01 CET 2013


The dojos are great place for ill-formed questions.
Is there a video of Brandon's PyCon Ireland 2013 presentation?
Need to finish example of handling expected error with pytest.

Please correct errors in the following.

Professor James Reed
Windows 8
cisprofjrr at alumni.ohio.edu
Idle versus Microsoft Visual Studio
Microsoft Visual Studio is now free.
not N8NT
immutability
idempotency

projector grief
were using only center 
can use VGA output or HDMI output on Brandon's laptop, 
but not both at same time. 
http://www.unix.com/showthread.php?t=188749
Need to test with own computers.
Projector only has HDMI cable to it?
When one is using VGA output, projector shows that it futzing with HDMI 
source, so there is likely some magic VGA to HDMI converter.

Brandon Rhodes presented about structure of code
lightning version of PyCon Ireland 2013 presentation
The Clean Architecture in Python
@brandon_rhodes
need to study his notes
http://rhodesmill.org/brandon/slides/2013-10-pyconie/
http://blog.8thlight.com/uncle-bob/2011/11/22/Clean-Architecture.html
http://blog.8thlight.com/uncle-bob/2012/08/13/the-clean-architecture.html
separate I/O 
easier to test

SVG coolness
http://kartograph.org/showcase/italia/

newcomer won an ebook from Manning
both are for beginners
    Quick Python (more for adults) http://www.manning.com/ceder/
    Hello World (more for kids) http://www.manning.com/sande/

Eric Floehr thunderstorm talk (longer than a lightning talk)
https://mail.python.org/pipermail/centraloh/2013-October/001866.html
weather movies
PIL (python image library) poorly maintained, so it has been forked to pillow
https://pypi.python.org/pypi/Pillow/1.7.7
Gnome 3.8
wohali is cherokee for eagle
cStringIO -- Faster version of StringIO
http://docs.python.org/release/2.5.2/lib/module-cStringIO.html
http://docs.python.org/2/library/stringio.html
Inconsolata fixed width font
http://www.levien.com/type/myfonts/inconsolata.html
foo(*bar) expands bar to individual arguments
max(itertools.chain(redlist, greenlist, bluelist))
max(redlist + greenlist + bluelist)  # Could be slow for big sequences.
max(max(redlist), max(greenlist), max(bluelist))
os.listdir(dirpath)
fnmatch.filter

example.py
"""A simple example."""

def average(sequence):
    return sum(sequence) * 1.0 / len(sequence)

test_1.py
# 1990s style: The days of yore.
# The days of everything written as if we were writing Java.
import example
import unittest

class ExampleTests(unittest.TestCase):
    def test_single_element_sequence(self):
        a = example.average([11.0])
        self.assertEqual(a, 11.0)

    def test_two_element_sequence(self):
        a = example.average([10.0, 20.0])
        self.assertEqual(a, 15.0)

    def test_zero_element_sequence(self):
        a = example.average([])
        self.assertEqual(a, 11.0)

awkward syntax
    extra indentation
    hassle of "self" variable
    awkward self.assertWhatever(x, y) instead of intuitive x == y
    billions of assertWhatever() methods

is good for showing details about failed test

$ python -m unittest
$ python -m unittest test_1
..E (last test failed)
ERROR: test_zero_element_sequence (test_1.ExampleTests)
ZeroDivisionError: 
$ python -m zipfile ;# emergency command line zip utility
# SimpleHTTPServer is part of base install
$ python -m SimpleHTTPServer 8888 ;# ad-hoc file server (w/ subdirectories)
# good for when someone forgets USB flash drive
$ python -m SimpleHTTPServer --help
$ python develop.py test
................................................................................................................................................................................................................................................................................SSSSSSSSSSSSSSSS.....................................................................................
Michael Foord added test discovery
http://www.voidspace.org.uk/python/articles/introduction-to-unittest.shtml
$ python -m unittest discover . ;# discovers all tests (beginning with 'test_' 
in all python files in directory (and subdirectories thereof?). 
Begins with 'test_' or just 'test'?

T-shirt of '.....................................................
OK'
to show off that they are TDD programmers.
http://www.zazzle.com/ok_tee_shirt-235887995086133837

pip install pytest
# http://pytest.org/latest/
# https://pypi.python.org/pypi/pytest

test_2.py
import example

# just plain functions, no class stuff, no self stuff.
# just plain assert statements
# py.test convention: plain old functions that start 
# with "test" in their name!
# actual code indented only one level
# no ugly self argument
# code if much easier to understand
# don't have to import anything into code that is to be tested

def test_single_element_sequence(self):
    a = example.average([11.0])
    assert a == 11.0

def test_two_element_sequence(self):
    a = example.average([10.0, 20.0])
    assert a == 15.0

def test_zero_element_sequence(self):
    a = example.average([])
    assert a == 0.0

$py.text .

# What if need to test that code must crash with Error?

example.py
"""A simple example."""

def average(sequence):
    if not sequence:
        raise ValueError('inadequate seqeuence')
    return sum(sequence) * 1.0 / len(sequence)

test_1.py
# 1990s style: The days of yore.
# The days of everything written as if we were writing Java.
import example
import unittest

class ExampleTests(unittest.TestCase):
    def test_single_element_sequence(self):
        a = example.average([11.0])
        self.assertEqual(a, 11.0)

    def test_two_element_sequence(self):
        a = example.average([10.0, 20.0])
        self.assertEqual(a, 15.0)

    def test_zero_element_sequence(self):
        with self.assertRaises(ValueError):
            example.average([])
        #self.assertEqual(a, 11.0)

py.test has an exactly equivalent context manager thing, 
but Brandon did not remember the syntax
will have to RTFM
test_2.py
import example

def test_single_element_sequence(self):
    a = example.average([11.0])
    assert a == 11.0

def test_two_element_sequence(self):
    a = example.average([10.0, 20.0])
    assert a == 15.0

def test_zero_element_sequence(self):
    # forgot syntax for requiring an error
    a = example.average([])
    assert a == 0.0

# http://pytest.org/latest/assert.html#assert-with-the-assert-statement

nose compare to pytest
    similar to pytest
    does automatic test discovery
    nose has terrible terrible magic in it;
    someone (Brandon?) has been bitten by quirks, 
    spent much time figuring out and working around such.
    pytest is much simpler and straightforward
        more automation
        less magic
py.test versus pytest
doctest
    one writes tests in docstrings, tests automatically generated from that
    looks for '>>> '
    sensitive to exact match: does not handle floats well
docopt: wonderful!
    docopt.org
    https://github.com/docopt/docopt
    one writes command line help first as doc string,
    then doctest analyzes that doc string to figure out how to parse 
    command line. way cool!
    https://pypi.python.org/pypi/docopt/0.6.1
python sure library automates testing
    https://github.com/gabrielfalcao/sure
    Raymond Chandler presented about it
        cucumber envy
Dec 9? OpenCV with augmented reality by Eric Floehr

For folks logged in to meetup.com, 
click on "About us..." link near top in left column
to see mailing list info.

Bangkok Grocery & Restaurant lauded as excellent by native of SE Asia
http://www.bangkokcolumbus.com/contact.html
3277 Refugee Rd. (just east of Winchester Pike)
Name on web site does not exactly match that on building

wp:Hawthorne_Effect
wp:Novelty_effect

Need to study how to connect to and use The Forge's projector and LCD monitors 
from my computers (VGA!!!!).

Buying a Brown Cow in Friesland
http://www.1066andallthat.com/english_old/mongrel-cow.asp
https://www.youtube.com/watch?v=OeC1yAaWG34
wp:Friesland
wp:Menno Simons
wp:Bluffton_University
    Open to non-Mennonites since its founding.
    Mennonites are now minority there.
wp:Bluffton,_Ohio
    whopping fifteen foot bluffs!!!!
wp:Bluffton_University_bus_accident

new guy needs help with serial I/O (ala RS-232). 
Told him to come to dojo.



More information about the CentralOH mailing list