Skip to content

Remove py2-specific dependencies and fix tests #192

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 5 commits into from
Feb 23, 2021
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Install Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python_version }}
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: python -m pip install tox
- name: Run tests
Expand Down
2 changes: 0 additions & 2 deletions readme_renderer/integration/distutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import distutils.log
from distutils.command.check import check as _check
from distutils.core import Command
import six

from ..rst import render

Expand All @@ -35,7 +34,6 @@
r'(?P<message>.*)', re.DOTALL | re.MULTILINE)


@six.python_2_unicode_compatible
class _WarningStream(object):
def __init__(self):
self.output = io.StringIO()
Expand Down
9 changes: 2 additions & 7 deletions readme_renderer/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,12 @@
import re
import warnings

from html.parser import unescape

import pygments
import pygments.lexers
import pygments.formatters

try:
from six.moves.html_parser import unescape
except ImportError: # Python 2
from six.moves import html_parser

unescape = html_parser.HTMLParser().unescape

from .clean import clean

_EXTRA_WARNING = (
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
],
install_requires=["bleach>=2.1.0", "docutils>=0.13.1", "Pygments>=2.5.1", "six"],
install_requires=["bleach>=2.1.0", "docutils>=0.13.1", "Pygments>=2.5.1"],
entry_points={
"distutils.commands": ["check = readme_renderer.integration.distutils:Check"],
},
Expand Down
26 changes: 13 additions & 13 deletions tests/test_integration_distutils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import distutils.dist
import unittest.mock

import mock
import pytest
import setuptools.dist

Expand All @@ -11,7 +11,7 @@ def test_valid_rst():
dist = distutils.dist.Distribution(attrs=dict(
long_description="Hello, I am some text."))
checker = readme_renderer.integration.distutils.Check(dist)
checker.warn = mock.Mock()
checker.warn = unittest.mock.Mock()

checker.check_restructuredtext()

Expand All @@ -22,14 +22,14 @@ def test_invalid_rst():
dist = distutils.dist.Distribution(attrs=dict(
long_description="Hello, I am some `totally borked< text."))
checker = readme_renderer.integration.distutils.Check(dist)
checker.warn = mock.Mock()
checker.announce = mock.Mock()
checker.warn = unittest.mock.Mock()
checker.announce = unittest.mock.Mock()

checker.check_restructuredtext()

# Should warn once for the syntax error, and finally to warn that the
# overall syntax is invalid
checker.warn.assert_called_once_with(mock.ANY)
checker.warn.assert_called_once_with(unittest.mock.ANY)
message = checker.warn.call_args[0][0]
assert 'invalid markup' in message
assert 'line 1: Warning:' in message
Expand All @@ -47,14 +47,14 @@ def test_malicious_rst():
dist = distutils.dist.Distribution(attrs=dict(
long_description=description))
checker = readme_renderer.integration.distutils.Check(dist)
checker.warn = mock.Mock()
checker.announce = mock.Mock()
checker.warn = unittest.mock.Mock()
checker.announce = unittest.mock.Mock()

checker.check_restructuredtext()

# Should warn once for the syntax error, and finally to warn that the
# overall syntax is invalid
checker.warn.assert_called_once_with(mock.ANY)
checker.warn.assert_called_once_with(unittest.mock.ANY)
message = checker.warn.call_args[0][0]
assert 'directive disabled' in message

Expand All @@ -68,7 +68,7 @@ def test_markdown():
long_description="Hello, I am some text.",
long_description_content_type="text/markdown"))
checker = readme_renderer.integration.distutils.Check(dist)
checker.warn = mock.Mock()
checker.warn = unittest.mock.Mock()

checker.check_restructuredtext()

Expand All @@ -79,21 +79,21 @@ def test_markdown():
def test_invalid_missing():
dist = distutils.dist.Distribution(attrs=dict())
checker = readme_renderer.integration.distutils.Check(dist)
checker.warn = mock.Mock()
checker.warn = unittest.mock.Mock()

checker.check_restructuredtext()

checker.warn.assert_called_once_with(mock.ANY)
checker.warn.assert_called_once_with(unittest.mock.ANY)
assert 'missing' in checker.warn.call_args[0][0]


def test_invalid_empty():
dist = distutils.dist.Distribution(attrs=dict(
long_description=""))
checker = readme_renderer.integration.distutils.Check(dist)
checker.warn = mock.Mock()
checker.warn = unittest.mock.Mock()

checker.check_restructuredtext()

checker.warn.assert_called_once_with(mock.ANY)
checker.warn.assert_called_once_with(unittest.mock.ANY)
assert 'missing' in checker.warn.call_args[0][0]
3 changes: 1 addition & 2 deletions tests/test_rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import os.path

import pytest
import six

from readme_renderer.rst import render

Expand Down Expand Up @@ -46,7 +45,7 @@ def test_rst_002():


def test_rst_raw():
warnings = six.StringIO()
warnings = io.StringIO()
assert render("""
.. raw:: html
<script>I am evil</script>
Expand Down
3 changes: 1 addition & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ envlist = py36,py37,py38,py39,pep8,packaging,noextra
[testenv]
deps =
pytest
mock
commands =
py.test --strict {posargs}
pytest --strict {posargs}
extras = md

[testenv:pep8]
Expand Down