Skip to content

Instantly share code, notes, and snippets.

@hjwp
hjwp / readme.md
Created March 12, 2014 10:39
Minimal repro of LiveServerTestCase / Selenium / Windows bug

This Gist is just a minimal repro of a bug (I think) in Django's LiveServerTestCase.

Once a site has some static files (eg CSS), then clicking on a link produces an ugly uncaught exception from the LiveServer thread, like this:

Exception happened during processing of request from ('127.0.0.1', 1925)
Traceback (most recent call last):
  File "c:\Python33\lib\site-packages\django\test\testcases.py", line 1035, in _handle_request_noblock
    self.process_request(request, client_address)
  File "c:\Python33\lib\socketserver.py", line 332, in process_request
@hjwp
hjwp / tdd-webdev-draft-v1.1.diff
Created April 22, 2014 08:44
updates for python 3.4 and rewrite chap. 19
diff --git a/chapter_01.asciidoc b/chapter_01.asciidoc
index bee486f..f46cd90 100644
--- a/chapter_01.asciidoc
+++ b/chapter_01.asciidoc
@@ -265,25 +265,24 @@ Next we can add the rest of the contents of the current folder, `.`:
----
$ *git add .*
$ *git status*
-# On branch master
-#
@hjwp
hjwp / gist:455a77e21a3710c1b958
Last active August 29, 2015 14:01
"Easily" run all the tests in a particular file in Django <1.6
grep "class.\+Test" appname/tests/test_file.py | awk '{print $2;}' | awk -F"(" '{print "appname."$1}' | xargs python manage.py test
@hjwp
hjwp / family.py
Created August 13, 2014 18:22
example of testing super calls
x = None
class Parent:
def foo(self):
return 'parent'
class Child(Parent):
def foo(self):
if x:
return x
@hjwp
hjwp / deccy.py
Created October 23, 2014 09:26
Simple decorator challeng
def absolute(fn):
# this decorator currently does nothing
def modified_fn(x):
return fn(x)
return modified_fn
def foo(x):
return 1 - x
get_ipython().system(u'sqlite3 my.db')
@hjwp
hjwp / load_env_from_bash_script.py
Last active August 29, 2015 14:21
Load environment variables from bash into current python process
import os
import subprocess
script = '/home/harry/.virtualenvs/my-project-name/bin/postactivate' # eg
env_to_json = 'import os, json; print(json.dumps(dict(os.environ)))'
environ_json = subprocess.check_output(
'. {} && python -c "{}"'.format(script, env_to_json),
shell=True, env={}
)
os.environ.update(json.loads(environ_json.decode('utf8')))
@hjwp
hjwp / test_chromedrive_autocapitalize_off.py
Created May 26, 2015 12:27
Minimal repro of chromedriver bug
import tempfile
from selenium import webdriver
htmlfile = tempfile.NamedTemporaryFile(suffix='.html', delete=False)
with htmlfile.file:
htmlfile.file.write('<!DOCTYPE html><html><input type="text" autocapitalize="off" /></html>')
def check_browser(browser):
browser.implicitly_wait(1)
@hjwp
hjwp / conftest.py
Last active August 29, 2015 14:23
pytest finalizer that prints?
import pytest
@pytest.yield_fixture
def print_on_fail():
yield
print('test failed')
@hjwp
hjwp / conftest.py
Last active August 29, 2015 14:23
pytest print in finalizer attempts
import time
import pytest
def pytest_runtest_call(item):
if hasattr(item, "_request"):
if hasattr(item._request, "_addoutput_on_failure"):
item._request._addoutput_on_failure()
@pytest.fixture