Skip to content

Commit

Permalink
Merge pull request #90 from skirpichev/use-py.test-sphinx
Browse files Browse the repository at this point in the history
Use py.test to test sphinx docs
  • Loading branch information
skirpichev committed Jun 7, 2015
2 parents f71ff5c + 3c5a782 commit 9077870
Show file tree
Hide file tree
Showing 21 changed files with 66 additions and 1,826 deletions.
2 changes: 1 addition & 1 deletion bin/coverage_doctest.py
Expand Up @@ -30,7 +30,7 @@
# It's html.parser in Python 3
from html.parser import HTMLParser

# Load color templates, used from sympy/utilities/runtests.py
# Load color templates
color_templates = (
("Black", "0;30"),
("Red", "0;31"),
Expand Down
75 changes: 0 additions & 75 deletions bin/doctest

This file was deleted.

6 changes: 3 additions & 3 deletions bin/test_travis.sh
Expand Up @@ -3,7 +3,6 @@
set -e -x # exit on error and echo each command

if [[ "${TEST_SPHINX}" == "true" ]]; then
bin/doctest `find doc/ -name '*.rst'`
make -C doc html-errors man latex
LATEXOPTIONS="-interaction=nonstopmode" make -C doc/_build/latex
else
Expand All @@ -19,12 +18,13 @@ else
py.test --duration=100 --cov sympy --doctest-modules \
sympy/printing/tests/test_theanocode.py \
sympy/external/tests/test_autowrap.py \
sympy/polys/ sympy/plotting/
sympy/polys/ sympy/plotting/ doc \
--ignore doc/tutorial/gotchas.rst # XXX: workaround __future__ imports!
else
py.test --duration=100 --doctest-modules \
sympy/printing/tests/test_theanocode.py \
sympy/external/tests/test_autowrap.py \
sympy/polys/ sympy/plotting/
sympy/polys/ sympy/plotting/ doc
fi
elif [[ "${TRAVIS_PYTHON_VERSION}" == "2.7" ]]; then
py.test -m 'not slow' --duration=100 --cov sympy --split="${SPLIT}" \
Expand Down
6 changes: 6 additions & 0 deletions doc/conftest.py
@@ -0,0 +1,6 @@
import sys


if sys.version_info[0] == 2:
reload(sys)
sys.setdefaultencoding('utf-8')
5 changes: 5 additions & 0 deletions doc/guide.rst
Expand Up @@ -347,6 +347,9 @@ This is how to create a function with two variables::
.. note:: the first argument of a @classmethod should be ``cls`` (i.e. not
``self``).

>>> from sympy.interactive import init_printing
>>> init_printing(use_unicode=False)

Here it's how to define a derivative of the function::

>>> from sympy import Function, sympify, cos
Expand Down Expand Up @@ -430,6 +433,8 @@ Please use the same way as is shown below all across SymPy.

>>> from sympy import sign, sin
>>> from sympy.abc import x, y, z
>>> from sympy.interactive import init_printing
>>> init_printing(pretty_print=False)

>>> e = sign(x**2)
>>> e.args
Expand Down
8 changes: 4 additions & 4 deletions doc/modules/core.rst
Expand Up @@ -396,15 +396,15 @@ Function
the atoms method:

>>> e = (f(x) + cos(x) + 2)
>>> e.atoms(Function)
set([f(x), cos(x)])
>>> e.atoms(Function) == {f(x), cos(x)}
True

If you just want the function you defined, not SymPy functions, the
thing to search for is AppliedUndef:

>>> from sympy.core.function import AppliedUndef
>>> e.atoms(AppliedUndef)
set([f(x)])
>>> e.atoms(AppliedUndef) == {f(x)}
True

Subs
^^^^
Expand Down
4 changes: 2 additions & 2 deletions doc/modules/evalf.rst
Expand Up @@ -138,9 +138,9 @@ cancellation:

>>> a, b = GoldenRatio**1000/sqrt(5), fibonacci(1000)
>>> float(a)
4.34665576869e+208
4.3466557686937455e+208
>>> float(b)
4.34665576869e+208
4.3466557686937455e+208
>>> float(a) - float(b)
0.0

Expand Down
8 changes: 4 additions & 4 deletions doc/modules/logic.rst
Expand Up @@ -37,8 +37,8 @@ Like most types in SymPy, Boolean expressions inherit from

>>> (y & x).subs({x: True, y: True})
True
>>> (x | y).atoms()
set([x, y])
>>> (x | y).atoms() == {x, y}
True

The logic module also includes the following functions to derive boolean expressions
from their truth tables-
Expand Down Expand Up @@ -114,8 +114,8 @@ values for ``x`` that make this sentence ``True``. On the other hand, ``(x
>>> y = Symbol('y')
>>> satisfiable(x & ~x)
False
>>> satisfiable((x | y) & (x | ~y) & (~x | y))
{x: True, y: True}
>>> satisfiable((x | y) & (x | ~y) & (~x | y)) == {x: True, y: True}
True

As you see, when a sentence is satisfiable, it returns a model that makes that
sentence ``True``. If it is not satisfiable it will return ``False``.
Expand Down
4 changes: 2 additions & 2 deletions doc/modules/numeric-computation.rst
Expand Up @@ -44,7 +44,7 @@ leveraging a variety of numerical libraries. It is used as follows:
>>> expr = sin(x)/x
>>> f = lambdify(x, expr)
>>> f(3.14)
0.000507214304614
0.0005072143046136395

Here lambdify makes a function that computes ``f(x) = sin(x)/x``. By default
lambdify relies on implementations in the ``math`` standard library. This
Expand All @@ -64,7 +64,7 @@ powerful vectorized ufuncs that are backed by compiled C code.

>>> import numpy
>>> data = numpy.linspace(1, 10, 10000)
>>> f(data)
>>> pprint(f(data))
[ 0.84147098 0.84119981 0.84092844 ..., -0.05426074 -0.05433146
-0.05440211]

Expand Down
12 changes: 6 additions & 6 deletions doc/modules/printing.rst
Expand Up @@ -202,12 +202,12 @@ return value is a three-tuple containing: (i) a set of number symbols that must
be defined as 'Fortran parameters', (ii) a list functions that can not be
translated in pure Fortran and (iii) a string of Fortran code. A few examples:

>>> fcode(1 - gamma(x)**2, human=False)
(set(), set([gamma(x)]), ' -gamma(x)**2 + 1')
>>> fcode(1 - sin(x)**2, human=False)
(set(), set(), ' -sin(x)**2 + 1')
>>> fcode(x - pi**2, human=False)
(set([(pi, '3.14159265358979d0')]), set(), ' x - pi**2')
>>> fcode(1 - gamma(x)**2, human=False) == (set(), {gamma(x)}, ' -gamma(x)**2 + 1')
True
>>> fcode(1 - sin(x)**2, human=False) == (set(), set(), ' -sin(x)**2 + 1')
True
>>> fcode(x - pi**2, human=False) == ({(pi, '3.14159265358979d0')}, set(), ' x - pi**2')
True

Mathematica code printing
-------------------------
Expand Down
4 changes: 2 additions & 2 deletions doc/modules/rewriting.rst
Expand Up @@ -48,8 +48,8 @@ process by using ``collect`` function:
>>> (x + I*y).as_real_imag()
(re(x) - im(y), re(y) + im(x))

>>> collect((x + I*y).expand(complex=True), I, evaluate=False)
{1: re(x) - im(y), I: re(y) + im(x)}
>>> collect((x + I*y).expand(complex=True), I, evaluate=False) == {1: re(x) - im(y), I: re(y) + im(x)}
True

There is also possibility for expanding expressions in terms of expressions of
different kind. This is very general type of expanding and usually you would
Expand Down
47 changes: 24 additions & 23 deletions doc/modules/solvers/diophantine.rst
Expand Up @@ -84,15 +84,16 @@ First, let's import the highest API of the Diophantine module.
Before we start solving the equations, we need to define the variables.

>>> from sympy import symbols
>>> x, y, z = symbols("x, y, z", integer=True)
>>> x, y, z, t, p, q = symbols("x, y, z, t, p, q", integer=True)
>>> t1, t2, t3, t4, t5 = symbols("t1:6", integer=True)

Let's start by solving the easiest type of Diophantine equations, i.e. linear
Diophantine equations. Let's solve `2x + 3y = 5`. Note that although we
write the equation in the above form, when we input the equation to any of the
functions in Diophantine module, it needs to be in the form `eq = 0`.

>>> diophantine(2*x + 3*y - 5)
set([(3*t - 5, -2*t + 5)])
>>> diophantine(2*x + 3*y - 5) == {(3*t - 5, -2*t + 5)}
True

Note that stepping one more level below the highest API, we can solve the very
same equation by calling :py:meth:`~sympy.solvers.diophantine.diop_solve`.
Expand All @@ -115,8 +116,8 @@ which is what :py:meth:`~sympy.solvers.diophantine.diop_solve` calls internally.

If the given equation has no solutions then the outputs will look like below.

>>> diophantine(2*x + 4*y - 3)
set()
>>> diophantine(2*x + 4*y - 3) == set()
True
>>> diop_solve(2*x + 4*y - 3)
(None, None)
>>> diop_linear(2*x + 4*y - 3)
Expand All @@ -143,27 +144,27 @@ of the solutions. Let us define `\Delta = b^2 - 4ac` w.r.t. the binary quadratic

When `\Delta < 0`, there are either no solutions or only a finite number of solutions.

>>> diophantine(x**2 - 4*x*y + 8*y**2 - 3*x + 7*y - 5)
set([(2, 1), (5, 1)])
>>> diophantine(x**2 - 4*x*y + 8*y**2 - 3*x + 7*y - 5) == {(2, 1), (5, 1)}
True

In the above equation `\Delta = (-4)^2 - 4*1*8 = -16` and hence only a finite
number of solutions exist.

When `\Delta = 0` we might have either no solutions or parameterized solutions.

>>> diophantine(3*x**2 - 6*x*y + 3*y**2 - 3*x + 7*y - 5)
set()
>>> diophantine(x**2 - 4*x*y + 4*y**2 - 3*x + 7*y - 5)
set([(-2*t**2 - 7*t + 10, -t**2 - 3*t + 5)])
>>> diophantine(x**2 + 2*x*y + y**2 - 3*x - 3*y)
set([(t, -t), (t, -t + 3)])
>>> diophantine(3*x**2 - 6*x*y + 3*y**2 - 3*x + 7*y - 5) == set()
True
>>> diophantine(x**2 - 4*x*y + 4*y**2 - 3*x + 7*y - 5) == {(-2*t**2 - 7*t + 10, -t**2 - 3*t + 5)}
True
>>> diophantine(x**2 + 2*x*y + y**2 - 3*x - 3*y) == {(t, -t), (t, -t + 3)}
True

The most interesting case is when `\Delta > 0` and it is not a perfect square.
In this case, the equation has either no solutions or an infinte number of
solutions. Consider the below cases where `\Delta = 8`.

>>> diophantine(x**2 - 4*x*y + 2*y**2 - 3*x + 7*y - 5)
set()
>>> diophantine(x**2 - 4*x*y + 2*y**2 - 3*x + 7*y - 5) == set()
True
>>> from sympy import expand
>>> n = symbols("n", integer=True)
>>> s = diophantine(x**2 - 2*y**2 - 2*x - 4*y, n)
Expand Down Expand Up @@ -224,10 +225,10 @@ of the form `ax^2 + by^2 + cz^2 + dxy + eyz + fzx = 0`. These type of equations
either have infinitely many solutions or no solutions (except the obvious
solution (0, 0, 0))

>>> diophantine(3*x**2 + 4*y**2 - 5*z**2 + 4*x*y + 6*y*z + 7*z*x)
set()
>>> diophantine(3*x**2 + 4*y**2 - 5*z**2 + 4*x*y - 7*y*z + 7*z*x)
set([(-16*p**2 + 28*p*q + 20*q**2, 3*p**2 + 38*p*q - 25*q**2, 4*p**2 - 24*p*q + 68*q**2)])
>>> diophantine(3*x**2 + 4*y**2 - 5*z**2 + 4*x*y + 6*y*z + 7*z*x) == set()
True
>>> diophantine(3*x**2 + 4*y**2 - 5*z**2 + 4*x*y - 7*y*z + 7*z*x) == {(-16*p**2 + 28*p*q + 20*q**2, 3*p**2 + 38*p*q - 25*q**2, 4*p**2 - 24*p*q + 68*q**2)}
True

If you are only interested about a base solution rather than the parameterized
general solution (to be more precise, one of the general solutions), you can
Expand Down Expand Up @@ -257,17 +258,17 @@ general sum of squares equation, `x_{1}^2 + x_{2}^2 + \ldots + x_{n}^2 = k` can
also be solved using the Diophantine module.

>>> from sympy.abc import a, b, c, d, e, f
>>> diophantine(9*a**2 + 16*b**2 + c**2 + 49*d**2 + 4*e**2 - 25*f**2)
set([(70*t1**2 + 70*t2**2 + 70*t3**2 + 70*t4**2 - 70*t5**2, 105*t1*t5, 420*t2*t5, 60*t3*t5, 210*t4*t5, 42*t1**2 + 42*t2**2 + 42*t3**2 + 42*t4**2 + 42*t5**2)])
>>> diophantine(9*a**2 + 16*b**2 + c**2 + 49*d**2 + 4*e**2 - 25*f**2) == {(70*t1**2 + 70*t2**2 + 70*t3**2 + 70*t4**2 - 70*t5**2, 105*t1*t5, 420*t2*t5, 60*t3*t5, 210*t4*t5, 42*t1**2 + 42*t2**2 + 42*t3**2 + 42*t4**2 + 42*t5**2)}
True

function :py:meth:`~sympy.solvers.diophantine.diop_general_pythagorean` can
also be called directly to solve the same equation. This is true about the
general sum of squares too. Either you can call
:py:meth:`~sympy.solvers.diophantine.diop_general_pythagorean` or use the high
level API.

>>> diophantine(a**2 + b**2 + c**2 + d**2 + e**2 + f**2 - 112)
set([(8, 4, 4, 4, 0, 0)])
>>> diophantine(a**2 + b**2 + c**2 + d**2 + e**2 + f**2 - 112) == {(8, 4, 4, 4, 0, 0)}
True

If you want to get a more thorough idea about the the Diophantine module please
refer to the following blog.
Expand Down
1 change: 0 additions & 1 deletion doc/modules/utilities/index.rst
Expand Up @@ -21,6 +21,5 @@ Contents:
misc.rst
pkgdata.rst
randtest.rst
runtests.rst
source.rst
timeutils.rst
6 changes: 0 additions & 6 deletions doc/modules/utilities/runtests.rst

This file was deleted.

2 changes: 1 addition & 1 deletion doc/tutorial/basic_operations.rst
Expand Up @@ -183,7 +183,7 @@ library math module, use ``"math"``.

>>> f = lambdify(x, expr, "math")
>>> f(0.1)
0.0998334166468
0.09983341664682815

To use lambdify with numerical libraries that it does not know about, pass a
dictionary of ``sympy_name:numerical_function`` pairs. For example
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorial/gotchas.rst
Expand Up @@ -300,7 +300,7 @@ to a Python expression. Use the :func:`sympy.core.sympify.sympify` function, or
:func:`S <sympy.core.sympify.sympify>`, to ensure that something is a SymPy expression.

>>> 6.2 # Python float. Notice the floating point accuracy problems.
6.2000000000000002
6.2
>>> type(6.2) # <type 'float'> in Python 2.x, <class 'float'> in Py3k
<... 'float'>
>>> S(6.2) # SymPy Float has no such problems because of arbitrary precision.
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorial/intro.rst
Expand Up @@ -21,7 +21,7 @@ compute square roots. We might do something like this
the square root of a number that isn't a perfect square

>>> math.sqrt(8)
2.82842712475
2.8284271247461903

Here we got an approximate result. 2.82842712475 is not the exact square root
of 8 (indeed, the actual square root of 8 cannot be represented by a finite
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Expand Up @@ -12,3 +12,4 @@ select = E101,W191,W291,W293,E111,E112,E113,W292,W391
[pytest]
minversion = 2.7.0
doctest_optionflags = ELLIPSIS NORMALIZE_WHITESPACE IGNORE_EXCEPTION_DETAIL
addopts = --ignore=doc/conf.py --ignore=setup.py --doctest-glob='*.rst'
4 changes: 0 additions & 4 deletions sympy/plotting/plot.py
Expand Up @@ -35,10 +35,6 @@
from sympy.utilities.iterables import is_sequence
from .experimental_lambdify import (vectorized_lambdify, lambdify)

# N.B.
# When changing the minimum module version for matplotlib, please change
# the same in the `SymPyDocTestFinder`` in `sympy/utilities/runtests.py`

# Global variable
# Set to False when running tests / doctests so that the plots don't show.
_show = True
Expand Down

0 comments on commit 9077870

Please sign in to comment.