Skip to content

Commit

Permalink
Require Python 3.5+ (#133)
Browse files Browse the repository at this point in the history
BREAKING CHANGE

Closes #124
  • Loading branch information
paulmelnikow authored Sep 30, 2020
1 parent 18a1213 commit 2fdae37
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 58 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
language: python
sudo: false
python:
- 2.7
- 3.4
- 3.5
- 3.6
- 3.7
Expand Down
14 changes: 3 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
with open("README.md") as f:
readme = f.read()

tests_require = ["six", "pytest>=4.6", "pytest-cov", "nose", "django>=1.10.6"]
tests_require = ["pytest>=4.6", "pytest-cov", "nose", "django>=1.10.6"]

setup(
name="snapshottest",
Expand All @@ -23,7 +23,7 @@
],
"nose.plugins.0.10": ["snapshottest = snapshottest.nose:SnapshotTestPlugin"],
},
install_requires=["six>=1.10.0", "termcolor", "fastdiff>=0.1.4,<1"],
install_requires=["termcolor", "fastdiff>=0.1.4,<1"],
tests_require=tests_require,
extras_require={
"test": tests_require,
Expand All @@ -34,21 +34,13 @@
"nose",
],
},
requires_python=">=3.5",
classifiers=[
"Development Status :: 5 - Production/Stable",
"Framework :: Django",
"Framework :: Pytest",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Topic :: Software Development :: Libraries",
"Topic :: Software Development :: Testing",
"Topic :: Software Development :: Testing :: Unit",
Expand Down
1 change: 0 additions & 1 deletion snapshottest/django.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import
from django.test import TestCase as dTestCase
from django.test import SimpleTestCase as dSimpleTestCase
from django.test.runner import DiscoverRunner
Expand Down
3 changes: 0 additions & 3 deletions snapshottest/error.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from __future__ import unicode_literals


class SnapshotError(Exception):
pass

Expand Down
3 changes: 1 addition & 2 deletions snapshottest/formatters.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import math
import six
from collections import defaultdict

from .sorted_dict import SortedDict
Expand Down Expand Up @@ -168,7 +167,7 @@ def default_formatters():
CollectionFormatter(list, format_list),
CollectionFormatter(set, format_set),
CollectionFormatter(frozenset, format_frozenset),
TypeFormatter(six.string_types, format_str),
TypeFormatter((str,), format_str),
TypeFormatter((float,), format_float),
TypeFormatter((int, complex, bool, bytes), format_std_type),
GenericFormatter(),
Expand Down
1 change: 0 additions & 1 deletion snapshottest/nose.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import
import logging
import os

Expand Down
1 change: 0 additions & 1 deletion snapshottest/pytest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import
import pytest
import re

Expand Down
1 change: 0 additions & 1 deletion snapshottest/unittest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import
import unittest
import inspect

Expand Down
46 changes: 15 additions & 31 deletions tests/test_formatter.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import pytest
import six
from math import isnan

from snapshottest.formatter import Formatter

if not six.PY2:
import unittest.mock
import unittest.mock


@pytest.mark.parametrize(
Expand All @@ -33,45 +29,33 @@ def test_text_formatting(text_value, expected):
formatted = formatter(text_value)
assert formatted == expected

if six.PY2:
# Also check that Python 2 str value formats the same as the unicode value.
# (If a test case raises UnicodeEncodeError in here, it should be moved to
# the non_ascii verson of this test, below.)
py2_str_value = text_value.encode("ASCII")
py2_str_formatted = formatter(py2_str_value)
assert py2_str_formatted == expected


# When unicode snapshots are saved in Python 2, there's no easy way to generate
# a clean unicode_literals repr that doesn't use escape sequences. But the
# resulting snapshots are still valid on Python 3 (and vice versa).
@pytest.mark.parametrize(
"text_value, expected_py3, expected_py2",
"text_value, expected",
[
("encodage précis", "'encodage précis'", "'encodage pr\\xe9cis'"),
("精确的编码", "'精确的编码'", "'\\u7cbe\\u786e\\u7684\\u7f16\\u7801'"),
("encodage précis", "'encodage précis'"),
("精确的编码", "'精确的编码'"),
# backslash [unicode repr can't just be `"u'{}'".format(value)`]
("omvänt\\snedstreck", "'omvänt\\\\snedstreck'", "'omv\\xe4nt\\\\snedstreck'"),
("omvänt\\snedstreck", "'omvänt\\\\snedstreck'"),
# multiline
("ett\ntvå\n", "'''ett\ntvå\n'''", "'''ett\ntv\\xe5\n'''"),
("ett\ntvå\n", "'''ett\ntvå\n'''"),
],
)
def test_non_ascii_text_formatting(text_value, expected_py3, expected_py2):
expected = expected_py2 if six.PY2 else expected_py3
def test_non_ascii_text_formatting(text_value, expected):
formatter = Formatter()
formatted = formatter(text_value)
assert formatted == expected


if not six.PY2:
# https://github.com/syrusakbary/snapshottest/issues/115
def test_can_normalize_unittest_mock_call_object():
formatter = Formatter()
print(formatter.normalize(unittest.mock.call(1, 2, 3)))
# https://github.com/syrusakbary/snapshottest/issues/115
def test_can_normalize_unittest_mock_call_object():
formatter = Formatter()
print(formatter.normalize(unittest.mock.call(1, 2, 3)))


def test_can_normalize_iterator_objects():
formatter = Formatter()
print(formatter.normalize(x for x in range(3)))
def test_can_normalize_iterator_objects():
formatter = Formatter()
print(formatter.normalize(x for x in range(3)))


@pytest.mark.parametrize(
Expand Down
2 changes: 0 additions & 2 deletions tests/test_module.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

import pytest

from snapshottest import Snapshot
Expand Down
2 changes: 0 additions & 2 deletions tests/test_snapshot_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

import pytest
from collections import OrderedDict

Expand Down
1 change: 0 additions & 1 deletion tests/test_sorted_dict.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import enum

import pytest
Expand Down

0 comments on commit 2fdae37

Please sign in to comment.