Skip to content

Commit

Permalink
drop old style exception get, use str.format instead of +
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborbernat committed Sep 17, 2018
1 parent 8247a15 commit 1d977fa
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/tox/_pytestplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def getnext(self, cat):
def expect(self, cat, messagepattern="*", invert=False):
__tracebackhide__ = True
if not messagepattern.startswith("*"):
messagepattern = "*" + messagepattern
messagepattern = "*{}".format(messagepattern)
while self._index < len(self._calls):
try:
call = self.getnext(cat)
Expand Down
7 changes: 3 additions & 4 deletions src/tox/_quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,8 @@ def do_prompt(map_, key, text, default=None, validator=nonempty, modificator=Non
if validator:
try:
answer = validator(answer)
except ValidationError:
err = sys.exc_info()[1]
print("* " + str(err))
except ValidationError as exception:
print("* {}".format(exception))
continue
break
map_[key] = modificator(answer, map_.get(key)) if modificator else answer
Expand Down Expand Up @@ -272,7 +271,7 @@ def parse_args():
default=".",
help="Custom root directory to write config to. Defaults to current directory.",
)
parser.add_argument("--version", action="version", version="%(prog)s " + tox.__version__)
parser.add_argument("--version", action="version", version="%(prog)s {}".format(tox.__version__))
return parser.parse_args()


Expand Down
13 changes: 7 additions & 6 deletions src/tox/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ def postprocess(self, testenv_config, value):
name = "{}{}".format(option, name[len(option) :].strip())
# in case of a long option, we add an equal sign
for option in tox.PIP.INSTALL_LONG_OPTIONS_ARGUMENT:
if name.startswith(option + " "):
name_start = "{} ".format(option)
if name.startswith(name_start):
name = "{}={}".format(option, name[len(option) :].strip())
name = self._replace_forced_dep(name, config)
deps.append(DepConfig(name, ixserver))
Expand Down Expand Up @@ -279,7 +280,7 @@ def parse_cli(args, pm):


def feedback(msg, sysexit=False):
print("ERROR: " + msg, file=sys.stderr)
print("ERROR: {}".format(msg), file=sys.stderr)
if sysexit:
raise SystemExit(1)

Expand Down Expand Up @@ -1030,7 +1031,7 @@ def __init__(self, config, ini_path, ini_data): # noqa

# configure testenvs
for name in all_envs:
section = testenvprefix + name
section = "{}{}".format(testenvprefix, name)
factors = set(name.split("-"))
if (
section in self._cfg
Expand All @@ -1055,7 +1056,7 @@ def parse_build_isolation(self, config, reader):
name = config.isolated_build_env
if name not in config.envconfigs:
config.envconfigs[name] = self.make_envconfig(
name, testenvprefix + name, reader._subs, config
name, "{}{}".format(testenvprefix, name), reader._subs, config
)

def _make_thread_safe_path(self, config, attr, unique_id):
Expand Down Expand Up @@ -1103,7 +1104,7 @@ def make_envconfig(self, name, section, subs, config, replace=True):
atype = env_attr.type
try:
if atype in ("bool", "path", "string", "dict", "dict_setenv", "argv", "argvlist"):
meth = getattr(reader, "get" + atype)
meth = getattr(reader, "get{}".format(atype))
res = meth(env_attr.name, env_attr.default, replace=replace)
elif atype == "space-separated-list":
res = reader.getlist(env_attr.name, sep=" ")
Expand Down Expand Up @@ -1502,7 +1503,7 @@ def getargvlist(cls, reader, value, replace=True):
if not line:
continue
if line.endswith("\\"):
current_command += " " + line[:-1]
current_command += " {}".format(line[:-1])
continue
current_command += line

Expand Down
10 changes: 5 additions & 5 deletions src/tox/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def show_help_ini(config):
for env_attr in config._testenv_attr:
tw.line(
"{:<15} {:<8} default: {}".format(
env_attr.name, "<" + env_attr.type + ">", env_attr.default
env_attr.name, "<{}>".format(env_attr.type), env_attr.default
),
bold=True,
)
Expand Down Expand Up @@ -518,8 +518,8 @@ def developpkg(self, venv, setupdir):
try:
venv.developpkg(setupdir, action)
return True
except tox.exception.InvocationError:
venv.status = sys.exc_info()[1]
except tox.exception.InvocationError as exception:
venv.status = exception
return False

def installpkg(self, venv, path):
Expand All @@ -535,8 +535,8 @@ def installpkg(self, venv, path):
try:
venv.installpkg(path, action)
return True
except tox.exception.InvocationError:
venv.status = sys.exc_info()[1]
except tox.exception.InvocationError as exception:
venv.status = exception
return False

def subcommand_test(self):
Expand Down
4 changes: 2 additions & 2 deletions src/tox/venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ def update(self, action):
try:
self.hook.tox_testenv_create(action=action, venv=self)
self.just_created = True
except tox.exception.UnsupportedInterpreter:
return sys.exc_info()[1]
except tox.exception.UnsupportedInterpreter as exception:
return exception
try:
self.hook.tox_testenv_install_deps(action=action, venv=self)
except tox.exception.InvocationError as exception:
Expand Down
5 changes: 2 additions & 3 deletions tests/unit/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2041,9 +2041,8 @@ def test_passing_no_argument(self, newconfig):
args = ["--hashseed"]
try:
self._check_testenv(newconfig, "", args=args)
except SystemExit:
e = sys.exc_info()[1]
assert e.code == 2
except SystemExit as exception:
assert exception.code == 2
return
assert False # getting here means we failed the test.

Expand Down

0 comments on commit 1d977fa

Please sign in to comment.