Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[MRG+1]: Use unicode #256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions sphinx_gallery/gen_gallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@


from __future__ import division, print_function, absolute_import
import codecs
import copy
import re
import os
Expand Down Expand Up @@ -188,24 +189,24 @@ def generate_gallery_rst(app):
computation_times += this_computation_times

# we create an index.rst with all examples
fhindex = open(os.path.join(gallery_dir, 'index.rst'), 'w')
# :orphan: to suppress "not included in TOCTREE" sphinx warnings
fhindex.write(":orphan:\n\n" + this_fhindex)
for directory in sorted(os.listdir(examples_dir)):
if os.path.isdir(os.path.join(examples_dir, directory)):
src_dir = os.path.join(examples_dir, directory)
target_dir = os.path.join(gallery_dir, directory)
this_fhindex, this_computation_times = generate_dir_rst(src_dir, target_dir, gallery_conf,
seen_backrefs)
fhindex.write(this_fhindex)
computation_times += this_computation_times

if gallery_conf['download_all_examples']:
download_fhindex = generate_zipfiles(gallery_dir)
fhindex.write(download_fhindex)

fhindex.write(SPHX_GLR_SIG)
fhindex.flush()
with codecs.open(os.path.join(gallery_dir, 'index.rst'), 'w',
encoding='utf-8') as fhindex:
# :orphan: to suppress "not included in TOCTREE" sphinx warnings
fhindex.write((u":orphan:\n\n" + this_fhindex))
for directory in sorted(os.listdir(examples_dir)):
if os.path.isdir(os.path.join(examples_dir, directory)):
src_dir = os.path.join(examples_dir, directory)
target_dir = os.path.join(gallery_dir, directory)
this_fhindex, this_computation_times = generate_dir_rst(src_dir, target_dir, gallery_conf,
seen_backrefs)
fhindex.write(this_fhindex)
computation_times += this_computation_times

if gallery_conf['download_all_examples']:
download_fhindex = generate_zipfiles(gallery_dir)
fhindex.write(download_fhindex)

fhindex.write(SPHX_GLR_SIG)

if gallery_conf['plot_gallery']:
logger.info("Computation time summary:", color='white')
Expand Down
3 changes: 2 additions & 1 deletion sphinx_gallery/gen_rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,8 @@ def generate_dir_rst(src_dir, target_dir, gallery_conf, seen_backrefs):
location=src_dir)
return "", [] # because string is an expected return type

with open(os.path.join(src_dir, 'README.txt')) as fid:
with codecs.open(os.path.join(src_dir, 'README.txt'), 'r',
encoding='utf-8') as fid:
fhindex = fid.read()
# Add empty lines to avoid bug in issue #165
fhindex += "\n\n"
Expand Down
3 changes: 2 additions & 1 deletion sphinx_gallery/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ def __init__(self):

def status_iterator(self, *args, **kwargs):
self.calls['status_iterator'].append(Params(args, kwargs))
yield
for it in args[0]:
yield it

def warning(self, *args, **kwargs):
self.calls['warning'].append(Params(args, kwargs))
Expand Down
24 changes: 20 additions & 4 deletions sphinx_gallery/tests/test_gen_rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@
import ast
import codecs
import copy
import logging
import tempfile
import re
import os
import shutil
import warnings
import zipfile
import pytest

import sphinx_gallery.gen_rst as sg
from sphinx_gallery import gen_gallery
from sphinx_gallery import downloads
from sphinx_gallery import gen_gallery, downloads
from sphinx_gallery.gen_gallery import generate_dir_rst
from sphinx_gallery import sphinx_compatibility
# Need to import gen_rst before matplotlib.pyplot to set backend to 'Agg'
import matplotlib.pyplot as plt

Expand Down Expand Up @@ -111,7 +112,7 @@ def test_extract_intro():
finally:
os.remove(f.name)
assert 'Docstring' not in result
assert result == 'This is the description of the example which goes on and on, Óscar'
assert result == 'This is the description of the example which goes on and on, Óscar' # noqa
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this comment doing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

turns off quality analysis / PEP8 in editors

assert 'second paragraph' not in result


Expand Down Expand Up @@ -177,6 +178,21 @@ def test_fail_example(log_collector):
raise ValueError('Did not stop executing script after error')


def test_gen_dir_rst(fakesphinxapp):
"""Test gen_dir_rst."""
gallery_conf = build_test_configuration()
print(os.listdir(gallery_conf['examples_dir']))
args = (gallery_conf['src_dir'], gallery_conf['gallery_dir'],
gallery_conf, [])
out = generate_dir_rst(*args)
assert out[0] == ""
fname_readme = os.path.join(gallery_conf['src_dir'], 'README.txt')
with open(fname_readme, 'wb') as fid:
fid.write(u"Testing\n=======\n\nÓscar here.".encode('utf-8'))
out = generate_dir_rst(*args)
assert u"Óscar here" in out[0]


def test_pattern_matching(log_collector):
"""Test if only examples matching pattern are executed"""

Expand Down