Skip to content

Commit

Permalink
Switch from nose to unittest.
Browse files Browse the repository at this point in the history
The nose docs state:

> Nose has been in maintenance mode for the past several years and will
> likely cease without a new person/team to take over maintainership.
> New projects should consider using Nose2, py.test, or just plain
> unittest/unittest2.

As we aren't using any of nose's features, its easiest to switch
to the standard lib unittest.

Also clean us various warnings as Nose was hiding them:

* warn => warning
* assertRegexpMatches => assertRegex
* Ensure 'new' files are closed.
* Cleanup tempdir
* assertEquals => assertEqual
  • Loading branch information
waylan authored Dec 23, 2019
1 parent 2491c14 commit 399f842
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 15 deletions.
6 changes: 3 additions & 3 deletions mkdocs/commands/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def _build_theme_template(template_name, env, files, config, nav):
try:
template = env.get_template(template_name)
except TemplateNotFound:
log.warn("Template skipped: '{}' not found in theme directories.".format(template_name))
log.warning("Template skipped: '{}' not found in theme directories.".format(template_name))
return

output = _build_template(template_name, template, files, config, nav)
Expand All @@ -132,14 +132,14 @@ def _build_extra_template(template_name, files, config, nav):

file = files.get_file_from_path(template_name)
if file is None:
log.warn("Template skipped: '{}' not found in docs_dir.".format(template_name))
log.warning("Template skipped: '{}' not found in docs_dir.".format(template_name))
return

try:
with open(file.abs_src_path, 'r', encoding='utf-8', errors='strict') as f:
template = jinja2.Template(f.read())
except Exception as e:
log.warn("Error reading template '{}': {}".format(template_name, e))
log.warning("Error reading template '{}': {}".format(template_name, e))
return

output = _build_template(template_name, template, files, config, nav)
Expand Down
2 changes: 1 addition & 1 deletion mkdocs/commands/gh_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def _check_version(branch):
previousv = parse_version(m.group()) if m else None
currentv = parse_version(mkdocs.__version__)
if not previousv:
log.warn('Version check skipped: No version specified in previous deployment.')
log.warning('Version check skipped: No version specified in previous deployment.')
elif currentv > previousv:
log.info(
'Previous deployment was done with MkDocs version {}; '
Expand Down
6 changes: 4 additions & 2 deletions mkdocs/commands/new.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ def new(output_dir):
os.mkdir(output_dir)

log.info('Writing config file: %s', config_path)
open(config_path, 'w', encoding='utf-8').write(config_text)
with open(config_path, 'w', encoding='utf-8') as f:
f.write(config_text)

if os.path.exists(index_path):
return

log.info('Writing initial docs: %s', index_path)
if not os.path.exists(docs_dir):
os.mkdir(docs_dir)
open(index_path, 'w', encoding='utf-8').write(index_text)
with open(index_path, 'w', encoding='utf-8') as f:
f.write(index_text)
2 changes: 1 addition & 1 deletion mkdocs/tests/build_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ def test_build_page_dirty_modified(self, site_dir, docs_dir, mock_write_file):
@tempdir(files={'testing.html': '<p>page content</p>'})
@mock.patch('mkdocs.utils.write_file')
def test_build_page_dirty_not_modified(self, site_dir, mock_write_file):
cfg = load_config(site_dir=site_dir, nav=['index.md'], plugins=[])
cfg = load_config(site_dir=site_dir, nav=['testing.md'], plugins=[])
files = Files([File('testing.md', cfg['docs_dir'], cfg['site_dir'], cfg['use_directory_urls'])])
nav = get_navigation(files, cfg)
page = files.documentation_pages()[0].page
Expand Down
1 change: 1 addition & 0 deletions mkdocs/tests/config/base_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def test_load_from_file(self):
self.assertEqual(cfg['site_name'], 'MkDocs Test')
finally:
os.remove(config_file.name)
temp_dir.cleanup()

def test_load_from_missing_file(self):

Expand Down
10 changes: 5 additions & 5 deletions mkdocs/tests/search_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def test_html_stripper(self):

stripper.feed("<h1>Testing</h1><p>Content</p>")

self.assertEquals(stripper.data, ["Testing", "Content"])
self.assertEqual(stripper.data, ["Testing", "Content"])

def test_content_parser(self):

Expand All @@ -196,7 +196,7 @@ def test_content_parser(self):
parser.feed('<h1 id="title">Title</h1>TEST')
parser.close()

self.assertEquals(parser.data, [search_index.ContentSection(
self.assertEqual(parser.data, [search_index.ContentSection(
text=["TEST"],
id_="title",
title="Title"
Expand All @@ -209,7 +209,7 @@ def test_content_parser_no_id(self):
parser.feed("<h1>Title</h1>TEST")
parser.close()

self.assertEquals(parser.data, [search_index.ContentSection(
self.assertEqual(parser.data, [search_index.ContentSection(
text=["TEST"],
id_=None,
title="Title"
Expand All @@ -222,7 +222,7 @@ def test_content_parser_content_before_header(self):
parser.feed("Content Before H1 <h1>Title</h1>TEST")
parser.close()

self.assertEquals(parser.data, [search_index.ContentSection(
self.assertEqual(parser.data, [search_index.ContentSection(
text=["TEST"],
id_=None,
title="Title"
Expand All @@ -234,7 +234,7 @@ def test_content_parser_no_sections(self):

parser.feed("No H1 or H2<span>Title</span>TEST")

self.assertEquals(parser.data, [])
self.assertEqual(parser.data, [])

def test_find_toc_by_id(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion mkdocs/tests/structure/page_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def test_page_defaults(self):
cfg = load_config()
fl = File('testing.md', cfg['docs_dir'], cfg['site_dir'], cfg['use_directory_urls'])
pg = Page('Foo', fl, cfg)
self.assertRegexpMatches(pg.update_date, r'\d{4}-\d{2}-\d{2}')
self.assertRegex(pg.update_date, r'\d{4}-\d{2}-\d{2}')
self.assertEqual(pg.url, 'testing/')
self.assertEqual(pg.abs_url, None)
self.assertEqual(pg.canonical_url, None)
Expand Down
1 change: 0 additions & 1 deletion requirements/test.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
coverage
flake8
nose
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ deps=
py{35,36,37,38,py3}-{unittests,min-req}: -rrequirements/test.txt
commands=
{envpython} --version
py{35,36,37,38,py3}-{unittests,min-req}: {envbindir}/nosetests --with-coverage --cover-package mkdocs mkdocs
py{35,36,37,38,py3}-{unittests,min-req}: {envbindir}/coverage run --source=mkdocs --omit 'mkdocs/tests/*' -m unittest discover -p '*tests.py' mkdocs
py{35,36,37,38,py3}-{unittests,min-req}: {envbindir}/coverage report --show-missing
py{35,36,37,38,py3}-integration: {envpython} -m mkdocs.tests.integration --output={envtmpdir}/builds

[testenv:flake8]
Expand Down

0 comments on commit 399f842

Please sign in to comment.