Conflicts:
	AUTHORS
This commit is contained in:
Kenneth Reitz
2011-12-22 18:13:23 -05:00
2 changed files with 178 additions and 19 deletions
+66
View File
@@ -9,18 +9,67 @@ Context
WSGI
----
The Web Server Gateway Interface (or "WSGI" for short) is a standard
interface between web servers and Python web application frameworks. By
standardizing behavior and communication between web servers and Python web
frameworks, WSGI makes it possible to write portable Python web code that
can be deployed in any `WSGI-compliant web server <#servers>`_. WSGI is
documented in `PEP-3333 <http://www.python.org/dev/peps/pep-3333/>`_.
Frameworks
::::::::::
Broadly speaking, a web framework is a set of libraries upon which you can
build custom code to implement a web application (i.e. an interactive web
site). Most web frameworks include patterns and utilities to accomplish at
least the following:
URL Routing
Matches an incoming HTTP request to a particular piece of Python code to
be invoked
Request and Response Objects
Encapsulate the information received from or sent to a user's browser
Template Engine
Allows for separating Python code implementing an application's logic from
the HTML (or other) output that it produces
Development Web Server
Runs an HTTP server on development machines to enable rapid development;
often automatically reloads server-side code when files are updated
Django
------
`Django <http://www.djangoproject.com>`_ is a "batteries included" web
application framework. By providing many utilities and patterns out of the
box, Django aims to make it possible to build complex, database-backed web
applications quickly, while encouraging best practices in code written using
it.
Django has a large and active community, and many pre-built `re-usable
modules <http://djangopackages.com/>`_ that can be incorporated into a new
project as-is, or customized to fit your needs.
There are annual Django conferences `in the United States
<http://djangocon.us>`_ and `in Europe <http://djangocon.eu>`_.
Flask
-----
`Flask <http://flask.pocoo.org/>`_ is a "microframework" for Python. Rather
than aiming to provide everything you could possibly need, Flask implements
the most commonly-used core components of a web application framework, like
URL routing, request and response objects, and templates. As a user of
Flask, it is therefore up to you to choose and integrate other components
you may need, such as database access or form generation and validation. For
many popular modules, `Extensions <http://flask.pocoo.org/extensions/>`_ may
already exist to suit your needs.
Pyramid
-------
@@ -39,6 +88,9 @@ Apache + mod_python
Nginx + gunicorn
----------------
Mongrel2 + Brubeck
------------------
Mongrel2 + wsgid
----------------
@@ -58,10 +110,24 @@ There is also a tutorial about deploying Django using this stack: http://daltonm
Hosting
:::::::
Heroku
------
DotCloud
--------
gondor.io
---------
ep.io
-----
Gondor
------
Heroku
------
WebFaction
-----------
+112 -19
View File
@@ -11,55 +11,148 @@ The Basics
Unittest
--------
Unittest is the batteries-included test module in the Python standard library.
Its API will be familiar to anyone who has used any of the JUnit/nUnit/CppUnit
series of tools.
Creating testcases is accomplished by subclassing a TestCase base class
::
import unittest
def fun(x):
return x + 1
class MyTest(unittest.TestCase):
def test(self):
self.assertEqual(fun(3), 4)
As of Python 2.7 unittest also includes its own test discovery mechanisms.
`unittest in the standard library documentation <http://docs.python.org/library/unittest.html>`_
Doc Strings
-----------
Doctest
-------
The doctest module searches for pieces of text that look like interactive Python
sessions, and then executes those sessions to verify that they work exactly as
shown.
Tools
:::::
Doctest
-------
py.test
-------
py.test is a no-boilerplate alternative to Python's standard unittest module.
::
$ pip install pytest
Despite being a fully-featured and extensible test tool it boasts a simple
syntax. Creating a test suite is as easy as writing a module with a couple of
functions
::
# content of test_sample.py
def func(x):
return x + 1
def test_answer():
assert func(3) == 5
and then running the `py.test` command
::
$ py.test
=========================== test session starts ============================
platform darwin -- Python 2.7.1 -- pytest-2.2.1
collecting ... collected 1 items
test_sample.py F
================================= FAILURES =================================
_______________________________ test_answer ________________________________
def test_answer():
> assert func(3) == 5
E assert 4 == 5
E + where 4 = func(3)
test_sample.py:5: AssertionError
========================= 1 failed in 0.02 seconds =========================
far less work than would be required for the equivalent functionality with the
unittest module!
`py.test <http://pytest.org/latest/>`_
Nose
----
::
$ pip install tox
Unittest2
---------
A backport of Python 2.7's
nose extends unittest to make testing easier.
::
$ pip install tox
$ pip install nose
nose provides automatic test discovery to save you the hassle of manually
creating test suites. It also provides numerous plugins for features such as
xUnit-compatible test output, coverage reporting, and test selection.
`nose <http://readthedocs.org/docs/nose/en/latest/>`_
tox
---
tox is a tool for automating test environment management and testing against multiple
interpreter configurations
::
$ pip install tox
tox allows you to configure complicatated multi-parameter test matrices via a
simple ini-style configuration file.
`tox <http://tox.testrun.org/latest/>`_
Unittest2
---------
unittest2 is a a backport of Python 2.7's unittest module which has an improved
API and better assertions over the one available in previous versions of Python.
If you're using Python 2.6 or below, you can install it with pip
::
$ pip install unittest2
You may want to import the module under the name unittest to make porting code
to newer versions of the module easier in the future
::
import unittest2 as unittest
class MyTest(unittest.TestCase):
...
This way if you ever switch to a newer python version and no longer need the
unittest2 module, you can simply change the import in your test module without
the need to change any other code.
`unittest2 <http://pypi.python.org/pypi/unittest2>`_