Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View pfctdayelise's full-sized avatar

Brianna Laugher pfctdayelise

View GitHub Profile
@pfctdayelise
pfctdayelise / 00-intro_errorreporting.txt
Created August 18, 2012 13:47
Examples of pytest, especially funcargs
These are snippets of py.test in action, used in a talk given at
PyCon AU 2012 in Hobart, Tasmania. They are all relevant for
py.test 2.2 except where specified. Where taken from open source
projects I have listed a URL, some examples are from the py.test
documentation, some are from my workplace.
Apart from things called test_*, these functions should probably
be in your conftest.py, although they can generally start life in
your test files.
@pfctdayelise
pfctdayelise / conftest.py
Last active October 26, 2018 15:48
py.test - idparametrize mark, to easily parametrize tests with test ids/test names
def pytest_generate_tests(metafunc):
"""
If the test_ fn has a idparametrize mark, use it to create parametrized
tests with ids. Instead of giving a list of argvals (test values), it
should be a dict of test id strings -> tuple of test values
e.g.
@py.test.mark.idparametrize(('a', 'b'), {
'foo': (1, 2),
'bar': (3, 4),
})
% Generate/verify memes in Prolog.
noun(apple).
noun(banana).
noun(orange).
noun(kiwifruit).
irregular_noun(kiwifruit, kiwifruit).
@pfctdayelise
pfctdayelise / 2.3.5_before.py
Last active December 25, 2015 14:29
py.test examples
import pytest
@pytest.mark.parametrize("input", "expected", [
("3+5", 8),
("2+4", 6),
])
def test_evalPassing(input, expected):
assert eval(input) == expected
@pfctdayelise
pfctdayelise / trickysorting.ipynb
Last active December 23, 2015 21:29
An IPython Notebook walk-through of how to make an interesting key function for comparing (sort/min/max) in Python. View it at the notebook viewer: http://nbviewer.ipython.org/6696813 Corrections welcome
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pfctdayelise
pfctdayelise / embeddinghtml.ipynb
Last active December 19, 2015 08:29
Iframes appear to break the nbviewer, although they work fine in the ipython notebook itself.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
"""Public domain, yo.
See http://brianna.laugher.id.au/blog/79/the-progressive-speaking-stack-in-python for background.
"""
class Speaker:
def __init__(self, name):
self.name = name
self._hasSpoken = False
def __eq__(self, other):
I/dalvikvm( 1836): Failed resolving Lorg/thoughtcrime/securesms/ConversationListFragment$1; interface 573 'Landroid/widget/SearchView$OnQueryTextListener;'
W/dalvikvm( 1836): Link of class 'Lorg/thoughtcrime/securesms/ConversationListFragment$1;' failed
E/dalvikvm( 1836): Could not find class 'org.thoughtcrime.securesms.ConversationListFragment$1', referenced from method org.thoughtcrime.securesms.ConversationListFragment.initializeSearch
W/dalvikvm( 1836): VFY: unable to resolve new-instance 1205 (Lorg/thoughtcrime/securesms/ConversationListFragment$1;) in Lorg/thoughtcrime/securesms/ConversationListFragment;
D/dalvikvm( 1836): VFY: replacing opcode 0x22 at 0x0000
D/dalvikvm( 1836): VFY: dead code 0x0002-0008 in Lorg/thoughtcrime/securesms/ConversationListFragment;.initializeSearch (Landroid/widget/SearchView;)V
E/dalvikvm( 1836): Could not find class 'android.widget.SearchView', referenced from method org.thoughtcrime.securesms.ConversationListFragment.onPrepareOptionsMenu
W/dalvikvm( 1836): VFY: unable to
@pfctdayelise
pfctdayelise / mockingwithdecorators.py
Created July 5, 2012 00:58
Mocking functions with decorators
class Foo(object):
def __init__(self, a, b):
self._a = a
self._b = b
@property
def a(self):
return self._a
@pfctdayelise
pfctdayelise / gist:2657480
Created May 11, 2012 04:10
lxml.html.clean Bug?
>>> from lxml.html.clean import clean_html
>>> clean_html("This is my abstract. I propose a set of lightning talks ( < 5 minutes).")
'<p>This is my abstract. I propose a set of lightning talks ( </p>'