Skip to content

Instantly share code, notes, and snippets.

View jmatthias's full-sized avatar

Josh Matthias jmatthias

  • Lacoda
  • Philadelphia
View GitHub Profile
@jmatthias
jmatthias / dictionary_mock.py
Created May 22, 2014 20:19
A `MagicMock` which maps dictionary methods to a sample dictionary.
def DictionaryMock(_sample_dict, methods=None):
""" A mock dictionary.
Makes it easier to check that the correct values are being retrieved
from a dictionary.
'_sample_dict': A dictionary of test values. Dictionary lookups will get
values from this dictionary. """
if methods is None:
methods = [
@jmatthias
jmatthias / uuid_column.py
Created February 27, 2014 23:48
Database-agnostic SQLAlchemy UUID column type
import psycopg2.extras
import sqlalchemy.dialects.postgresql
from sqlalchemy.types import TypeEngine
from sqlalchemy.types import String
from sqlalchemy.types import TypeDecorator
import uuid
# Required for PostgreSQL to accept UUID type.
psycopg2.extras.register_uuid()