提交 d11e2251 authored 作者: Pascal Lamblin's avatar Pascal Lamblin

pep8 and syntax in unittest doc

上级 a3b4133f
...@@ -333,12 +333,12 @@ type this: ...@@ -333,12 +333,12 @@ type this:
Using Random Values in Test Cases Using Random Values in Test Cases
--------------------------------- ---------------------------------
numpy.random is often used in unit tests to initialize large data ``numpy.random`` is often used in unit tests to initialize large data
structures, for use as inputs to the function or module being structures, for use as inputs to the function or module being
tested. When doing this, it is imperative that the random number tested. When doing this, it is imperative that the random number
generator be seeded at the be beginning of each unit test. This will generator be seeded at the be beginning of each unit test. This will
ensure that unittest behaviour is consistent from one execution to ensure that unittest behaviour is consistent from one execution to
another (i.e always pass or always fail). another (i.e., always pass or always fail).
Instead of using ``numpy.random.seed`` to do this, we encourage users to Instead of using ``numpy.random.seed`` to do this, we encourage users to
do the following: do the following:
...@@ -351,30 +351,30 @@ do the following: ...@@ -351,30 +351,30 @@ do the following:
def setUp(self): def setUp(self):
unittest_tools.seed_rng() unittest_tools.seed_rng()
# OR ... call with an explicit seed # OR ... call with an explicit seed
unittest_tools.seed_rng(234234) #use only if really necessary! unittest_tools.seed_rng(234234) # use only if really necessary!
The behaviour of seed_rng is as follows: The behaviour of ``seed_rng`` is as follows:
* If an explicit seed is given, it will be used for seeding numpy's rng. * If an explicit seed is given, it will be used for seeding numpy's rng.
* If not, it will use ``config.unittests.rseed`` (its default value is 666). * If not, it will use ``config.unittests.rseed`` (its default value is ``666``).
* If config.unittests.rseed is set to "random", it will seed the rng with * If ``config.unittests.rseed`` is set to ``"random"``, it will seed the rng with
None, which is equivalent to seeding with a random seed. None, which is equivalent to seeding with a random seed.
The main advantage of using unittest_tools.seed_rng is that it allows The main advantage of using ``unittest_tools.seed_rng`` is that it allows
us to change the seed used in the unitests, without having to manually us to change the seed used in the unitests, without having to manually
edit all the files. For example, this allows the nightly build to run edit all the files. For example, this allows the nightly build to run
theano-nose repeatedly, changing the seed on every run (hence achieving ``theano-nose`` repeatedly, changing the seed on every run (hence achieving
a higher confidence that the variables are correct), while still a higher confidence that the variables are correct), while still
making sure unittests are deterministic. making sure unittests are deterministic.
Users who prefer their unittests to be random (when run on their local Users who prefer their unittests to be random (when run on their local
machine) can simply set ``config.unittests.rseed`` to 'random' (see machine) can simply set ``config.unittests.rseed`` to ``'random'`` (see
:mod:`config`). :mod:`config`).
Similarly, to provide a seed to numpy.random.RandomState, simply use: Similarly, to provide a seed to ``numpy.random.RandomState``, simply use:
.. testcode:: .. testcode::
...@@ -382,7 +382,7 @@ Similarly, to provide a seed to numpy.random.RandomState, simply use: ...@@ -382,7 +382,7 @@ Similarly, to provide a seed to numpy.random.RandomState, simply use:
rng = numpy.random.RandomState(unittest_tools.fetch_seed()) rng = numpy.random.RandomState(unittest_tools.fetch_seed())
# OR providing an explicit seed # OR providing an explicit seed
rng = numpy.random.RandomState(unittest_tools.fetch_seed(1231)) #again not recommended rng = numpy.random.RandomState(unittest_tools.fetch_seed(1231)) # again not recommended
Note that the ability to change the seed from one nosetest to another, Note that the ability to change the seed from one nosetest to another,
is incompatible with the method of hard-coding the baseline variables is incompatible with the method of hard-coding the baseline variables
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论