Cleanup test environment and requirements

- pytest: verbose isn't needed but show skipped tests
- mock is not needed anymore. it is part of stdlib
- Unpin Sphinx and fix warning about lexer
- Mirror tox command for doc build in tasks.py
This commit is contained in:
Deniz Turgut 2020-04-26 00:59:54 +03:00
commit 839629b102
No known key found for this signature in database
GPG key ID: 87B7168D7AB3ED2F
10 changed files with 11 additions and 54 deletions

View file

@ -61,7 +61,7 @@ html_show_sourcelink = False
def setup(app): def setup(app):
# overrides for wide tables in RTD theme # overrides for wide tables in RTD theme
app.add_stylesheet('theme_overrides.css') # path relative to _static app.add_css_file('theme_overrides.css') # path relative to _static
# -- Options for LaTeX output ------------------------------------------------- # -- Options for LaTeX output -------------------------------------------------

View file

@ -242,7 +242,7 @@ as the name of the metadata field, except in all-lowercase characters.
For example, you could add a field called `FacebookImage` to your article For example, you could add a field called `FacebookImage` to your article
metadata, as shown below: metadata, as shown below:
.. code-block:: markdown .. code-block:: md
Title: I love Python more than music Title: I love Python more than music
Date: 2013-11-06 10:06 Date: 2013-11-06 10:06

View file

@ -1,17 +1,11 @@
import os import os
from shutil import rmtree from shutil import rmtree
from tempfile import mkdtemp from tempfile import mkdtemp
from unittest.mock import MagicMock
from pelican.generators import ArticlesGenerator, PagesGenerator from pelican.generators import ArticlesGenerator, PagesGenerator
from pelican.tests.support import get_context, get_settings, unittest from pelican.tests.support import get_context, get_settings, unittest
try:
from unittest.mock import MagicMock
except ImportError:
try:
from mock import MagicMock
except ImportError:
MagicMock = False
CUR_DIR = os.path.dirname(__file__) CUR_DIR = os.path.dirname(__file__)
CONTENT_DIR = os.path.join(CUR_DIR, 'content') CONTENT_DIR = os.path.join(CUR_DIR, 'content')
@ -131,7 +125,6 @@ class TestCache(unittest.TestCase):
self.assertEqual(uncached_pages, cached_pages) self.assertEqual(uncached_pages, cached_pages)
self.assertEqual(uncached_hidden_pages, cached_hidden_pages) self.assertEqual(uncached_hidden_pages, cached_hidden_pages)
@unittest.skipUnless(MagicMock, 'Needs Mock module')
def test_article_object_caching(self): def test_article_object_caching(self):
"""Test Article objects caching at the generator level""" """Test Article objects caching at the generator level"""
settings = self._get_cache_enabled_settings() settings = self._get_cache_enabled_settings()
@ -162,7 +155,6 @@ class TestCache(unittest.TestCase):
""" """
self.assertEqual(generator.readers.read_file.call_count, 6) self.assertEqual(generator.readers.read_file.call_count, 6)
@unittest.skipUnless(MagicMock, 'Needs Mock module')
def test_article_reader_content_caching(self): def test_article_reader_content_caching(self):
"""Test raw article content caching at the reader level""" """Test raw article content caching at the reader level"""
settings = self._get_cache_enabled_settings() settings = self._get_cache_enabled_settings()
@ -185,7 +177,6 @@ class TestCache(unittest.TestCase):
for reader in readers.values(): for reader in readers.values():
self.assertEqual(reader.read.call_count, 0) self.assertEqual(reader.read.call_count, 0)
@unittest.skipUnless(MagicMock, 'Needs Mock module')
def test_article_ignore_cache(self): def test_article_ignore_cache(self):
"""Test that all the articles are read again when not loading cache """Test that all the articles are read again when not loading cache
@ -212,7 +203,6 @@ class TestCache(unittest.TestCase):
generator.readers.read_file.call_count, generator.readers.read_file.call_count,
orig_call_count) orig_call_count)
@unittest.skipUnless(MagicMock, 'Needs Mock module')
def test_page_object_caching(self): def test_page_object_caching(self):
"""Test Page objects caching at the generator level""" """Test Page objects caching at the generator level"""
settings = self._get_cache_enabled_settings() settings = self._get_cache_enabled_settings()
@ -238,7 +228,6 @@ class TestCache(unittest.TestCase):
""" """
self.assertEqual(generator.readers.read_file.call_count, 1) self.assertEqual(generator.readers.read_file.call_count, 1)
@unittest.skipUnless(MagicMock, 'Needs Mock module')
def test_page_reader_content_caching(self): def test_page_reader_content_caching(self):
"""Test raw page content caching at the reader level""" """Test raw page content caching at the reader level"""
settings = self._get_cache_enabled_settings() settings = self._get_cache_enabled_settings()
@ -262,7 +251,6 @@ class TestCache(unittest.TestCase):
for reader in readers.values(): for reader in readers.values():
self.assertEqual(reader.read.call_count, 0) self.assertEqual(reader.read.call_count, 0)
@unittest.skipUnless(MagicMock, 'Needs Mock module')
def test_page_ignore_cache(self): def test_page_ignore_cache(self):
"""Test that all the pages are read again when not loading cache """Test that all the pages are read again when not loading cache

View file

@ -2,6 +2,7 @@ import locale
import os import os
from shutil import copy, rmtree from shutil import copy, rmtree
from tempfile import mkdtemp from tempfile import mkdtemp
from unittest.mock import MagicMock
from pelican.generators import (ArticlesGenerator, Generator, PagesGenerator, from pelican.generators import (ArticlesGenerator, Generator, PagesGenerator,
PelicanTemplateNotFound, StaticGenerator, PelicanTemplateNotFound, StaticGenerator,
@ -9,14 +10,6 @@ from pelican.generators import (ArticlesGenerator, Generator, PagesGenerator,
from pelican.tests.support import get_context, get_settings, unittest from pelican.tests.support import get_context, get_settings, unittest
from pelican.writers import Writer from pelican.writers import Writer
try:
from unittest.mock import MagicMock
except ImportError:
try:
from mock import MagicMock
except ImportError:
MagicMock = False
CUR_DIR = os.path.dirname(__file__) CUR_DIR = os.path.dirname(__file__)
CONTENT_DIR = os.path.join(CUR_DIR, 'content') CONTENT_DIR = os.path.join(CUR_DIR, 'content')
@ -198,7 +191,6 @@ class TestArticlesGenerator(unittest.TestCase):
return [[article.title, article.status, article.category.name, return [[article.title, article.status, article.category.name,
article.template] for article in articles] article.template] for article in articles]
@unittest.skipUnless(MagicMock, 'Needs Mock module')
def test_generate_feeds(self): def test_generate_feeds(self):
settings = get_settings() settings = get_settings()
settings['CACHE_PATH'] = self.temp_cache settings['CACHE_PATH'] = self.temp_cache
@ -218,7 +210,6 @@ class TestArticlesGenerator(unittest.TestCase):
generator.generate_feeds(writer) generator.generate_feeds(writer)
self.assertFalse(writer.write_feed.called) self.assertFalse(writer.write_feed.called)
@unittest.skipUnless(MagicMock, 'Needs Mock module')
def test_generate_feeds_override_url(self): def test_generate_feeds_override_url(self):
settings = get_settings() settings = get_settings()
settings['CACHE_PATH'] = self.temp_cache settings['CACHE_PATH'] = self.temp_cache
@ -334,7 +325,6 @@ class TestArticlesGenerator(unittest.TestCase):
categories_expected = ['default', 'yeah', 'test', 'zhi-dao-shu'] categories_expected = ['default', 'yeah', 'test', 'zhi-dao-shu']
self.assertEqual(sorted(categories), sorted(categories_expected)) self.assertEqual(sorted(categories), sorted(categories_expected))
@unittest.skipUnless(MagicMock, 'Needs Mock module')
def test_direct_templates_save_as_url_default(self): def test_direct_templates_save_as_url_default(self):
settings = get_settings() settings = get_settings()
@ -352,7 +342,6 @@ class TestArticlesGenerator(unittest.TestCase):
template_name='archives', template_name='archives',
page_name='archives', url="archives.html") page_name='archives', url="archives.html")
@unittest.skipUnless(MagicMock, 'Needs Mock module')
def test_direct_templates_save_as_url_modified(self): def test_direct_templates_save_as_url_modified(self):
settings = get_settings() settings = get_settings()
@ -373,7 +362,6 @@ class TestArticlesGenerator(unittest.TestCase):
page_name='archives/index', page_name='archives/index',
url="archives/") url="archives/")
@unittest.skipUnless(MagicMock, 'Needs Mock module')
def test_direct_templates_save_as_false(self): def test_direct_templates_save_as_false(self):
settings = get_settings() settings = get_settings()
@ -398,7 +386,6 @@ class TestArticlesGenerator(unittest.TestCase):
self.assertIn(custom_template, self.articles) self.assertIn(custom_template, self.articles)
self.assertIn(standard_template, self.articles) self.assertIn(standard_template, self.articles)
@unittest.skipUnless(MagicMock, 'Needs Mock module')
def test_period_in_timeperiod_archive(self): def test_period_in_timeperiod_archive(self):
""" """
Test that the context of a generated period_archive is passed Test that the context of a generated period_archive is passed
@ -1022,7 +1009,6 @@ class TestStaticGenerator(unittest.TestCase):
with open(self.endfile) as f: with open(self.endfile) as f:
self.assertEqual(f.read(), "staticcontent") self.assertEqual(f.read(), "staticcontent")
@unittest.skipUnless(MagicMock, 'Needs Mock module')
def test_file_update_required_when_dest_does_not_exist(self): def test_file_update_required_when_dest_does_not_exist(self):
staticfile = MagicMock() staticfile = MagicMock()
staticfile.source_path = self.startfile staticfile.source_path = self.startfile
@ -1032,7 +1018,6 @@ class TestStaticGenerator(unittest.TestCase):
update_required = self.generator._file_update_required(staticfile) update_required = self.generator._file_update_required(staticfile)
self.assertTrue(update_required) self.assertTrue(update_required)
@unittest.skipUnless(MagicMock, 'Needs Mock module')
def test_dest_and_source_mtimes_are_equal(self): def test_dest_and_source_mtimes_are_equal(self):
staticfile = MagicMock() staticfile = MagicMock()
staticfile.source_path = self.startfile staticfile.source_path = self.startfile
@ -1045,7 +1030,6 @@ class TestStaticGenerator(unittest.TestCase):
isnewer = self.generator._source_is_newer(staticfile) isnewer = self.generator._source_is_newer(staticfile)
self.assertFalse(isnewer) self.assertFalse(isnewer)
@unittest.skipUnless(MagicMock, 'Needs Mock module')
def test_source_is_newer(self): def test_source_is_newer(self):
staticfile = MagicMock() staticfile = MagicMock()
staticfile.source_path = self.startfile staticfile.source_path = self.startfile

View file

@ -1,16 +1,10 @@
import os import os
from unittest.mock import patch
from pelican import readers from pelican import readers
from pelican.tests.support import get_settings, unittest from pelican.tests.support import get_settings, unittest
from pelican.utils import SafeDatetime from pelican.utils import SafeDatetime
try:
from unittest.mock import patch
except ImportError:
try:
from mock import patch
except ImportError:
patch = False
CUR_DIR = os.path.dirname(__file__) CUR_DIR = os.path.dirname(__file__)
CONTENT_PATH = os.path.join(CUR_DIR, 'content') CONTENT_PATH = os.path.join(CUR_DIR, 'content')
@ -125,7 +119,6 @@ class DefaultReaderTest(ReaderTest):
self.assertDictHasSubset(page.metadata, expected) self.assertDictHasSubset(page.metadata, expected)
@unittest.skipUnless(patch, 'Needs Mock module')
def test_find_empty_alt(self): def test_find_empty_alt(self):
with patch('pelican.readers.logger') as log_mock: with patch('pelican.readers.logger') as log_mock:
content = ['<img alt="" src="test-image.png" width="300px" />', content = ['<img alt="" src="test-image.png" width="300px" />',

View file

@ -1,15 +1,8 @@
from unittest.mock import Mock
from pelican.tests.support import unittest from pelican.tests.support import unittest
try:
from unittest.mock import Mock
except ImportError:
try:
from mock import Mock
except ImportError:
Mock = False
@unittest.skipUnless(Mock, 'Needs Mock module')
class Test_abbr_role(unittest.TestCase): class Test_abbr_role(unittest.TestCase):
def call_it(self, text): def call_it(self, text):
from pelican.rstdirectives import abbr_role from pelican.rstdirectives import abbr_role

View file

@ -1,3 +1,3 @@
sphinx==1.4.9 sphinx
sphinx_rtd_theme sphinx_rtd_theme
livereload livereload

View file

@ -1,6 +1,5 @@
# Tests # Tests
Pygments==2.6.1 Pygments==2.6.1
mock
pytest==5.3.5 pytest==5.3.5
pytest-cov pytest-cov
pytest-xdist pytest-xdist

View file

@ -24,7 +24,7 @@ PRECOMMIT = (
@task @task
def docbuild(c): def docbuild(c):
"""Build documentation""" """Build documentation"""
c.run(f"{VENV_BIN}/sphinx-build docs docs/_build") c.run(f"{VENV_BIN}/sphinx-build -W docs docs/_build")
@task(docbuild) @task(docbuild)

View file

@ -14,7 +14,7 @@ deps =
commands = commands =
{envpython} --version {envpython} --version
pytest -sv --cov=pelican pelican pytest -s --cov=pelican pelican
[testenv:docs] [testenv:docs]
basepython = python3.6 basepython = python3.6
@ -28,7 +28,7 @@ commands =
filterwarnings = filterwarnings =
default::DeprecationWarning default::DeprecationWarning
error:.*:Warning:pelican error:.*:Warning:pelican
addopts = -n 2 addopts = -n 2 -r a
[flake8] [flake8]
application-import-names = pelican application-import-names = pelican