Skip to content

Commit

Permalink
Merge pull request #283 from clumio-oss/dead-code
Browse files Browse the repository at this point in the history
Cleanup dead code and fix some imports.
  • Loading branch information
sodul authored Jan 25, 2024
2 parents 042e32e + 83eb87d commit d1e1bf5
Show file tree
Hide file tree
Showing 14 changed files with 14 additions and 74 deletions.
2 changes: 1 addition & 1 deletion green/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ def parseArguments(argv=None): # pragma: no cover
),
default=argparse.SUPPRESS,
)
),
)
store_opt(
cov_args.add_argument(
"-R",
Expand Down
2 changes: 1 addition & 1 deletion green/junit.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from lxml.etree import Element, SubElement, tostring as to_xml
from lxml.etree import Element, tostring as to_xml


class JUnitDialect:
Expand Down
2 changes: 1 addition & 1 deletion green/loader.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections import OrderedDict
from doctest import DocTestCase, DocTestSuite
from doctest import DocTestSuite
from fnmatch import fnmatch
import functools
import glob
Expand Down
2 changes: 1 addition & 1 deletion green/output.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from colorama import init, deinit, Fore, Style
from colorama import Fore, Style
from colorama.ansi import Cursor
from colorama.initialise import wrap_stream
import logging
Expand Down
3 changes: 1 addition & 2 deletions green/process.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging
import multiprocessing
from multiprocessing.pool import Pool, RUN, TERMINATE
import platform
from multiprocessing.pool import Pool
import random
import sys
import tempfile
Expand Down
10 changes: 0 additions & 10 deletions green/result.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
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
from unittest.result import failfast
Expand Down Expand Up @@ -737,14 +735,6 @@ def printErrors(self):
if not self.args.no_tracebacks:
relevant_frames = []
for i, frame in enumerate(err.traceback_lines):
# Python2 tracebacks containing unicode need some special handling
# This doesn't always make it readable, but at least it doesn't
# crash
if sys.version_info[0] == 2: # pragma: no cover
try:
"".join([frame]) # intentionally trigger exceptions
except UnicodeDecodeError:
frame = frame.decode("utf-8")
debug(
"\n"
f"{'*' * 30}Frame {i}:{'*' * 30}\n" + self.colors.yellow(frame),
Expand Down
46 changes: 1 addition & 45 deletions green/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,46 +80,7 @@ def countTestCases(self):
cases += test.countTestCases()
return cases

def _handleClassSetUpPre38(self, test, result): # pragma: nocover
previousClass = getattr(result, "_previousTestClass", None)
currentClass = test.__class__
if currentClass == previousClass:
return
if result._moduleSetUpFailed:
return
if getattr(currentClass, "__unittest_skip__", False): # pragma: no cover
return

try:
currentClass._classSetupFailed = False
except TypeError: # pragma: no cover
# test may actually be a function
# so its class will be a builtin-type
pass

setUpClass = getattr(currentClass, "setUpClass", None)
if setUpClass is not None:
_call_if_exists(result, "_setupStdout")
try:
setUpClass()
# Upstream Python forgets to take SkipTest into account
except unittest.case.SkipTest as e:
currentClass.__unittest_skip__ = True
currentClass.__unittest_skip_why__ = str(e)
# -- END of fix
except Exception as e: # pragma: no cover
if isinstance(result, _DebugResult):
raise
currentClass._classSetupFailed = True
className = util.strclass(currentClass)
errorName = "setUpClass (%s)" % className
self._addClassOrModuleLevelException(result, e, errorName)
finally:
_call_if_exists(result, "_restoreStdout")

def _handleClassSetUpPost38(
self, test, result
): # pragma: no cover -- because it's just like *Pre38
def _handleClassSetUp(self, test, result):
previousClass = getattr(result, "_previousTestClass", None)
currentClass = test.__class__
if currentClass == previousClass:
Expand Down Expand Up @@ -164,11 +125,6 @@ def _handleClassSetUpPost38(
result, exc[1], "setUpClass", className, info=exc
)

if sys.version_info < (3, 8): # pragma: no cover
_handleClassSetUp = _handleClassSetUpPre38
else:
_handleClassSetUp = _handleClassSetUpPost38

def run(self, result):
"""
Emulate unittest's behavior, with Green-specific changes.
Expand Down
2 changes: 2 additions & 0 deletions green/test/test_command.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import argparse
import contextlib
import os
import sys
import unittest
from configparser import ConfigParser
from unittest.mock import patch, MagicMock, call

from setuptools.dist import Distribution
Expand Down
4 changes: 2 additions & 2 deletions green/test/test_junit.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from green.config import default_args
from green.output import GreenStream
from green.junit import JUnitXML, JUnitDialect, Verdict
from green.result import GreenTestResult, BaseTestResult, ProtoTest, proto_error
from green.result import GreenTestResult, ProtoTest, proto_error

from io import StringIO

from sys import exc_info

from unittest import TestCase

from xml.etree.ElementTree import fromstring as from_xml, tostring as to_xml
from xml.etree.ElementTree import fromstring as from_xml


def test(module, class_name, method_name):
Expand Down
3 changes: 1 addition & 2 deletions green/test/test_load_tests.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import os
from queue import Queue, Empty
from queue import Queue
import shutil
import tempfile
import unittest
import textwrap

from green.loader import GreenTestLoader
from green.process import poolRunner
from green import process


class TestLoadTests(unittest.TestCase):
Expand Down
7 changes: 1 addition & 6 deletions green/test/test_output.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from io import StringIO
import platform
import sys
import unittest
from unittest.mock import MagicMock, patch

Expand Down Expand Up @@ -100,11 +99,7 @@ def testBadStringType(self):
s = StringIO()
gs = GreenStream(s)
msg = "some string"
if sys.version_info[0] == 3: # pragma: no cover
bad_str = bytes(msg, "utf-8")
else: # pragma: no cover
bad_str = str(msg)
gs.write(bad_str)
gs.write(bytes(msg, "utf-8"))
self.assertEqual(s.getvalue(), msg)

def testDisableWindowsTrue(self):
Expand Down
1 change: 0 additions & 1 deletion green/test/test_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import doctest
from io import StringIO
import sys
import os
import unittest
from unittest.mock import MagicMock, patch
import tempfile
Expand Down
3 changes: 2 additions & 1 deletion green/test/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,12 +413,13 @@ def testPasses(self):

def test_run_coverage(self):
"""
Running coverage in process mode doesn't crash
Running coverage in process mode doesn't crash.
"""
try:
import coverage
except ImportError:
self.skipTest("Coverage needs to be installed for this test")
self.assertTrue(coverage.version_info)
sub_tmpdir = pathlib.Path(tempfile.mkdtemp(dir=self.tmpdir))
(sub_tmpdir / "__init__.py").write_text("\n", encoding="utf-8")
content = dedent(
Expand Down
1 change: 0 additions & 1 deletion green/test/test_version.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import unittest

from green.version import __version__, pretty_version
import green.version


class TestVersion(unittest.TestCase):
Expand Down

0 comments on commit d1e1bf5

Please sign in to comment.