Skip to content

Instantly share code, notes, and snippets.

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.
@javouhey
javouhey / gist:8700104
Created January 30, 2014 00:20
GET https://www.dropbox.com/ (http headers only)
$ curl -i -XGET https://www.dropbox.com/
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 30 Jan 2014 00:16:51 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
set-cookie: locale=en; expires=Tue, 29 Jan 2019 00:16:51 GMT; Path=/
set-cookie: gvc=MjA..; expires=Tue, 29 Jan 2019 00:16:51 GMT; Path=/; httponly
$ curl -i -XGET https://www.dropbox.com/static/images/logo.png
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 30 Jan 2014 00:21:48 GMT
Content-Type: image/png
Content-Length: 4994
Last-Modified: Fri, 12 Oct 2012 02:29:21 GMT
Connection: keep-alive
ETag: "50778081-1382"
@javouhey
javouhey / gist:8995441
Created February 14, 2014 03:48
golang skeleton code for www.codeeval.com
package main
import (
"bufio"
"fmt"
"io"
"log"
"os"
"strings"
)
#!/bin/bash
# bash generate random alphanumeric string
#
# bash generate random 32 character alphanumeric string (upper and lowercase) and
NEW_UUID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
# bash generate random 32 character alphanumeric string (lowercase only)
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1
@javouhey
javouhey / gist:9013310
Created February 15, 2014 01:49
Notes on gradle
@javouhey
javouhey / gist:9080510
Created February 18, 2014 21:29
supervisord sending SIGINT
# code
#!/usr/bin/env python
import signal
import sys
def signal_handler(signal, frame):
print 'You pressed Ctrl+C!'
sys.exit(0)
This is the list of exit codes for wget:
0 No problems occurred
1 Generic error code
2 Parse error — for instance, when parsing command-line options, the .wgetrc or .netrc…
3 File I/O error
4 Network failure
5 SSL verification failure
6 Username/password authentication failure
7 Protocol errors
module CallPrice
function callprice(S0, K, r, T, sigma, paths)
Csum = 0.0
for j = 1:paths
Zs = randn()
Zj = T*(r-sigma.^2/2) + Zs*T.^0.5*sigma
STj = exp(Zj)*S0
Csum += exp(-r*T)*max(STj - K,0.0)
end
return Csum/paths
@javouhey
javouhey / gist:9162475
Created February 22, 2014 21:09
Forcing a type check
package main
import (
"fmt"
)
type Boo interface{ Write(int32) int32 }
type Babi struct {}