diff --git a/green/__init__.py b/green/__init__.py index bebb0d8..f27e890 100644 --- a/green/__init__.py +++ b/green/__init__.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals from .version import __version__ __version__ diff --git a/green/__main__.py b/green/__main__.py index 9e7321c..989a60a 100644 --- a/green/__main__.py +++ b/green/__main__.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import - import sys from .cmdline import main diff --git a/green/cmdline.py b/green/cmdline.py index 5c0b11a..5988674 100644 --- a/green/cmdline.py +++ b/green/cmdline.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals import os import sys import tempfile diff --git a/green/command.py b/green/command.py index 95c3311..b3f77ce 100644 --- a/green/command.py +++ b/green/command.py @@ -1,6 +1,3 @@ -from __future__ import unicode_literals -from __future__ import print_function - import sys try: diff --git a/green/config.py b/green/config.py index edb2cff..813b05c 100644 --- a/green/config.py +++ b/green/config.py @@ -1,6 +1,3 @@ -from __future__ import unicode_literals # pragma: no cover -from __future__ import print_function # pragma: no cover - # We have to use this entire file before we can turn coverage on, so we exclude # it from coverage. We still have tests, though! diff --git a/green/djangorunner.py b/green/djangorunner.py index 9c5a486..8cbc3ff 100644 --- a/green/djangorunner.py +++ b/green/djangorunner.py @@ -1,5 +1,3 @@ -from __future__ import unicode_literals - """ To try running Django tests using green you can run: diff --git a/green/examples.py b/green/examples.py index 3bc0a3f..6010e08 100644 --- a/green/examples.py +++ b/green/examples.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals import sys import unittest diff --git a/green/exceptions.py b/green/exceptions.py index 4e3c137..c05dcd5 100644 --- a/green/exceptions.py +++ b/green/exceptions.py @@ -1,5 +1,2 @@ -from __future__ import unicode_literals - - class InitializerOrFinalizerError(Exception): pass diff --git a/green/junit.py b/green/junit.py index 1313dcd..b343056 100644 --- a/green/junit.py +++ b/green/junit.py @@ -1,5 +1,3 @@ -from __future__ import unicode_literals - from lxml.etree import Element, SubElement, tostring as to_xml diff --git a/green/loader.py b/green/loader.py index b57166c..8109bb8 100644 --- a/green/loader.py +++ b/green/loader.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals from collections import OrderedDict from doctest import DocTestCase, DocTestSuite from fnmatch import fnmatch diff --git a/green/output.py b/green/output.py index cfbebba..2fe859d 100644 --- a/green/output.py +++ b/green/output.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals from colorama import init, deinit, Fore, Style from colorama.ansi import Cursor from colorama.initialise import wrap_stream @@ -12,11 +11,8 @@ global debug_level debug_level = 0 -if sys.version_info[0] == 3: # pragma: no cover - text_type = str - unicode = None # so pyflakes stops complaining -else: # pragma: no cover - text_type = unicode +text_type = str +unicode = None # so pyflakes stops complaining def debug(message, level=1): diff --git a/green/process.py b/green/process.py index dce5882..339be4d 100644 --- a/green/process.py +++ b/green/process.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals import logging import multiprocessing from multiprocessing.pool import Pool, RUN, TERMINATE @@ -219,36 +218,9 @@ def _repopulate_pool_static( if tuple(map(int, platform.python_version_tuple()[:2])) < (3, 8): # pragma: no cover LoggingDaemonlessPool = LoggingDaemonlessPool37 -import platform import multiprocessing.pool from multiprocessing import util - -try: - from multiprocessing.pool import MaybeEncodingError -except: # pragma: no cover - # Python 2.7.4 introduced this class. If we're on Python 2.7.0 to 2.7.3 - # then we'll have to define it ourselves. :-/ - class MaybeEncodingError(Exception): - """Wraps possible unpickleable errors, so they can be - safely sent through the socket.""" - - def __init__(self, exc, value): - self.exc = repr(exc) - self.value = repr(value) - super(MaybeEncodingError, self).__init__(self.exc, self.value) - - def __str__(self): - return "Error sending result: '%s'. Reason: '%s'" % (self.value, self.exc) - - def __repr__(self): - return "" % str(self) - - -# Python 2 and 3 raise a different error when they exit -if platform.python_version_tuple()[0] == "2": # pragma: no cover - PortableOSError = IOError -else: # pragma: no cover - PortableOSError = OSError +from multiprocessing.pool import MaybeEncodingError def worker( @@ -278,7 +250,7 @@ def worker( while maxtasks is None or (maxtasks and completed < maxtasks): try: task = get() - except (EOFError, PortableOSError): + except (EOFError, OSError): util.debug("worker got EOFError or OSError -- exiting") break diff --git a/green/result.py b/green/result.py index 457504c..ebac51a 100644 --- a/green/result.py +++ b/green/result.py @@ -1,10 +1,8 @@ -from __future__ import unicode_literals -from __future__ import print_function - from collections import OrderedDict from doctest import DocTestCase from io import StringIO from math import ceil +from shutil import get_terminal_size import sys import time import traceback @@ -14,11 +12,6 @@ from green.output import Colors, debug from green.version import pretty_version -# introduced in Python 3 -try: - from shutil import get_terminal_size -except ImportError: # pragma: no cover - from backports.shutil_get_terminal_size import get_terminal_size terminal_width, _ignored = get_terminal_size() diff --git a/green/runner.py b/green/runner.py index 841052c..0302682 100644 --- a/green/runner.py +++ b/green/runner.py @@ -1,6 +1,3 @@ -from __future__ import unicode_literals -from __future__ import print_function - import multiprocessing from sys import modules from unittest.signals import registerResult, installHandler, removeResult diff --git a/green/suite.py b/green/suite.py index e62678a..715ee53 100644 --- a/green/suite.py +++ b/green/suite.py @@ -1,6 +1,3 @@ -from __future__ import unicode_literals -from __future__ import print_function - from fnmatch import fnmatch import sys from unittest.suite import _call_if_exists, _DebugResult, _isnotsuite, TestSuite diff --git a/green/test/test_cmdline.py b/green/test/test_cmdline.py index 3d26baa..95f0573 100644 --- a/green/test/test_cmdline.py +++ b/green/test/test_cmdline.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals from io import StringIO import logging import os @@ -7,16 +6,12 @@ import sys import tempfile import unittest +from unittest.mock import MagicMock from green import cmdline from green import config from green.output import GreenStream -try: - from unittest.mock import MagicMock -except: - from mock import MagicMock - class TestMain(unittest.TestCase): def setUp(self): diff --git a/green/test/test_command.py b/green/test/test_command.py index 168ca61..7603ec4 100644 --- a/green/test/test_command.py +++ b/green/test/test_command.py @@ -1,19 +1,14 @@ -from __future__ import unicode_literals - import argparse import contextlib import sys import unittest +from unittest.mock import patch, MagicMock, call try: from setuptools.dist import Distribution except ImportError: from distutil.dist import Distribution -try: - from mock import patch, MagicMock, call -except: - from unittest.mock import patch, MagicMock, call from green import command from green.config import StoreOpt diff --git a/green/test/test_config.py b/green/test/test_config.py index f9304b9..cedb1ff 100644 --- a/green/test/test_config.py +++ b/green/test/test_config.py @@ -1,7 +1,4 @@ -try: - import configparser -except: - import ConfigParser as configparser +import configparser import copy from io import StringIO import os diff --git a/green/test/test_djangorunner.py b/green/test/test_djangorunner.py index 1c53396..2dea361 100644 --- a/green/test/test_djangorunner.py +++ b/green/test/test_djangorunner.py @@ -1,14 +1,9 @@ -from __future__ import unicode_literals from argparse import Namespace from argparse import ArgumentParser from io import StringIO import sys import unittest - -try: - from unittest.mock import MagicMock, patch -except: - from mock import MagicMock, patch +from unittest.mock import MagicMock, patch from green import djangorunner from green.config import mergeConfig diff --git a/green/test/test_integration.py b/green/test/test_integration.py index 0cf8cbb..a643865 100644 --- a/green/test/test_integration.py +++ b/green/test/test_integration.py @@ -7,11 +7,7 @@ import tempfile from textwrap import dedent import unittest - -try: - from unittest.mock import MagicMock -except: - from mock import MagicMock +from unittest.mock import MagicMock from green import cmdline diff --git a/green/test/test_junit.py b/green/test/test_junit.py index 6abf543..d9cfd4f 100644 --- a/green/test/test_junit.py +++ b/green/test/test_junit.py @@ -1,5 +1,3 @@ -from __future__ import unicode_literals - from green.config import default_args from green.output import GreenStream from green.junit import JUnitXML, JUnitDialect, Verdict diff --git a/green/test/test_load_tests.py b/green/test/test_load_tests.py index 719ff08..dececba 100644 --- a/green/test/test_load_tests.py +++ b/green/test/test_load_tests.py @@ -1,16 +1,10 @@ -from __future__ import unicode_literals - import os +from queue import Queue, Empty import shutil import tempfile import unittest import textwrap -try: - from Queue import Queue, Empty -except ImportError: - from queue import Queue, Empty - from green.loader import GreenTestLoader from green.process import poolRunner from green import process diff --git a/green/test/test_loader.py b/green/test/test_loader.py index 52fbd98..c13d25a 100644 --- a/green/test/test_loader.py +++ b/green/test/test_loader.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals import os from os.path import dirname import platform @@ -7,11 +6,7 @@ import tempfile from textwrap import dedent import unittest - -try: - from unittest.mock import MagicMock, patch -except: - from mock import MagicMock, patch +from unittest.mock import MagicMock, patch from green import loader from green.loader import GreenTestLoader, flattenTestSuite diff --git a/green/test/test_output.py b/green/test/test_output.py index 1db53fa..5d7d17d 100644 --- a/green/test/test_output.py +++ b/green/test/test_output.py @@ -1,14 +1,8 @@ -from __future__ import unicode_literals from io import StringIO import platform import sys import unittest - - -try: - from unittest.mock import MagicMock, patch -except: - from mock import MagicMock, patch +from unittest.mock import MagicMock, patch from green.output import Colors, GreenStream, debug import green.output diff --git a/green/test/test_process.py b/green/test/test_process.py index 15b162e..cfb3641 100644 --- a/green/test/test_process.py +++ b/green/test/test_process.py @@ -1,23 +1,16 @@ from ctypes import c_double import os import multiprocessing +from queue import Queue, Empty import shutil import tempfile from textwrap import dedent import unittest - -try: - from unittest.mock import MagicMock -except: - from mock import MagicMock +from unittest.mock import MagicMock from green.process import ProcessLogger, poolRunner from green import process -try: - from Queue import Queue, Empty -except: - from queue import Queue, Empty class TestProcessLogger(unittest.TestCase): diff --git a/green/test/test_result.py b/green/test/test_result.py index 6d896a2..04bcf2d 100644 --- a/green/test/test_result.py +++ b/green/test/test_result.py @@ -1,5 +1,4 @@ # encoding: utf-8 -from __future__ import unicode_literals import copy # `from doctest import DocTestCase` causes crashes, since the DocTestCase is @@ -11,6 +10,7 @@ import sys import os import unittest +from unittest.mock import MagicMock, patch import tempfile from green.config import default_args @@ -24,11 +24,6 @@ BaseTestResult, ) -try: - from unittest.mock import MagicMock, patch -except ImportError: - from mock import MagicMock, patch - from coverage import coverage, CoverageException diff --git a/green/test/test_runner.py b/green/test/test_runner.py index 026d6e2..6a150d6 100644 --- a/green/test/test_runner.py +++ b/green/test/test_runner.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals import copy from io import StringIO import os @@ -9,6 +8,7 @@ import tempfile from textwrap import dedent import unittest +from unittest.mock import MagicMock import weakref from green.config import default_args @@ -18,11 +18,6 @@ from green.runner import InitializerOrFinalizer, run from green.suite import GreenTestSuite -try: - from unittest.mock import MagicMock -except: - from mock import MagicMock - global skip_testtools skip_testtools = False diff --git a/green/test/test_suite.py b/green/test/test_suite.py index cec41c2..a853ba3 100644 --- a/green/test/test_suite.py +++ b/green/test/test_suite.py @@ -1,18 +1,10 @@ -from __future__ import unicode_literals -from __future__ import print_function - import copy from io import StringIO import os import tempfile from textwrap import dedent import unittest - - -try: - from unittest.mock import MagicMock -except: - from mock import MagicMock +from unittest.mock import MagicMock from green.config import default_args from green.loader import GreenTestLoader diff --git a/green/test/test_version.py b/green/test/test_version.py index 9a1547e..e4a3cf2 100644 --- a/green/test/test_version.py +++ b/green/test/test_version.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals import unittest from green.version import __version__, pretty_version diff --git a/green/version.py b/green/version.py index 7120860..33511e1 100644 --- a/green/version.py +++ b/green/version.py @@ -1,17 +1,10 @@ -from __future__ import unicode_literals # pragma: no cover -import os.path # pragma nocover +import pathlib # pragma nocover import sys # pragma nocover import coverage # pragma: no cover -with open( - os.path.join(os.path.dirname(__file__), "VERSION") -) as vfile: # pragma nocover - __version__ = vfile.read().strip() -if sys.version_info[0] == 2: # pragma nocover - from __builtin__ import unicode # just so the linter stops complaining - __version__ = unicode(__version__) +__version__ = (pathlib.Path(__file__).parent / "VERSION").read_text(encoding='utf-8').strip() def pretty_version(): # pragma nocover