Skip to content

Commit

Permalink
Merge pull request #2703 from getnikola/drop-doctests
Browse files Browse the repository at this point in the history
Don’t use doctests anymore
  • Loading branch information
Kwpolska committed Mar 31, 2017
2 parents 3835c95 + 0917282 commit c8be300
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 28 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Expand Up @@ -29,7 +29,6 @@ install:
- if [[ $NMODE == 'nikola' ]]; then pip install .; fi
- if [[ $NMODE == 'flake8' ]]; then pip install flake8 pydocstyle; fi
script:
- if [[ $NMODE == 'nikola' ]]; then py.test --doctest-modules nikola/; fi
- if [[ $NMODE == 'nikola' ]]; then py.test tests/; fi
- if [[ $NMODE == 'nikola' ]]; then nikola; fi
- if [[ $NMODE == 'nikola' ]]; then nikola help; fi
Expand Down
4 changes: 2 additions & 2 deletions docs/internals.txt
Expand Up @@ -85,8 +85,8 @@ one of the existing ones.
.. sidebar:: Tests

While Nikola is not a hardcore TDD project, we like tests. So, please add them if you can.
You can do doctests, you can do unit tests, you can do integration tests. There is support
for all of them.
You can write unit tests or integration tests. (Doctests are not supported
anymore due to fragility.)

Posts and Pages
---------------
Expand Down
12 changes: 2 additions & 10 deletions dodo.py
Expand Up @@ -65,26 +65,18 @@ def set_nikola_test_locales():
return {'actions': [set_nikola_test_locales], 'verbosity': 2}


def task_doctest():
"""run doctests with py.test"""
return {
'actions': ['py.test --doctest-modules nikola/'],
'verbosity': 2,
}


def task_test():
"""run unit-tests using py.test"""
return {
'task_dep': ['locale', 'doctest'],
'task_dep': ['locale'],
'actions': ['py.test tests/'],
}


def task_coverage():
"""run unit-tests using py.test, with coverage reporting"""
return {
'task_dep': ['locale', 'doctest'],
'task_dep': ['locale'],
'actions': ['py.test --cov nikola --cov-report term-missing tests/'],
'verbosity': 2,
}
Expand Down
27 changes: 13 additions & 14 deletions nikola/utils.py
Expand Up @@ -469,9 +469,8 @@ class TemplateHookRegistry(object):
>>> r = TemplateHookRegistry('foo', None)
>>> r.append('Hello!')
>>> r.append(lambda x: 'Hello ' + x + '!', False, 'world')
>>> str(r()) # str() call is not recommended in real use
>>> repr(r())
'Hello!\nHello world!'
>>>
"""

def __init__(self, name, site):
Expand Down Expand Up @@ -954,26 +953,26 @@ def get_crumbs(path, is_file=False, index_folder=None, lang=None):
>>> crumbs = get_crumbs('galleries')
>>> len(crumbs)
1
>>> print('|'.join(crumbs[0]))
#|galleries
>>> crumbs[0]
['#', 'galleries']
>>> crumbs = get_crumbs(os.path.join('galleries','demo'))
>>> len(crumbs)
2
>>> print('|'.join(crumbs[0]))
..|galleries
>>> print('|'.join(crumbs[1]))
#|demo
>>> crumbs[0]
['..', 'galleries']
>>> crumbs[1]
['#', 'demo']
>>> crumbs = get_crumbs(os.path.join('listings','foo','bar'), is_file=True)
>>> len(crumbs)
3
>>> print('|'.join(crumbs[0]))
..|listings
>>> print('|'.join(crumbs[1]))
.|foo
>>> print('|'.join(crumbs[2]))
#|bar
>>> crumbs[0]
['..', 'listings']
>>> crumbs[1]
['.', 'foo']
>>> crumbs[2]
['#', 'bar']
"""
crumbs = path.split(os.sep)
_crumbs = []
Expand Down
7 changes: 7 additions & 0 deletions tests/test_compile_markdown.py
Expand Up @@ -64,5 +64,12 @@ def test_compile_strikethrough(self):
actual_output = self.compile(input_str)
self.assertEquals(actual_output.strip(), expected_output.strip())

def test_mdx_podcast(self):
input_str = "[podcast]https://archive.org/download/Rebeldes_Stereotipos/rs20120609_1.mp3[/podcast]"
expected_output = '<p><audio controls=""><source src="https://archive.org/download/Rebeldes_Stereotipos/rs20120609_1.mp3" type="audio/mpeg"></source></audio></p>'
actual_output = self.compile(input_str)
self.assertEquals(actual_output.strip(), expected_output.strip())


if __name__ == '__main__':
unittest.main()
63 changes: 62 additions & 1 deletion tests/test_utils.py
Expand Up @@ -2,9 +2,13 @@
from __future__ import unicode_literals
import unittest
import mock
import os
import lxml.html
from nikola.post import get_meta
from nikola.utils import demote_headers, TranslatableSetting
from nikola.utils import (demote_headers, TranslatableSetting, get_crumbs,
TemplateHookRegistry, get_asset_path, get_theme_chain,
get_translation_candidate)
from nikola.plugins.task.sitemap import get_base_path as sitemap_get_base_path


class dummy(object):
Expand Down Expand Up @@ -327,5 +331,62 @@ def test_get_metadata_from_file():
assert 'title' in g([".. foo: bar", "", "FooBar", "------"])


def test_get_asset_path():
assert get_asset_path('assets/css/rst.css', get_theme_chain('bootstrap3', ['themes'])).replace('\\', '/').endswith('nikola/data/themes/base/assets/css/rst.css')
assert get_asset_path('assets/css/theme.css', get_theme_chain('bootstrap3', ['themes'])).replace('\\', '/').endswith('nikola/data/themes/bootstrap3/assets/css/theme.css')
assert get_asset_path('nikola.py', get_theme_chain('bootstrap3', ['themes']), {'nikola': ''}).replace('\\', '/').endswith('nikola/nikola.py')
assert get_asset_path('nikola.py', get_theme_chain('bootstrap3', ['themes']), {'nikola': 'nikola'}) is None
assert get_asset_path('nikola/nikola.py', get_theme_chain('bootstrap3', ['themes']), {'nikola': 'nikola'}).replace('\\', '/').endswith('nikola/nikola.py')


def test_get_crumbs():
crumbs = get_crumbs('galleries')
assert len(crumbs) == 1
assert crumbs[0] == ['#', 'galleries']

crumbs = get_crumbs(os.path.join('galleries', 'demo'))
assert len(crumbs) == 2
assert crumbs[0] == ['..', 'galleries']
assert crumbs[1] == ['#', 'demo']

crumbs = get_crumbs(os.path.join('listings', 'foo', 'bar'), is_file=True)
assert len(crumbs) == 3
assert crumbs[0] == ['..', 'listings']
assert crumbs[1] == ['.', 'foo']
assert crumbs[2] == ['#', 'bar']


def test_get_translation_candidate():
config = {'TRANSLATIONS_PATTERN': '{path}.{lang}.{ext}', 'DEFAULT_LANG': 'en', 'TRANSLATIONS': {'es': '1', 'en': 1}}
assert get_translation_candidate(config, '*.rst', 'es') == '*.es.rst'
assert get_translation_candidate(config, 'fancy.post.rst', 'es') == 'fancy.post.es.rst'
assert get_translation_candidate(config, '*.es.rst', 'es') == '*.es.rst'
assert get_translation_candidate(config, '*.es.rst', 'en') == '*.rst'
assert get_translation_candidate(config, 'cache/posts/fancy.post.es.html', 'en') == 'cache/posts/fancy.post.html'
assert get_translation_candidate(config, 'cache/posts/fancy.post.html', 'es') == 'cache/posts/fancy.post.es.html'
assert get_translation_candidate(config, 'cache/pages/charts.html', 'es') == 'cache/pages/charts.es.html'
assert get_translation_candidate(config, 'cache/pages/charts.html', 'en') == 'cache/pages/charts.html'

config = {'TRANSLATIONS_PATTERN': '{path}.{ext}.{lang}', 'DEFAULT_LANG': 'en', 'TRANSLATIONS': {'es': '1', 'en': 1}}
assert get_translation_candidate(config, '*.rst', 'es') == '*.rst.es'
assert get_translation_candidate(config, '*.rst.es', 'es') == '*.rst.es'
assert get_translation_candidate(config, '*.rst.es', 'en') == '*.rst'
assert get_translation_candidate(config, 'cache/posts/fancy.post.html.es', 'en') == 'cache/posts/fancy.post.html'
assert get_translation_candidate(config, 'cache/posts/fancy.post.html', 'es') == 'cache/posts/fancy.post.html.es'


def test_TemplateHookRegistry():
r = TemplateHookRegistry('foo', None)
r.append('Hello!')
r.append(lambda x: 'Hello ' + x + '!', False, 'world')
assert r() == 'Hello!\nHello world!'


def test_sitemap_get_base_path():
assert sitemap_get_base_path('http://some.site') == '/'
assert sitemap_get_base_path('http://some.site/') == '/'
assert sitemap_get_base_path('http://some.site/some/sub-path') == '/some/sub-path/'
assert sitemap_get_base_path('http://some.site/some/sub-path/') == '/some/sub-path/'

if __name__ == '__main__':
unittest.main()

0 comments on commit c8be300

Please sign in to comment.