Skip to content

Commit

Permalink
Drop code that explicitly supported python 2.
Browse files Browse the repository at this point in the history
Tested with `green green` with python 3.6 (some of the test code uses f-strings so we cannot test with python 3.5).
  • Loading branch information
sodul committed Apr 25, 2023
1 parent 9483a2e commit 5b3b4fb
Show file tree
Hide file tree
Showing 30 changed files with 20 additions and 158 deletions.
1 change: 0 additions & 1 deletion green/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import unicode_literals
from .version import __version__

__version__
2 changes: 0 additions & 2 deletions green/__main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

import sys

from .cmdline import main
Expand Down
1 change: 0 additions & 1 deletion green/cmdline.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import unicode_literals
import os
import sys
import tempfile
Expand Down
3 changes: 0 additions & 3 deletions green/command.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from __future__ import unicode_literals
from __future__ import print_function

import sys

try:
Expand Down
3 changes: 0 additions & 3 deletions green/config.py
Original file line number Diff line number Diff line change
@@ -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!

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

"""
To try running Django tests using green you can run:
Expand Down
1 change: 0 additions & 1 deletion green/examples.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import unicode_literals
import sys
import unittest

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


class InitializerOrFinalizerError(Exception):
pass
2 changes: 0 additions & 2 deletions green/junit.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from lxml.etree import Element, SubElement, tostring as to_xml


Expand Down
1 change: 0 additions & 1 deletion green/loader.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import unicode_literals
from collections import OrderedDict
from doctest import DocTestCase, DocTestSuite
from fnmatch import fnmatch
Expand Down
8 changes: 2 additions & 6 deletions green/output.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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):
Expand Down
32 changes: 2 additions & 30 deletions green/process.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import unicode_literals
import logging
import multiprocessing
from multiprocessing.pool import Pool, RUN, TERMINATE
Expand Down Expand Up @@ -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 "<MaybeEncodingError: %s>" % 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(
Expand Down Expand Up @@ -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

Expand Down
9 changes: 1 addition & 8 deletions green/result.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()

Expand Down
3 changes: 0 additions & 3 deletions green/runner.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 0 additions & 3 deletions green/suite.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 1 addition & 6 deletions green/test/test_cmdline.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import unicode_literals
from io import StringIO
import logging
import os
Expand All @@ -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):
Expand Down
7 changes: 1 addition & 6 deletions green/test/test_command.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 1 addition & 4 deletions green/test/test_config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
try:
import configparser
except:
import ConfigParser as configparser
import configparser
import copy
from io import StringIO
import os
Expand Down
7 changes: 1 addition & 6 deletions green/test/test_djangorunner.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 1 addition & 5 deletions green/test/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 0 additions & 2 deletions green/test/test_junit.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 1 addition & 7 deletions green/test/test_load_tests.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 1 addition & 6 deletions green/test/test_loader.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import unicode_literals
import os
from os.path import dirname
import platform
Expand All @@ -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
Expand Down
8 changes: 1 addition & 7 deletions green/test/test_output.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 2 additions & 9 deletions green/test/test_process.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
7 changes: 1 addition & 6 deletions green/test/test_result.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# encoding: utf-8
from __future__ import unicode_literals
import copy

# `from doctest import DocTestCase` causes crashes, since the DocTestCase is
Expand All @@ -11,6 +10,7 @@
import sys
import os
import unittest
from unittest.mock import MagicMock, patch
import tempfile

from green.config import default_args
Expand All @@ -24,11 +24,6 @@
BaseTestResult,
)

try:
from unittest.mock import MagicMock, patch
except ImportError:
from mock import MagicMock, patch

from coverage import coverage, CoverageException


Expand Down
7 changes: 1 addition & 6 deletions green/test/test_runner.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import unicode_literals
import copy
from io import StringIO
import os
Expand All @@ -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
Expand All @@ -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
Expand Down
Loading

0 comments on commit 5b3b4fb

Please sign in to comment.