Last active
June 13, 2018 12:50
-
-
Save twidi/9ce8ed0e8f92788031daaa78a765da75 to your computer and use it in GitHub Desktop.
Revisions
-
twidi revised this gist
Jul 1, 2016 . 2 changed files with 14 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,11 +15,17 @@ Blah blah blah from django.db import connection connection.creation.create_test_db(verbosity=0) # I use sqlite3 inmemory .. testcode:: print('this python code will be tested because in `testcode`, but not displayed by github") .. code-block:: print('this python code will be tested because in `code-block` which is replaced by `testcode` in our bash cript") .. code:: python print("this python code won't be tested because in `code`") This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,8 +8,10 @@ TMPDIR=.tmpdocs rm -rf $TMPDIR mkdir $TMPDIR # We copy in it our file to be tested, replacing "code-block" by "testcode" (we need to do it # because github don't display the "testcode" sections, but we want them to be displayed, and # the tests only work on "testcode" sections. sed -e 's/.. code-block:: python/.. testcode::/' README.rst > $TMPDIR/README.rst # Create the smallest configuration file possible for shpinx cat > $TMPDIR/conf.py <<EOF -
twidi renamed this gist
Jun 30, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
twidi revised this gist
Jun 30, 2016 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ # Real name of this file is README.rst but I don't want github to render the rst ;) Blah blah blah .. testsetup:: -
twidi renamed this gist
Jun 30, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
twidi created this gist
Jun 30, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ Blah blah blah .. testsetup:: # This prepare the django environment to run all the "testcode" in this file # This is not visible in the rendered README import os os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings' import django django.setup() from django.db import connection connection.creation.create_test_db(verbosity=0) # I use sqlite3 inmemory .. code-block:: python print("this python code won't be tested because in `code-block`") .. testcode:: print('this python code will be tested because in `testcode`") This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ #!/usr/bin/env bash # Run the tests included in the README.rst file # Temporary directory to be used by sphinx TMPDIR=.tmpdocs # Will reset it before rm -rf $TMPDIR mkdir $TMPDIR # We copy in it our file to be tested cp README.rst $TMPDIR/ # Create the smallest configuration file possible for shpinx cat > $TMPDIR/conf.py <<EOF extensions = ['sphinx.ext.doctest'] master_doc = 'README' EOF # And we can run the tests sphinx-build -q -c $TMPDIR -b doctest $TMPDIR $TMPDIR $TMPDIR/README.rst # Save the exit status to return it at the end ERROR=$? # Clean our mess rm -fr $TMPDIR # We want to tell the world if something was wrong exit $ERROR This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ """Test all examples from the README.rst file""" import os import subprocess from unittest import TestCase class ExamplesTestCase(TestCase): """Run all the example in the readme file""" def test_all(self): """The example are tested by running sphinx with the doctest plugin And it's done by running the ``test-readme.sh`` file, and in case of errors, the whole output is displayed and the test marked as failed. """ test_file_dir = os.path.join(os.path.dirname(__file__), '..') test_file_path = os.path.join(test_file_dir, 'test-readme.sh') try: subprocess.check_output( [test_file_path], shell=True, stderr=subprocess.STDOUT, cwd=test_file_dir, ) except subprocess.CalledProcessError as exception: try: output = 'Error while running examples in README.rst :\n\n%s' % \ exception.output.decode('utf-8') except Exception: # pylint: disable=broad-except output = exception.output self.fail(output)