This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
"""\ | |
============== | |
pipetestserver | |
============== | |
This recipe describes how you can create / activate and kill a temporary HTTP | |
server with a WSGI app to provide unittest resources to a client software, | |
that's the target of your application. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
"""Mock datetime.datetime.now()""" | |
import contextlib | |
import datetime | |
@contextlib.contextmanager | |
def mock_datetime_now(*args, **kwargs): | |
"""Context manager for mocking out datetime.datetime.now() in unit tests. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
"""Python enumeration""" | |
import itertools | |
def enumeration(name, *auto, **named): | |
"""Pythonic enumeration type | |
>>> Colors = enumeration('Colors', 'GREEN', 'RED', 'YELLOW') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import contextlib | |
import time | |
@contextlib.contextmanager | |
def mock_time(timestamp): | |
"""A simple context manager for mocking time.time() useful for traveling | |
immediately in the future or in the past in unit tests. | |
>>> t0 = time.time() | |
>>> with mock_time(t0 + 5.0): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WSGISCRIPT_TEMPLATE = """\ | |
# -*- coding: utf-8 -*- | |
import sys | |
import os | |
sys.path[0:0] = [ | |
{0} | |
] | |
_application = None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[wsgiscript] | |
# Build the wsgi script for mod_wsgi | |
recipe = z3c.recipe.runscript | |
install-script = ${buildout:directory}/buildouthelpers.py:make_wsgi_script | |
update-script = ${:install-script} | |
# Parameters | |
egg = egg.with.wsgiapp | |
script = ${buildout:parts-directory}/wsgiscript/myapp.wsgi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from PIL import Image | |
# Prefer the r"xxx" notation when you have backslashes | |
pathe = r"C:\David\" | |
for (path, dirs, files) in os.walk(pathe): | |
print path | |
print dirs | |
print files | |
for archivo in files: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 | |
"""\ | |
A simple demo of logging configuration with YAML (Python 2.7) | |
============================================================= | |
Requires PyYAML -> "easy_install PyYAML" | |
See the recipes for configuring logging with dicts and YAML | |
- http://docs.python.org/2.7/howto/logging-cookbook.html | |
- http://stackoverflow.com/questions/10519392/python2-7-logging-configuration-with-yaml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from sqlalchemy import create_engine | |
from sqlalchemy.orm import sessionmaker, relationship | |
from sqlalchemy.ext.declarative import declarative_base | |
from sqlalchemy.ext.orderinglist import ordering_list | |
from sqlalchemy import Column, Integer, Text, ForeignKey | |
sa_engine = create_engine("sqlite:///:memory:") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
"""Tests de www.alterway.fr avec splinter""" | |
# Préambule | |
import splinter | |
HOME = 'http://www.alterway.fr' | |
browser = splinter.Browser('firefox') | |
# On va à la page d'accueil |