docs/**: Specify language for code-blocks (syntax highlighting! mmm…)

This commit is contained in:
Zearin
2014-03-28 13:26:24 -04:00
parent 471f86b3a8
commit 1e4b4a5460
11 changed files with 58 additions and 33 deletions
+6 -2
View File
@@ -100,7 +100,9 @@ code easier to understand. In Python, comments begin with a hash
.. _docstring-ref:
In Python, *docstrings* describe modules, classes, and functions: ::
In Python, *docstrings* describe modules, classes, and functions:
.. code-block:: python
def square_and_rooter(x):
"""Returns the square root of self times self."""
@@ -130,7 +132,9 @@ Docstrings versus Block comments
These aren't interchangeable. For a function or class, the leading
comment block is a programmer's note. The docstring describes the
operation of the function or class: ::
*operation* of the function or class:
.. code-block:: python
# This function slows down program execution for some reason.
def square_and_rooter(x):
+10 -5
View File
@@ -336,7 +336,9 @@ Instead, use a list comprehension:
four_lists = [[] for __ in xrange(4)]
A common idiom for creating strings is to use :py:meth:`str.join` on an empty string.::
A common idiom for creating strings is to use :py:meth:`str.join` on an empty string.
.. code-block:: python
letters = ['s', 'p', 'a', 'm']
word = ''.join(letters)
@@ -345,7 +347,9 @@ This will set the value of the variable *word* to 'spam'. This idiom can be appl
Sometimes we need to search through a collection of things. Let's look at two options: lists and dictionaries.
Take the following code for example::
Take the following code for example:
.. code-block:: python
d = {'s': [], 'p': [], 'a': [], 'm': []}
l = ['s', 'p', 'a', 'm']
@@ -365,7 +369,7 @@ Zen of Python
Also known as :pep:`20`, the guiding principles for Python's design.
::
.. code-block:: pycon
>>> import this
The Zen of Python, by Tim Peters
@@ -406,14 +410,15 @@ exists a command-line program, `pep8 <https://github.com/jcrocholl/pep8>`_,
that can check your code for conformance. Install it by running the following
command in your Terminal:
::
.. code-block:: console
$ pip install pep8
Then run it on a file or series of files to get a report of any violations.
::
.. code-block:: console
$ pep8 optparse.py
optparse.py:69:11: E401 multiple imports on one line
+7 -6
View File
@@ -81,7 +81,7 @@ series of tools.
Creating testcases is accomplished by subclassing a TestCase base class
::
.. code-block:: python
import unittest
@@ -148,7 +148,7 @@ py.test is a no-boilerplate alternative to Python's standard unittest module.
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
functions:
.. code-block:: python
@@ -251,9 +251,10 @@ the need to change any other code.
mock
----
mock is a library for testing in Python. Starting with Python 3.3, it is
available in the `standard library <http://docs.python.org/dev/library/unittest.mock`_. For older versions of
python, simply:
**``mock``** is a library for testing in Python. As of Python 3.3, it is
available in the `standard library <http://docs.python.org/dev/library/unittest.mock`_.
For older versions of Python:
.. code-block:: console
@@ -262,7 +263,7 @@ python, simply:
It allows you to replace parts of your system under test with mock objects and
make assertions about how they have been used.
For example, you can monkey patch a method
For example, you can monkey-patch a method:
.. code-block:: python