Skip to content

Instantly share code, notes, and snippets.

@diminoten
diminoten / ExamplePluginWithTest.py
Last active December 30, 2015 13:29
An example of the problem I'm having unit testing a custom nose plugin.
"""
Will need to install mock and nose for this example to work.
"""
import unittest
from mock import Mock
from nose.plugins import Plugin
from nose.plugins import PluginTester
class ExamplePlugin(Plugin):
@diminoten
diminoten / tuples.py
Created December 13, 2013 19:35
Tuples as function args
#A function with an optional argument
def foo(fee, far=None, fleeb="floob"):
print fee
if far:
print far
if fleeb:
print fleeb
#A function that accepts a tuple as its argument, and then calls another function using the accepted tuple as arguments for the called function
class Foo():
@classmethod
def _fetch(cls, data):
response = requests.get("http://example.com/my/fun/data", data=data)
return cls(response.json())
class ChildFoo(Foo):
@staticmethod
def get_latest():
#Can I refer to Foo in some way other than directly like this?
<html>
<head>
<script src='script.js'></script>
</head>
<body>
<button id="button1" onClick="doSomething(this.id)">Do something</button>
</body>
</html>
import datetime
import random
import time
def wait_for_condition(action, seconds):
endtime = datetime.datetime.now() + datetime.timedelta(seconds=seconds)
condition = False
while endtime > datetime.datetime.now() and not condition:
/usr/bin/install -c python /usr/local/bin/python2.7
if test -f libpython2.7.a; then \
if test -n "" ; then \
/usr/bin/install -c -m 555 /usr/local/bin; \
else \
/usr/bin/install -c -m 555 libpython2.7.a /usr/local/lib/libpython2.7.a; \
if test libpython2.7.a != libpython2.7.a; then \
(cd /usr/local/lib; ln -sf libpython2.7.a libpython2.7.a) \
fi \
fi; \
Compiling /usr/local/lib/python2.7/zipfile.py ...
[{WIFEXITED(s) && WEXITSTATUS(s) == 1}], 0, NULL) = 7391
--- SIGCHLD (Child exited) @ 0 (0) ---
rt_sigreturn(0xffffffff) = 7391
open("/usr/share/locale/locale.alias", O_RDONLY|O_CLOEXEC) = 4
fstat(4, {st_mode=S_IFREG|0644, st_size=2570, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fbc4e0aa000
read(4, "# Locale name alias data base.\n#"..., 4096) = 2570
read(4, "", 4096) = 0
close(4) = 0
import lxml.builder as builder
from lxml import etree
foo = builder.E.foo
bar = builder.E.bar
bing = builder.E.bing
foo_xml = foo(
bar(
bing("Some nested thing."),
daeMEaqjvPKrrfIofviClvj7svkggeoMQyzQkptsMMcDnfyBIkFtugNe5CQW6uvLMhevr3dIQWbvvflKk6HksnrQq1ffvzJqKrcrv6KQQmtiQQBQkLANuPFsfmurvTuvP6PGPkvxLku(kevMleL9I(RKAWkIdd1ILO8ysAYK4YcBwr9zinAv0Pj1RvKmBQ62sy3I8BknCkSCP8CLMoX1vPTlr13PiJxvvDEkQ1tfs7xbnFyNaMDkewcFVbXBoEZbHcckeuyNW)ompVHqKEv675aX3Z3tUQNSXreC(1yjcTavBtDZgbb0M9Aqi(3aNucf6KWg(58T6KqWPd9UdVnYppK6e0keGtSI1ebSIIw02e2xlnnkA0w2PqiDl6nnkA0w6(qWBXkSt4UrTQhVlbPDdcnSAWoHIRx0StHcbb7JKWoHIRx0StHcHM1hStO46fn7uOqq1J3LDcRoH6dc5)(V8Gofkem7W88gcDFkD8MJmeziQE(gqHGk709HDc)7W88gcr6vPNCFzdYEghZQoknIGZVgZiCtstJIgn2jSgH37Ilc6(8Hi34ifcstJIgn2jiMnccRGL7syncV3fxe095drUXrc3uuEKec4RyjC3OEpTMCirNeuVRylQp1kbbrxekeIYJKqyAR1RynLgoj)MfTf7oCIJemcV3rq4Ur9AeEVlUiOtc3nQVjTqNe2tRjhse2tRjhstBTEfRPefckXILBdlbDs4m0ONcDhhFZXXXX4xw2XGXhcElwHDcc2hjHDcfxVOzNcfcQE8USty1juFqi)3)Lh0Pq4UrTQhVlDsOHvd2juC9IMDkuiC3OEncv6KWAeQSty1juFq3kkeUBuRAlkdl0jHM1hStO46fn7uOqHWSnjG2rd6(uIGIEn8yZGGvNAjmCYBzqOfOABQB2iiOvTjcyffTOTjSVwAAu0OTStHaoPlWI2MyNWk4MWobXSrqWOfBiemAXgcb0M1efkeWxXYYiOviG8I9wcM0kYjrkxvv1Zr2twUbvziogW5xJzem7
Traceback (most recent call last):
File "/Users/diminoten/git/project/ENV/bin/pep8", line 11, in <module>
sys.exit(_main())
File "/Users/diminoten/git/project/ENV/lib/python2.7/site-packages/pep8.py", line 2107, in _main
report = pep8style.check_files()
File "/Users/diminoten/git/project/ENV/lib/python2.7/site-packages/pep8.py", line 1830, in check_files
self.input_dir(path)
File "/Users/diminoten/git/project/ENV/lib/python2.7/site-packages/pep8.py", line 1866, in input_dir
runner(os.path.join(root, filename))
File "/Users/diminoten/git/project/ENV/lib/python2.7/site-packages/pep8.py", line 1844, in input_file