Skip to content

Commit 038f13d

Browse files
author
Kenneth Reitz
committed
Conflicts: AUTHORS
2 parents f287b26 + a24c606 commit 038f13d

File tree

2 files changed

+169
-10
lines changed

2 files changed

+169
-10
lines changed

docs/scenarios/web.rst

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,67 @@ Context
99
WSGI
1010
----
1111

12+
The Web Server Gateway Interface (or "WSGI" for short) is a standard
13+
interface between web servers and Python web application frameworks. By
14+
standardizing behavior and communication between web servers and Python web
15+
frameworks, WSGI makes it possible to write portable Python web code that
16+
can be deployed in any `WSGI-compliant web server <#servers>`_. WSGI is
17+
documented in `PEP-3333 <http://www.python.org/dev/peps/pep-3333/>`_.
18+
1219

1320
Frameworks
1421
::::::::::
1522

23+
Broadly speaking, a web framework is a set of libraries upon which you can
24+
build custom code to implement a web application (i.e. an interactive web
25+
site). Most web frameworks include patterns and utilities to accomplish at
26+
least the following:
27+
28+
URL Routing
29+
Matches an incoming HTTP request to a particular piece of Python code to
30+
be invoked
31+
32+
Request and Response Objects
33+
Encapsulate the information received from or sent to a user's browser
34+
35+
Template Engine
36+
Allows for separating Python code implementing an application's logic from
37+
the HTML (or other) output that it produces
38+
39+
Development Web Server
40+
Runs an HTTP server on development machines to enable rapid development;
41+
often automatically reloads server-side code when files are updated
42+
1643

1744
Django
1845
------
1946

47+
`Django <http://www.djangoproject.com>`_ is a "batteries included" web
48+
application framework. By providing many utilities and patterns out of the
49+
box, Django aims to make it possible to build complex, database-backed web
50+
applications quickly, while encouraging best practices in code written using
51+
it.
52+
53+
Django has a large and active community, and many pre-built `re-usable
54+
modules <http://djangopackages.com/>`_ that can be incorporated into a new
55+
project as-is, or customized to fit your needs.
56+
57+
There are annual Django conferences `in the United States
58+
<http://djangocon.us>`_ and `in Europe <http://djangocon.eu>`_.
59+
2060

2161
Flask
2262
-----
2363

64+
`Flask <http://flask.pocoo.org/>`_ is a "microframework" for Python. Rather
65+
than aiming to provide everything you could possibly need, Flask implements
66+
the most commonly-used core components of a web application framework, like
67+
URL routing, request and response objects, and templates. As a user of
68+
Flask, it is therefore up to you to choose and integrate other components
69+
you may need, such as database access or form generation and validation. For
70+
many popular modules, `Extensions <http://flask.pocoo.org/extensions/>`_ may
71+
already exist to suit your needs.
72+
2473

2574
Pyramid
2675
-------
@@ -39,6 +88,9 @@ Apache + mod_python
3988
Nginx + gunicorn
4089
----------------
4190

91+
Mongrel2 + Brubeck
92+
------------------
93+
4294

4395
Mongrel2 + wsgid
4496
----------------
@@ -58,10 +110,24 @@ There is also a tutorial about deploying Django using this stack: http://daltonm
58110
Hosting
59111
:::::::
60112

113+
Heroku
114+
------
115+
116+
DotCloud
117+
--------
118+
119+
gondor.io
120+
---------
61121

62122
ep.io
63123
-----
64124

125+
Gondor
126+
------
127+
128+
Heroku
129+
------
130+
65131
WebFaction
66132
-----------
67133

docs/writing/tests.rst

Lines changed: 103 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,55 +11,148 @@ The Basics
1111
Unittest
1212
--------
1313

14+
Unittest is the batteries-included test module in the Python standard library.
15+
Its API will be familiar to anyone who has used any of the JUnit/nUnit/CppUnit
16+
series of tools.
1417

18+
Creating testcases is accomplished by subclassing a TestCase base class
1519

16-
Doc Strings
17-
-----------
20+
::
1821

22+
import unittest
1923

24+
def fun(x):
25+
return x + 1
2026

27+
class MyTest(unittest.TestCase):
28+
def test(self):
29+
self.assertEqual(fun(3), 4)
2130

22-
Tools
23-
:::::
31+
As of Python 2.7 unittest also includes its own test discovery mechanisms.
32+
33+
`unittest in the standard library documentation <http://docs.python.org/library/unittest.html>`_
2434

2535

2636
Doctest
2737
-------
2838

39+
The doctest module searches for pieces of text that look like interactive Python
40+
sessions, and then executes those sessions to verify that they work exactly as
41+
shown.
42+
43+
44+
Tools
45+
:::::
46+
2947

3048
py.test
3149
-------
3250

51+
py.test is a no-boilerplate alternative to Python's standard unittest module.
52+
3353
::
3454

3555
$ pip install pytest
3656

57+
Despite being a fully-featured and extensible test tool it boasts a simple
58+
syntax. Creating a test suite is as easy as writing a module with a couple of
59+
functions
60+
61+
::
62+
63+
# content of test_sample.py
64+
def func(x):
65+
return x + 1
66+
67+
def test_answer():
68+
assert func(3) == 5
69+
70+
and then running the `py.test` command
71+
72+
::
73+
74+
$ py.test
75+
=========================== test session starts ============================
76+
platform darwin -- Python 2.7.1 -- pytest-2.2.1
77+
collecting ... collected 1 items
78+
79+
test_sample.py F
80+
81+
================================= FAILURES =================================
82+
_______________________________ test_answer ________________________________
83+
84+
def test_answer():
85+
> assert func(3) == 5
86+
E assert 4 == 5
87+
E + where 4 = func(3)
88+
89+
test_sample.py:5: AssertionError
90+
========================= 1 failed in 0.02 seconds =========================
91+
92+
far less work than would be required for the equivalent functionality with the
93+
unittest module!
94+
95+
`py.test <http://pytest.org/latest/>`_
96+
3797

3898
Nose
3999
----
40100

101+
nose extends unittest to make testing easier.
102+
103+
104+
::
105+
106+
$ pip install nose
107+
108+
nose provides automatic test discovery to save you the hassle of manually
109+
creating test suites. It also provides numerous plugins for features such as
110+
xUnit-compatible test output, coverage reporting, and test selection.
111+
112+
`nose <http://readthedocs.org/docs/nose/en/latest/>`_
113+
114+
115+
tox
116+
---
117+
118+
tox is a tool for automating test environment management and testing against multiple
119+
interpreter configurations
41120

42121
::
43122

44123
$ pip install tox
45124

125+
tox allows you to configure complicatated multi-parameter test matrices via a
126+
simple ini-style configuration file.
46127

128+
`tox <http://tox.testrun.org/latest/>`_
47129

48130
Unittest2
49131
---------
50132

51-
A backport of Python 2.7's
133+
unittest2 is a a backport of Python 2.7's unittest module which has an improved
134+
API and better assertions over the one available in previous versions of Python.
52135

136+
If you're using Python 2.6 or below, you can install it with pip
53137

54138
::
55139

56-
$ pip install tox
140+
$ pip install unittest2
57141

142+
You may want to import the module under the name unittest to make porting code
143+
to newer versions of the module easier in the future
58144

59-
tox
60-
---
145+
::
61146

147+
import unittest2 as unittest
148+
149+
class MyTest(unittest.TestCase):
150+
...
151+
152+
This way if you ever switch to a newer python version and no longer need the
153+
unittest2 module, you can simply change the import in your test module without
154+
the need to change any other code.
155+
156+
`unittest2 <http://pypi.python.org/pypi/unittest2>`_
62157

63-
::
64158

65-
$ pip install tox

0 commit comments

Comments
 (0)