Upload
marty-alchin
View
116
Download
0
Tags:
Embed Size (px)
DESCRIPTION
My talk from the Testing in Python BoF at PyCon 2011
Citation preview
Lab CoatTest your specimens
class Human: legs = ['left', 'right']
class Dog: legs = ['lf', 'rf', 'lr', 'rr'] tail = True fur_color = 'brown'
def bark(self): return 'Woof!'
First some species
Then some observations● Humans have two legs, dogs have four● Dogs have a tail and fur of a specific color● Dogs can bark, humans can�t (for our purposes)● Humans are actually pretty boring
class Dog: legs = ['lf', 'rf', 'lr', 'rr'] tail = True fur_color = 'brown'
def bark(self): return 'Woof!'
How to examine a dog
dog.has.tail
class Dog: legs = ['lf', 'rf', 'lr', 'rr'] tail = True fur_color = 'brown'
def bark(self): return 'Woof!'
How to examine a dog
dog.has.legs
class Dog: legs = ['lf', 'rf', 'lr', 'rr'] tail = True fur_color = 'brown'
def bark(self): return 'Woof!'
How to examine a dog
dog.has(4).legs
class Dog: legs = ['lf', 'rf', 'lr', 'rr'] tail = True fur_color = 'brown'
def bark(self): return 'Woof!'
dog.can.bark()
How to examine a dog
class Dog: legs = ['lf', 'rf', 'lr', 'rr'] tail = True fur_color = 'brown'
def bark(self): return 'Woof!'
dog.s.fur_color == 'brown'
How to examine a dog
class Human: legs = ['left', 'right']
How to examine a human
human.has.legs
class Human: legs = ['left', 'right']
How to examine a human
human.lacks.tail
class Human: legs = ['left', 'right']
How to examine a human
human.lacks(4).legs
class Human: legs = ['left', 'right']
How to examine a human
human.can_not.bark()(for today�s purposes)
class Furniture: legs = ['a', 'b', 'c', 'd']
class Dog: def hump(self, obj): ...
How to examine interaction
dog.can.hump(furniture)
class Furniture: legs = ['a', 'b', 'c', 'd']
class Dog: def hump(self, obj): ...
How to examine interaction
dog.can.hump(human)
class BadDog(Exception): pass
class Dog: def hump(self, obj): if isinstance(obj, Human): raise BadDog('Down boy!')
How to examine interaction
dog.can_not.hump(human)
class BadDog(Exception): pass
class Dog: def hump(self, obj): if isinstance(obj, Human): raise BadDog('Down boy!')
How to examine interaction
dog.can_not.hump(human) \.because(BadDog)
from labcoat import Specimen
with Specimen(Dog) as rover: rover.has.tail rover.has(4).legs rover.can.bark()
with Specimen(Furniture) as couch: rover.can.hump(couch)
with Specimen(Human) as owner: rover.can_not.hump(owner).because(BadDog)
Obtaining specimens
black_lab = Specimen(Dog)black_lab.fur_color = 'black'
with black_lab as rover: rover.s.fur_color != 'brown' rover.s.fur_color == 'black'
# Dye the dog's fur brown rover.s.fur_color = 'brown'
with black_lab as rover: rover.s.fur_color == 'black'
Specimen initialization
specimen.s.attribute <|<=|==|!=|>|>= 'value'
specimen.has.attributespecimen.has(num).attributesspecimen.has(num).or_more.attributesspecimen.has(num).or_less.attributes
specimen.lacks.attributespecimen.lacks(num).attributesspecimen.lacks(num).or_more.attributesspecimen.lacks(num).or_less.attributes
Attribute tests
specimen.please.act()
specimen.can.act()specimen.can_not.act()
specimen.can_not.act().because(Exception)
Method tests
https://github.com/gulopine/labcoat
https://github.com/gulopine/labcoat
A week oldNo docs
No setup.py
https://github.com/gulopine/labcoat
A week oldNo docs
No setup.pyNo tests