Skip to content

Instantly share code, notes, and snippets.

Brianna Laugher pfctdayelise

Block or report user

Report or block pfctdayelise

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View customtestids.py
import pytest
def params(n):
fn = range(n)
return {'name': 'a', 'args': fn, 'ids': ['a: {}'.format(i) for i in fn]}
named_args = params(3)
@pytest.mark.parametrize(
named_args['name'], named_args['args'], ids=named_args['ids'])
@pfctdayelise
pfctdayelise / issue4806.py
Created Feb 19, 2014
Demonstration and workaround of Python bug 4806
View issue4806.py
# written in python2.7
def bad(n):
if n == 1:
raise ValueError('n is 1!')
if n == 2:
raise TypeError('n is 2!')
return n, 2*n
View memes.pl
% Generate/verify memes in Prolog.
noun(apple).
noun(banana).
noun(orange).
noun(kiwifruit).
irregular_noun(kiwifruit, kiwifruit).
View 2.3.5_before.py
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 Dec 23, 2015
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
View trickysorting.ipynb
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 Dec 19, 2015
Iframes appear to break the nbviewer, although they work fine in the ipython notebook itself.
View embeddinghtml.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pfctdayelise
pfctdayelise / conftest.py
Last active Oct 26, 2018
py.test - idparametrize mark, to easily parametrize tests with test ids/test names
View conftest.py
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),
})
View progressive.py
"""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):
View adb logcat output
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 / 00-intro_errorreporting.txt
Created Aug 18, 2012
Examples of pytest, especially funcargs
View 00-intro_errorreporting.txt
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.
You can’t perform that action at this time.