Skip to content

Commit

Permalink
Merge pull request #1 from dvdn/patch-python3.11-support
Browse files Browse the repository at this point in the history
[BO-2512] Patch Python3 support
  • Loading branch information
pthegner authored Nov 15, 2023
2 parents 7c26ad1 + 065ca1c commit 40e48ff
Show file tree
Hide file tree
Showing 30 changed files with 183 additions and 191 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ build
.tox
.*.sw[nop]
cover
*.bak
2 changes: 1 addition & 1 deletion nose/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def __init__(self, method, test=None, arg=tuple(), descriptor=None):
self.descriptor = descriptor
if isfunction(method):
raise ValueError("Unbound methods must be wrapped using pyversion.unbound_method before passing to MethodTestCase")
self.cls = method.im_class
self.cls = method.__self__.__class__
self.inst = self.cls()
if self.test is None:
method_name = self.method.__name__
Expand Down
2 changes: 1 addition & 1 deletion nose/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def run(self):

ei_cmd = self.get_finalized_command("egg_info")
argv = ['nosetests', '--where', ei_cmd.egg_base]
for (option_name, cmd_name) in self.option_to_cmds.items():
for (option_name, cmd_name) in list(self.option_to_cmds.items()):
if option_name in option_blacklist:
continue
value = getattr(self, option_name)
Expand Down
36 changes: 18 additions & 18 deletions nose/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
import re
import sys
import ConfigParser
import configparser
from optparse import OptionParser
from nose.util import absdir, tolist
from nose.plugins.manager import NoPlugins
Expand Down Expand Up @@ -62,24 +62,24 @@ def _configTuples(self, cfg, filename):
def _readFromFilenames(self, filenames):
config = []
for filename in filenames:
cfg = ConfigParser.RawConfigParser()
cfg = configparser.RawConfigParser()
try:
cfg.read(filename)
except ConfigParser.Error, exc:
except configparser.Error as exc:
raise ConfigError("Error reading config file %r: %s" %
(filename, str(exc)))
config.extend(self._configTuples(cfg, filename))
return config

def _readFromFileObject(self, fh):
cfg = ConfigParser.RawConfigParser()
cfg = configparser.RawConfigParser()
try:
filename = fh.name
except AttributeError:
filename = '<???>'
try:
cfg.readfp(fh)
except ConfigParser.Error, exc:
except configparser.Error as exc:
raise ConfigError("Error reading config file %r: %s" %
(filename, str(exc)))
return self._configTuples(cfg, filename)
Expand All @@ -89,7 +89,7 @@ def _readConfiguration(self, config_files):
config_files.readline
except AttributeError:
filename_or_filenames = config_files
if isinstance(filename_or_filenames, basestring):
if isinstance(filename_or_filenames, str):
filenames = [filename_or_filenames]
else:
filenames = filename_or_filenames
Expand All @@ -113,12 +113,12 @@ def _applyConfigurationToValues(self, parser, config, values):
continue
try:
self._processConfigValue(name, value, values, parser)
except NoSuchOptionError, exc:
except NoSuchOptionError as exc:
self._file_error(
"Error reading config file %r: "
"no such option %r" % (filename, exc.name),
name=name, filename=filename)
except optparse.OptionValueError, exc:
except optparse.OptionValueError as exc:
msg = str(exc).replace('--' + name, repr(name), 1)
self._file_error("Error reading config file %r: "
"%s" % (filename, msg),
Expand All @@ -128,12 +128,12 @@ def parseArgsAndConfigFiles(self, args, config_files):
values = self._parser.get_default_values()
try:
config = self._readConfiguration(config_files)
except ConfigError, exc:
except ConfigError as exc:
self._error(str(exc))
else:
try:
self._applyConfigurationToValues(self._parser, config, values)
except ConfigError, exc:
except ConfigError as exc:
self._error(str(exc))
return self._parser.parse_args(args, values)

Expand Down Expand Up @@ -194,7 +194,7 @@ def __init__(self, **kw):
r'^_',
r'^setup\.py$',
]
self.ignoreFiles = map(re.compile, self.ignoreFilesDefaultStrings)
self.ignoreFiles = list(map(re.compile, self.ignoreFilesDefaultStrings))
self.include = None
self.loggingConfig = None
self.logStream = sys.stderr
Expand Down Expand Up @@ -246,7 +246,7 @@ def __repr__(self):
d = self.__dict__.copy()
# don't expose env, could include sensitive info
d['env'] = {}
keys = [ k for k in d.keys()
keys = [ k for k in list(d.keys())
if not k.startswith('_') ]
keys.sort()
return "Config(%s)" % ', '.join([ '%s=%r' % (k, d[k])
Expand Down Expand Up @@ -327,17 +327,17 @@ def configure(self, argv=None, doc=None):
self.testMatch = re.compile(options.testMatch)

if options.ignoreFiles:
self.ignoreFiles = map(re.compile, tolist(options.ignoreFiles))
self.ignoreFiles = list(map(re.compile, tolist(options.ignoreFiles)))
log.info("Ignoring files matching %s", options.ignoreFiles)
else:
log.info("Ignoring files matching %s", self.ignoreFilesDefaultStrings)

if options.include:
self.include = map(re.compile, tolist(options.include))
self.include = list(map(re.compile, tolist(options.include)))
log.info("Including tests matching %s", options.include)

if options.exclude:
self.exclude = map(re.compile, tolist(options.exclude))
self.exclude = list(map(re.compile, tolist(options.exclude)))
log.info("Excluding tests matching %s", options.exclude)

# When listing plugins we don't want to run them
Expand Down Expand Up @@ -622,15 +622,15 @@ def __setstate__(self, state):
def __getnewargs__(self):
return ()

def __nonzero__(self):
def __bool__(self):
return False


def user_config_files():
"""Return path to any existing user config files
"""
return filter(os.path.exists,
map(os.path.expanduser, config_files))
return list(filter(os.path.exists,
list(map(os.path.expanduser, config_files))))


def all_config_files():
Expand Down
24 changes: 12 additions & 12 deletions nose/core.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Implements nose test program and collector.
"""
from __future__ import generators


import logging
import os
Expand Down Expand Up @@ -150,7 +150,7 @@ def parseArgs(self, argv):
if self.config.options.version:
from nose import __version__
sys.stdout = sys.__stdout__
print "%s version %s" % (os.path.basename(sys.argv[0]), __version__)
print(("%s version %s" % (os.path.basename(sys.argv[0]), __version__)))
sys.exit(0)

if self.config.options.showPlugins:
Expand Down Expand Up @@ -224,26 +224,26 @@ def add_option(self, *arg, **kw):
v = self.config.verbosity
self.config.plugins.sort()
for p in self.config.plugins:
print "Plugin %s" % p.name
print(("Plugin %s" % p.name))
if v >= 2:
print " score: %s" % p.score
print '\n'.join(textwrap.wrap(p.help().strip(),
print((" score: %s" % p.score))
print(('\n'.join(textwrap.wrap(p.help().strip(),
initial_indent=' ',
subsequent_indent=' '))
subsequent_indent=' '))))
if v >= 3:
parser = DummyParser()
p.addOptions(parser)
if len(parser.options):
print
print " Options:"
print()
print(" Options:")
for opts, help in parser.options:
print ' %s' % (', '.join(opts))
print((' %s' % (', '.join(opts))))
if help:
print '\n'.join(
print(('\n'.join(
textwrap.wrap(help.strip(),
initial_indent=' ',
subsequent_indent=' '))
print
subsequent_indent=' '))))
print()

def usage(cls):
import nose
Expand Down
Loading

0 comments on commit 40e48ff

Please sign in to comment.