Repository: syrusakbary/snapshottest

Issue:
Require Python 3
Since Python 2 has been deprecated, I suggest we drop support for it the next major release. Many libraries, including developer tools, have done so… pip, pytest, etc.

IMO it is not worth spending the limited volunteer development efforts we have to keep this working on an obsolete platform.

Discussion:

Patch:
diff --git a/.travis.yml b/.travis.yml
index 9494339..578c891 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,8 +1,6 @@
 language: python
 sudo: false
 python:
-- 2.7
-- 3.4
 - 3.5
 - 3.6
 - 3.7
diff --git a/setup.py b/setup.py
index 1229d68..a18b9b0 100644
--- a/setup.py
+++ b/setup.py
@@ -5,7 +5,7 @@ from setuptools import setup, find_packages
 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",
@@ -23,7 +23,7 @@ setup(
         ],
         "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,
@@ -34,21 +34,16 @@ setup(
             "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",
     ],
     license="MIT",
     packages=find_packages(exclude=("tests",)),


Test patch:
diff --git a/snapshottest/django.py b/snapshottest/django.py
index 298fd5f..9d20b9c 100644
--- a/snapshottest/django.py
+++ b/snapshottest/django.py
@@ -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
diff --git a/snapshottest/error.py b/snapshottest/error.py
index 5cd1fd7..da0ff8a 100644
--- a/snapshottest/error.py
+++ b/snapshottest/error.py
@@ -1,6 +1,3 @@
-from __future__ import unicode_literals
-
-
 class SnapshotError(Exception):
     pass
 
diff --git a/snapshottest/formatters.py b/snapshottest/formatters.py
index 089209f..39a0644 100644
--- a/snapshottest/formatters.py
+++ b/snapshottest/formatters.py
@@ -1,5 +1,4 @@
 import math
-import six
 from collections import defaultdict
 
 from .sorted_dict import SortedDict
@@ -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(),
diff --git a/snapshottest/nose.py b/snapshottest/nose.py
index 371734d..9d0e6b4 100644
--- a/snapshottest/nose.py
+++ b/snapshottest/nose.py
@@ -1,4 +1,3 @@
-from __future__ import absolute_import
 import logging
 import os
 
diff --git a/snapshottest/pytest.py b/snapshottest/pytest.py
index 2d40ca6..5b28898 100644
--- a/snapshottest/pytest.py
+++ b/snapshottest/pytest.py
@@ -1,4 +1,3 @@
-from __future__ import absolute_import
 import pytest
 import re
 
diff --git a/snapshottest/unittest.py b/snapshottest/unittest.py
index b68fce7..535b24a 100644
--- a/snapshottest/unittest.py
+++ b/snapshottest/unittest.py
@@ -1,4 +1,3 @@
-from __future__ import absolute_import
 import unittest
 import inspect
 
diff --git a/tests/test_formatter.py b/tests/test_formatter.py
index 8c53056..2b43f0a 100644
--- a/tests/test_formatter.py
+++ b/tests/test_formatter.py
@@ -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(
@@ -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(
diff --git a/tests/test_module.py b/tests/test_module.py
index cef2207..5ad2758 100644
--- a/tests/test_module.py
+++ b/tests/test_module.py
@@ -1,5 +1,3 @@
-from __future__ import unicode_literals
-
 import pytest
 
 from snapshottest import Snapshot
diff --git a/tests/test_snapshot_test.py b/tests/test_snapshot_test.py
index 9249478..9084f87 100644
--- a/tests/test_snapshot_test.py
+++ b/tests/test_snapshot_test.py
@@ -1,5 +1,3 @@
-from __future__ import unicode_literals
-
 import pytest
 from collections import OrderedDict
 
diff --git a/tests/test_sorted_dict.py b/tests/test_sorted_dict.py
index b8217d8..41ff194 100644
--- a/tests/test_sorted_dict.py
+++ b/tests/test_sorted_dict.py
@@ -1,5 +1,4 @@
 # -*- coding: utf-8 -*-
-from __future__ import unicode_literals
 import enum
 
 import pytest