Skip to content

Instantly share code, notes, and snippets.

@Lothiraldan
Lothiraldan / test_third.py
Created October 10, 2011 21:29
Example with unittest templates.
import unittest
from poc import TemplateTestCase, Call, template
def support_http_method(method):
if method in ('POST', 'GET'):
return True
else:
return False
class SupportHttpMethodTestCase(unittest.TestCase):
@Lothiraldan
Lothiraldan / test_third_broken.py
Created October 10, 2011 21:32
Example with unittest templates and a typo in the function.
import unittest
from poc import TemplateTestCase, Call, template
def support_http_method(method):
if method in ('POST', 'GETT'):
return True
else:
return False
class SupportHttpMethodTestCase(unittest.TestCase):
@Lothiraldan
Lothiraldan / problem_loop_inside_test_method.py
Created October 27, 2011 18:04
Problem with for loop in test method
import unittest
class ListApiSet(object):
def __init__(self):
self.container = set()
def extend(self, value):
self.container.update(value)
return self.container
@Lothiraldan
Lothiraldan / gist:1348368
Created November 8, 2011 16:59
Setattr and properties
def __setattr__(self, index, value):
# Hack for properties setter
if hasattr(getattr(self.__class__, index, None), '__get__'):
return object.__setattr__(self, index, value)
@Lothiraldan
Lothiraldan / gist:1719522
Created February 1, 2012 21:16
ZMQStreams util function
# Come from excellent http://stefan.sofa-rockers.org/2012/02/01/designing-and-testing-pyzmq-applications-part-1/
def stream(context, loop, sock_type, addr, bind, callback=None, subscribe=b'',
random=False):
"""
Creates a :class:`~zmq.eventloop.zmqstream.ZMQStream`.
:param sock_type: The ØMQ socket type (e.g. ``zmq.REQ``)
:param addr: Address to bind or connect to formatted as *host:port*,
*(host, port)* or *host* (bind to random port).
If *bind* is ``True``, *host* may be:
@Lothiraldan
Lothiraldan / gist:1762265
Created February 7, 2012 21:42
Stdout bug with nosetests
import nose.core
import unittest
runner = nose.core.TextTestRunner()
# runner = unittest.TextTestRunner() # Does not work either
programm = nose.core.TestProgram(defaultTest='.', testRunner=runner,
argv=['nosetests'], exit=False)
# programm = nose.core.TestProgram(defaultTest='.', # This works
# argv=['nosetests'], exit=False)
print "Hello World !"
@Lothiraldan
Lothiraldan / gist:2867535
Created June 4, 2012 09:50
Super property/attribute access
class A(object):
class_attribute = 1
def __init__(self):
self.instance_attribute = 2
class B(A):
def test1(self):
print super(B, self).class_attribute
def test2(self):
@Lothiraldan
Lothiraldan / multicast.java
Created October 22, 2012 17:39
UDP Multicast Socket
InetAddress group = InetAddress.getByName("228.5.6.7");
MulticastSocket s = new MulticastSocket(6789);
s.joinGroup(group);
@Lothiraldan
Lothiraldan / udp_listener.py
Created October 25, 2012 10:06
Multiple UDP listener on the same port
import socket
# Socket part
ANY = "0.0.0.0"
MCAST_ADDR = "237.252.249.227"
MCAST_PORT = 1600
#create a UDP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
#allow multiple sockets to use the same PORT number
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<meta name="description" content="">