1 new commit in tox: https://bitbucket.org/hpk42/tox/commits/37151bb27e53/ Changeset: 37151bb27e53 User: Vladimir Vitvitskiy Date: 2015-04-22 21:18:46+00:00 Summary: fix PEP8 violations
* tox.ini updated to run PEP8 checks along with flakes * added dev test environment to run any command in it or looponfail tests * fixed all PEP8 violations pytest-pep8 complained about * line width set to 99 Affected #: 16 files diff -r d3b25d3d9d603ac562030d12e18216f3b6268fd2 -r 37151bb27e530549ef2a17d3920f2bfea2421a87 tests/test_config.py --- a/tests/test_config.py +++ b/tests/test_config.py @@ -65,8 +65,8 @@ def test_force_dep_version(self, initproj): """ - Make sure we can override dependencies configured in tox.ini when using the command line option - --force-dep. + Make sure we can override dependencies configured in tox.ini when using the command line + option --force-dep. """ initproj("example123-0.5", filedefs={ 'tox.ini': ''' @@ -83,7 +83,7 @@ config = parseconfig( ['--force-dep=dep1==1.5', '--force-dep=dep2==2.1', '--force-dep=dep3==3.0']) - assert config.option.force_dep== [ + assert config.option.force_dep == [ 'dep1==1.5', 'dep2==2.1', 'dep3==3.0'] assert [str(x) for x in config.envconfigs['python'].deps] == [ 'dep1==1.5', 'dep2==2.1', 'dep3==3.0', 'dep4==4.0', @@ -126,7 +126,6 @@ monkeypatch.undo() assert not venv.matching_platform() - @pytest.mark.parametrize("plat", ["win", "lin", ]) def test_config_parse_platform_with_factors(self, newconfig, plat, monkeypatch): monkeypatch.setattr(sys, "platform", "win32") @@ -171,6 +170,7 @@ """ % tmpdir) assert config.toxworkdir == tmpdir + class TestParseconfig: def test_search_parents(self, tmpdir): b = tmpdir.mkdir("a").mkdir("b") @@ -182,12 +182,13 @@ old.chdir() assert config.toxinipath == toxinipath + def test_get_homedir(monkeypatch): monkeypatch.setattr(py.path.local, "_gethomedir", classmethod(lambda x: {}[1])) assert not get_homedir() monkeypatch.setattr(py.path.local, "_gethomedir", - classmethod(lambda x: 0/0)) + classmethod(lambda x: 0 / 0)) assert not get_homedir() monkeypatch.setattr(py.path.local, "_gethomedir", classmethod(lambda x: "123")) @@ -224,7 +225,8 @@ assert x == [["echo", "whatever"]] def test_command_substitution_from_other_section_multiline(self, newconfig): - """Ensure referenced multiline commands form from other section injected as multiple commands.""" + """Ensure referenced multiline commands form from other section injected + as multiple commands.""" config = newconfig(""" [section] commands = @@ -275,7 +277,7 @@ reader = IniReader(config._cfg, fallbacksections=['mydefault']) assert reader is not None py.test.raises(tox.exception.ConfigError, - 'reader.getdefault("mydefault", "key2")') + 'reader.getdefault("mydefault", "key2")') def test_getdefault_fallback_sections(self, tmpdir, newconfig): config = newconfig(""" @@ -346,7 +348,7 @@ x = reader.getdefault("section", "key1") assert x == "hello" py.test.raises(tox.exception.ConfigError, - 'reader.getdefault("section", "key2")') + 'reader.getdefault("section", "key2")') def test_getdefault_environment_substitution_with_default(self, monkeypatch, newconfig): monkeypatch.setenv("KEY1", "hello") @@ -392,7 +394,7 @@ """) reader = IniReader(config._cfg) reader.addsubstitutions(item1="with space", item2="grr") - #py.test.raises(tox.exception.ConfigError, + # py.test.raises(tox.exception.ConfigError, # "reader.getargvlist('section', 'key1')") assert reader.getargvlist('section', 'key1') == [] x = reader.getargvlist("section", "key2") @@ -418,7 +420,7 @@ """) reader = IniReader(config._cfg) reader.addsubstitutions(item1="with space", item2="grr") - #py.test.raises(tox.exception.ConfigError, + # py.test.raises(tox.exception.ConfigError, # "reader.getargvlist('section', 'key1')") assert reader.getargvlist('section', 'key1') == [] x = reader.getargvlist("section", "key2") @@ -446,7 +448,7 @@ reader = IniReader(config._cfg) posargs = ['hello', 'world'] reader.addsubstitutions(posargs, item2="value2") - #py.test.raises(tox.exception.ConfigError, + # py.test.raises(tox.exception.ConfigError, # "reader.getargvlist('section', 'key1')") assert reader.getargvlist('section', 'key1') == [] argvlist = reader.getargvlist("section", "key2") @@ -455,7 +457,7 @@ reader = IniReader(config._cfg) reader.addsubstitutions([], item2="value2") - #py.test.raises(tox.exception.ConfigError, + # py.test.raises(tox.exception.ConfigError, # "reader.getargvlist('section', 'key1')") assert reader.getargvlist('section', 'key1') == [] argvlist = reader.getargvlist("section", "key2") @@ -490,8 +492,7 @@ x = reader.getargvlist("section", "key2") assert x == [["cmd1", "-f", "foo", "bar baz"]] - def test_positional_arguments_are_only_replaced_when_standing_alone(self, - tmpdir, newconfig): + def test_positional_arguments_are_only_replaced_when_standing_alone(self, tmpdir, newconfig): config = newconfig(""" [section] key= @@ -520,7 +521,9 @@ posargs = ['hello', 'world'] reader.addsubstitutions(posargs, envlogdir='ENV_LOG_DIR', envname='ENV_NAME') - expected = ['py.test', '-n5', '--junitxml=ENV_LOG_DIR/junit-ENV_NAME.xml', 'hello', 'world'] + expected = [ + 'py.test', '-n5', '--junitxml=ENV_LOG_DIR/junit-ENV_NAME.xml', 'hello', 'world' + ] assert reader.getargvlist('section', 'key')[0] == expected def test_getargv(self, newconfig): @@ -582,8 +585,8 @@ envconfig = config.envconfigs['python'] assert envconfig.commands == [["xyz", "--abc"]] assert envconfig.changedir == config.setupdir - assert envconfig.sitepackages == False - assert envconfig.develop == False + assert envconfig.sitepackages is False + assert envconfig.develop is False assert envconfig.envlogdir == envconfig.envdir.join("log") assert list(envconfig.setenv.keys()) == ['PYTHONHASHSEED'] hashseed = envconfig.setenv['PYTHONHASHSEED'] @@ -596,7 +599,7 @@ def test_sitepackages_switch(self, tmpdir, newconfig): config = newconfig(["--sitepackages"], "") envconfig = config.envconfigs['python'] - assert envconfig.sitepackages == True + assert envconfig.sitepackages is True def test_installpkg_tops_develop(self, newconfig): config = newconfig(["--installpkg=abc"], """ @@ -918,7 +921,7 @@ assert argv[0] == ["cmd1", "hello"] def test_take_dependencies_from_other_testenv(self, newconfig): - inisource=""" + inisource = """ [testenv] deps= pytest @@ -933,7 +936,7 @@ assert packages == ['pytest', 'pytest-cov', 'fun'] def test_take_dependencies_from_other_section(self, newconfig): - inisource=""" + inisource = """ [testing:pytest] deps= pytest @@ -953,7 +956,7 @@ assert packages == ['pytest', 'pytest-cov', 'mock', 'fun'] def test_multilevel_substitution(self, newconfig): - inisource=""" + inisource = """ [testing:pytest] deps= pytest @@ -978,7 +981,7 @@ assert packages == ['pytest', 'pytest-cov', 'mock', 'fun'] def test_recursive_substitution_cycle_fails(self, newconfig): - inisource=""" + inisource = """ [testing:pytest] deps= {[testing:mock]deps} @@ -1004,7 +1007,7 @@ assert conf.changedir.dirpath().realpath() == tmpdir.realpath() def test_factors(self, newconfig): - inisource=""" + inisource = """ [tox] envlist = a-x,b @@ -1022,7 +1025,7 @@ assert [dep.name for dep in configs['b'].deps] == ["dep-all", "dep-b"] def test_factor_ops(self, newconfig): - inisource=""" + inisource = """ [tox] envlist = {a,b}-{x,y} @@ -1040,7 +1043,7 @@ assert get_deps("b-y") == ["dep-a-or-b", "dep-ab-and-y"] def test_default_factors(self, newconfig): - inisource=""" + inisource = """ [tox] envlist = py{26,27,33,34}-dep @@ -1055,7 +1058,7 @@ @pytest.mark.issue188 def test_factors_in_boolean(self, newconfig): - inisource=""" + inisource = """ [tox] envlist = py{27,33} @@ -1069,7 +1072,7 @@ @pytest.mark.issue190 def test_factors_in_setenv(self, newconfig): - inisource=""" + inisource = """ [tox] envlist = py27,py26 @@ -1083,7 +1086,7 @@ @pytest.mark.issue191 def test_factor_use_not_checked(self, newconfig): - inisource=""" + inisource = """ [tox] envlist = py27-{a,b} @@ -1095,7 +1098,7 @@ @pytest.mark.issue198 def test_factors_groups_touch(self, newconfig): - inisource=""" + inisource = """ [tox] envlist = {a,b}{-x,} @@ -1107,7 +1110,7 @@ assert set(configs.keys()) == set(['a', 'a-x', 'b', 'b-x']) def test_period_in_factor(self, newconfig): - inisource=""" + inisource = """ [tox] envlist = py27-{django1.6,django1.7} @@ -1185,7 +1188,7 @@ [testenv:py27] basepython=python2.7 """ - #py.test.raises(tox.exception.ConfigError, + # py.test.raises(tox.exception.ConfigError, # "newconfig(['-exyz'], inisource)") config = newconfig([], inisource) assert config.envlist == ["py26"] @@ -1222,7 +1225,7 @@ assert env.basepython == name else: assert name.startswith("py") - bp = "python%s.%s" %(name[2], name[3]) + bp = "python%s.%s" % (name[2], name[3]) assert env.basepython == bp def test_envlist_expansion(self, newconfig): @@ -1284,6 +1287,7 @@ assert env.basepython == "python2.4" assert env.commands == [['xyz']] + class TestHashseedOption: def _get_envconfigs(self, newconfig, args=None, tox_ini=None, @@ -1331,7 +1335,7 @@ args = ['--hashseed', ''] self._check_testenv(newconfig, '', args=args) - @pytest.mark.xfail(sys.version_info >= (3,2), + @pytest.mark.xfail(sys.version_info >= (3, 2), reason="at least Debian python 3.2/3.3 have a bug: " "http://bugs.python.org/issue11884") def test_passing_no_argument(self, tmpdir, newconfig): @@ -1378,6 +1382,7 @@ """ next_seed = [1000] # This function is guaranteed to generate a different value each time. + def make_hashseed(): next_seed[0] += 1 return str(next_seed[0]) @@ -1401,6 +1406,7 @@ self._check_hashseed(envconfigs["hash1"], '2') self._check_hashseed(envconfigs["hash2"], '123456789') + class TestIndexServer: def test_indexserver(self, tmpdir, newconfig): config = newconfig(""" @@ -1409,7 +1415,7 @@ name1 = XYZ name2 = ABC """) - assert config.indexserver['default'].url == None + assert config.indexserver['default'].url is None assert config.indexserver['name1'].url == "XYZ" assert config.indexserver['name2'].url == "ABC" @@ -1423,10 +1429,10 @@ config = newconfig([], inisource) assert config.indexserver['default'].url == "http://pypi.testrun.org" assert config.indexserver['name1'].url == "whatever" - config = newconfig(['-i','qwe'], inisource) + config = newconfig(['-i', 'qwe'], inisource) assert config.indexserver['default'].url == "qwe" assert config.indexserver['name1'].url == "whatever" - config = newconfig(['-i','name1=abc', '-i','qwe2'], inisource) + config = newconfig(['-i', 'name1=abc', '-i', 'qwe2'], inisource) assert config.indexserver['default'].url == "qwe2" assert config.indexserver['name1'].url == "abc" @@ -1447,8 +1453,8 @@ config = newconfig([], inisource) expected = "file://%s/.pip/downloads/simple" % config.homedir assert config.indexserver['default'].url == expected - assert config.indexserver['local1'].url == \ - config.indexserver['default'].url + assert config.indexserver['local1'].url == config.indexserver['default'].url + class TestParseEnv: @@ -1467,6 +1473,7 @@ config = newconfig([], inisource) assert config.envconfigs['hello'].recreate + class TestCmdInvocation: def test_help(self, cmd): result = cmd.run("tox", "-h") @@ -1544,6 +1551,7 @@ r'*deps=*dep1, dep2==5.0*', ]) + class TestArgumentParser: def test_dash_e_single_1(self): @@ -1591,12 +1599,15 @@ assert list(p.words()) == ['{sub:something with spaces}'] def test_command_parser_with_complex_word_set(self): - complex_case = 'word [] [literal] {something} {some:other thing} w{ord} w{or}d w{ord} w{o:rd} w{o:r}d {w:or}d w[]ord {posargs:{a key}}' + complex_case = ( + 'word [] [literal] {something} {some:other thing} w{ord} w{or}d w{ord} ' + 'w{o:rd} w{o:r}d {w:or}d w[]ord {posargs:{a key}}') p = CommandParser(complex_case) parsed = list(p.words()) expected = [ 'word', ' ', '[]', ' ', '[literal]', ' ', '{something}', ' ', '{some:other thing}', - ' ', 'w', '{ord}', ' ', 'w', '{or}', 'd', ' ', 'w', '{ord}', ' ', 'w', '{o:rd}', ' ', 'w', '{o:r}', 'd', ' ', '{w:or}', 'd', + ' ', 'w', '{ord}', ' ', 'w', '{or}', 'd', ' ', 'w', '{ord}', ' ', 'w', '{o:rd}', ' ', + 'w', '{o:r}', 'd', ' ', '{w:or}', 'd', ' ', 'w[]ord', ' ', '{posargs:{a key}}', ] @@ -1619,7 +1630,10 @@ cmd = "nosetests -v -a !deferred --with-doctest []" p = CommandParser(cmd) parsed = list(p.words()) - assert parsed == ['nosetests', ' ', '-v', ' ', '-a', ' ', '!deferred', ' ', '--with-doctest', ' ', '[]'] + assert parsed == [ + 'nosetests', ' ', '-v', ' ', '-a', ' ', '!deferred', ' ', + '--with-doctest', ' ', '[]' + ] @pytest.mark.skipif("sys.platform != 'win32'") def test_commands_with_backslash(self, newconfig): diff -r d3b25d3d9d603ac562030d12e18216f3b6268fd2 -r 37151bb27e530549ef2a17d3920f2bfea2421a87 tests/test_interpreters.py --- a/tests/test_interpreters.py +++ b/tests/test_interpreters.py @@ -4,10 +4,12 @@ import pytest from tox.interpreters import * # noqa + @pytest.fixture def interpreters(): return Interpreters() + @pytest.mark.skipif("sys.platform != 'win32'") def test_locate_via_py(monkeypatch): class PseudoPy: @@ -16,6 +18,7 @@ assert args[1] == '-c' # Return value needs to actually exist! return sys.executable + @staticmethod def ret_pseudopy(name): assert name == 'py' @@ -24,6 +27,7 @@ monkeypatch.setattr(py.path.local, 'sysfind', ret_pseudopy) assert locate_via_py('3', '2') == sys.executable + def test_find_executable(): p = find_executable(sys.executable) assert p == py.path.local(sys.executable) @@ -41,10 +45,11 @@ p = find_executable(name) assert p popen = py.std.subprocess.Popen([str(p), '-V'], - stderr=py.std.subprocess.PIPE) + stderr=py.std.subprocess.PIPE) stdout, stderr = popen.communicate() assert ver in py.builtin._totext(stderr, "ascii") + def test_find_executable_extra(monkeypatch): @staticmethod def sysfind(x): @@ -53,6 +58,7 @@ t = find_executable("qweqwe") assert t == "hello" + def test_run_and_get_interpreter_info(): name = os.path.basename(sys.executable) info = run_and_get_interpreter_info(name, sys.executable) @@ -60,6 +66,7 @@ assert info.name == name assert info.executable == sys.executable + class TestInterpreters: def test_get_info_self_exceptions(self, interpreters): diff -r d3b25d3d9d603ac562030d12e18216f3b6268fd2 -r 37151bb27e530549ef2a17d3920f2bfea2421a87 tests/test_result.py --- a/tests/test_result.py +++ b/tests/test_result.py @@ -4,12 +4,14 @@ import tox import pytest + @pytest.fixture def pkg(tmpdir): p = tmpdir.join("hello-1.0.tar.gz") p.write("whatever") return p + def test_pre_set_header(pkg): replog = ResultLog() d = replog.dict @@ -22,6 +24,7 @@ replog2 = ResultLog.loads_json(data) assert replog2.dict == replog.dict + def test_set_header(pkg): replog = ResultLog() d = replog.dict @@ -31,13 +34,15 @@ assert replog.dict["toxversion"] == tox.__version__ assert replog.dict["platform"] == sys.platform assert replog.dict["host"] == py.std.socket.getfqdn() - assert replog.dict["installpkg"] == {"basename": "hello-1.0.tar.gz", - "md5": pkg.computehash("md5"), - "sha256": pkg.computehash("sha256")} + assert replog.dict["installpkg"] == { + "basename": "hello-1.0.tar.gz", + "md5": pkg.computehash("md5"), + "sha256": pkg.computehash("sha256")} data = replog.dumps_json() replog2 = ResultLog.loads_json(data) assert replog2.dict == replog.dict + def test_addenv_setpython(pkg): replog = ResultLog() replog.set_header(installpkg=pkg) @@ -47,6 +52,7 @@ assert envlog.dict["python"]["version"] == sys.version assert envlog.dict["python"]["executable"] == sys.executable + def test_get_commandlog(pkg): replog = ResultLog() replog.set_header(installpkg=pkg) @@ -60,4 +66,3 @@ assert envlog.dict["setup"] setuplog2 = replog.get_envlog("py26").get_commandlog("setup") assert setuplog2.list == setuplog.list - diff -r d3b25d3d9d603ac562030d12e18216f3b6268fd2 -r 37151bb27e530549ef2a17d3920f2bfea2421a87 tests/test_venv.py --- a/tests/test_venv.py +++ b/tests/test_venv.py @@ -1,12 +1,13 @@ import py import tox import pytest -import os, sys +import os +import sys import tox._config from tox._venv import * # noqa from tox.interpreters import NoInterpreterInfo -#def test_global_virtualenv(capfd): +# def test_global_virtualenv(capfd): # v = VirtualEnv() # l = v.list() # assert l @@ -14,8 +15,11 @@ # assert not out # assert not err # + + def test_getdigest(tmpdir): - assert getdigest(tmpdir) == "0"*32 + assert getdigest(tmpdir) == "0" * 32 + def test_getsupportedinterpreter(monkeypatch, newconfig, mocksession): config = newconfig([], """ @@ -25,8 +29,7 @@ venv = VirtualEnv(config.envconfigs['python'], session=mocksession) interp = venv.getsupportedinterpreter() # realpath needed for debian symlinks - assert py.path.local(interp).realpath() \ - == py.path.local(sys.executable).realpath() + assert py.path.local(interp).realpath() == py.path.local(sys.executable).realpath() monkeypatch.setattr(sys, 'platform', "win32") monkeypatch.setattr(venv.envconfig, 'basepython', 'jython') py.test.raises(tox.exception.UnsupportedInterpreter, @@ -58,14 +61,14 @@ assert "virtualenv" == str(args[2]) if sys.platform != "win32": # realpath is needed for stuff like the debian symlinks - assert py.path.local(sys.executable).realpath() \ - == py.path.local(args[0]).realpath() - #assert Envconfig.toxworkdir in args + assert py.path.local(sys.executable).realpath() == py.path.local(args[0]).realpath() + # assert Envconfig.toxworkdir in args assert venv.getcommandpath("easy_install", cwd=py.path.local()) interp = venv._getliveconfig().python assert interp == venv.envconfig._basepython_info.executable assert venv.path_config.check(exists=False) + @pytest.mark.skipif("sys.platform == 'win32'") def test_commandpath_venv_precendence(tmpdir, monkeypatch, mocksession, newconfig): @@ -80,6 +83,7 @@ p = venv.getcommandpath("easy_install") assert py.path.local(p).relto(envconfig.envbindir), p + def test_create_sitepackages(monkeypatch, mocksession, newconfig): config = newconfig([], """ [testenv:site] @@ -106,6 +110,7 @@ assert "--system-site-packages" not in map(str, args) assert "--no-site-packages" not in map(str, args) + def test_install_deps_wildcard(newmocksession): mocksession = newmocksession([], """ [tox] @@ -128,8 +133,8 @@ assert l[-1].cwd == venv.envconfig.config.toxinidir assert "pip" in str(args[0]) assert args[1] == "install" - #arg = "--download-cache=" + str(venv.envconfig.downloadcache) - #assert arg in args[2:] + # arg = "--download-cache=" + str(venv.envconfig.downloadcache) + # assert arg in args[2:] args = [arg for arg in args if str(arg).endswith("dep1-1.1.zip")] assert len(args) == 1 @@ -162,6 +167,7 @@ deps = list(filter(None, [x[1] for x in venv._getliveconfig().deps])) assert deps == ['dep1', 'dep2'] + def test_install_deps_indexserver(newmocksession): mocksession = newmocksession([], """ [tox] @@ -194,6 +200,7 @@ assert "-i ABC" in args assert "dep3" in args + def test_install_deps_pre(newmocksession): mocksession = newmocksession([], """ [testenv] @@ -213,6 +220,7 @@ assert "--pre " in args assert "dep1" in args + def test_installpkg_indexserver(newmocksession, tmpdir): mocksession = newmocksession([], """ [tox] @@ -228,6 +236,7 @@ args = " ".join(l[0].args) assert "-i ABC" in args + def test_install_recreate(newmocksession, tmpdir): pkg = tmpdir.ensure("package.tar.gz") mocksession = newmocksession(['--recreate'], """ @@ -241,6 +250,7 @@ venv.update() mocksession.report.expect("verbosity0", "*recreate*") + def test_test_hashseed_is_in_output(newmocksession): original_make_hashseed = tox._config.make_hashseed tox._config.make_hashseed = lambda: '123456789' @@ -255,6 +265,7 @@ venv.test() mocksession.report.expect("verbosity0", "python runtests: PYTHONHASHSEED='123456789'") + def test_test_runtests_action_command_is_in_output(newmocksession): mocksession = newmocksession([], ''' [testenv] @@ -265,6 +276,7 @@ venv.test() mocksession.report.expect("verbosity0", "*runtests*commands?0? | echo foo bar") + def test_install_error(newmocksession, monkeypatch): mocksession = newmocksession(['--recreate'], """ [testenv] @@ -277,6 +289,7 @@ mocksession.report.expect("error", "*not find*qwelkqw*") assert venv.status == "commands failed" + def test_install_command_not_installed(newmocksession, monkeypatch): mocksession = newmocksession(['--recreate'], """ [testenv] @@ -288,6 +301,7 @@ mocksession.report.expect("warning", "*test command found but not*") assert venv.status == 0 + def test_install_command_whitelisted(newmocksession, monkeypatch): mocksession = newmocksession(['--recreate'], """ [testenv] @@ -303,6 +317,7 @@ invert=True) assert venv.status == "commands failed" + @pytest.mark.skipif("not sys.platform.startswith('linux')") def test_install_command_not_installed_bash(newmocksession): mocksession = newmocksession(['--recreate'], """ @@ -340,6 +355,7 @@ for x in args: assert "--download-cache" not in args, args + class TestCreationConfig: def test_basic(self, newconfig, mocksession, tmpdir): @@ -435,7 +451,7 @@ venv = VirtualEnv(envconfig, session=mocksession) venv.update() cconfig = venv._getliveconfig() - cconfig.deps[:] = [("1"*32, "xyz.zip")] + cconfig.deps[:] = [("1" * 32, "xyz.zip")] cconfig.writeconfig(venv.path_config) mocksession._clearmocks() venv.update() @@ -453,6 +469,7 @@ venv.update() mocksession.report.expect("verbosity0", "*recreate*") + class TestVenvTest: def test_patchPATH(self, newmocksession, monkeypatch): @@ -468,14 +485,14 @@ assert oldpath == "xyz" res = os.environ['PATH'] assert res == "%s%sxyz" % (envconfig.envbindir, os.pathsep) - p = "xyz"+os.pathsep+str(envconfig.envbindir) + p = "xyz" + os.pathsep + str(envconfig.envbindir) monkeypatch.setenv("PATH", p) venv.patchPATH() res = os.environ['PATH'] - assert res == "%s%s%s" %(envconfig.envbindir, os.pathsep, p) + assert res == "%s%s%s" % (envconfig.envbindir, os.pathsep, p) assert envconfig.commands - monkeypatch.setattr(venv, '_pcall', lambda *args, **kwargs: 0/0) + monkeypatch.setattr(venv, '_pcall', lambda *args, **kwargs: 0 / 0) py.test.raises(ZeroDivisionError, "venv._install(list('123'))") py.test.raises(ZeroDivisionError, "venv.test()") py.test.raises(ZeroDivisionError, "venv.run_install_command(['qwe'])") @@ -488,6 +505,7 @@ assert 'PIP_REQUIRE_VIRTUALENV' not in os.environ assert '__PYVENV_LAUNCHER__' not in os.environ + def test_env_variables_added_to_pcall(tmpdir, mocksession, newconfig, monkeypatch): pkg = tmpdir.ensure("package.tar.gz") monkeypatch.setenv("X123", "123") @@ -516,11 +534,12 @@ assert env['X123'] == "123" assert set(["ENV_VAR", "VIRTUAL_ENV", "PYTHONHASHSEED", "X123", "PATH"])\ - .issubset(env) + .issubset(env) - #for e in os.environ: + # for e in os.environ: # assert e in env + def test_installpkg_no_upgrade(tmpdir, newmocksession): pkg = tmpdir.ensure("package.tar.gz") mocksession = newmocksession([], "") @@ -532,6 +551,7 @@ assert len(l) == 1 assert '-U' not in l[0].args + def test_installpkg_upgrade(newmocksession, tmpdir): pkg = tmpdir.ensure("package.tar.gz") mocksession = newmocksession([], "") @@ -545,6 +565,7 @@ assert '-U' in l[0].args[:index] assert '--no-deps' in l[0].args[:index] + def test_run_install_command(newmocksession): mocksession = newmocksession([], "") venv = mocksession.getenv('python') @@ -559,6 +580,7 @@ env = l[0].env assert env is not None + def test_run_custom_install_command(newmocksession): mocksession = newmocksession([], """ [testenv] @@ -574,6 +596,7 @@ assert 'easy_install' in l[0].args[0] assert l[0].args[1:] == ['whatever'] + def test_command_relative_issue26(newmocksession, tmpdir, monkeypatch): mocksession = newmocksession([], """ [testenv] @@ -591,6 +614,7 @@ assert x4.endswith(os.sep + 'x') mocksession.report.expect("warning", "*test command found but not*") + def test_sethome_only_on_option(newmocksession, monkeypatch): mocksession = newmocksession([], "") venv = mocksession.getenv('python') @@ -598,6 +622,7 @@ monkeypatch.setattr(tox._venv, "hack_home_env", None) venv._install(["x"], action=action) + def test_sethome_works_on_option(newmocksession, monkeypatch): mocksession = newmocksession(["--set-home", "-i ALL=http://qwe"], "") venv = mocksession.getenv('python') @@ -622,6 +647,7 @@ assert not tmpdir.join(".pydistutils.cfg").check() assert "PIP_INDEX_URL" not in env + def test_hack_home_env_passthrough(tmpdir, monkeypatch): from tox._venv import hack_home_env env = hack_home_env(tmpdir, "http://index") diff -r d3b25d3d9d603ac562030d12e18216f3b6268fd2 -r 37151bb27e530549ef2a17d3920f2bfea2421a87 tests/test_z_cmdline.py --- a/tests/test_z_cmdline.py +++ b/tests/test_z_cmdline.py @@ -12,35 +12,40 @@ from tox._cmdline import Session from tox._config import parseconfig + def test_report_protocol(newconfig): config = newconfig([], """ [testenv:mypython] deps=xy """) + class Popen: def __init__(self, *args, **kwargs): pass + def communicate(self): return "", "" + def wait(self): pass session = Session(config, popen=Popen, - Report=ReportExpectMock) + Report=ReportExpectMock) report = session.report report.expect("using") venv = session.getvenv("mypython") venv.update() report.expect("logpopen") + def test__resolve_pkg(tmpdir, mocksession): distshare = tmpdir.join("distshare") spec = distshare.join("pkg123-*") py.test.raises(tox.exception.MissingDirectory, - 'mocksession._resolve_pkg(spec)') + 'mocksession._resolve_pkg(spec)') distshare.ensure(dir=1) py.test.raises(tox.exception.MissingDependency, - 'mocksession._resolve_pkg(spec)') + 'mocksession._resolve_pkg(spec)') distshare.ensure("pkg123-1.3.5.zip") p = distshare.ensure("pkg123-1.4.5.zip") @@ -58,6 +63,7 @@ result = mocksession._resolve_pkg(spec) assert result == p + def test__resolve_pkg_doubledash(tmpdir, mocksession): distshare = tmpdir.join("distshare") p = distshare.ensure("pkg-mine-1.3.0.zip") @@ -68,7 +74,6 @@ assert res == p - class TestSession: def test_make_sdist(self, initproj): initproj("example123-0.5", filedefs={ @@ -116,7 +121,7 @@ action.popen(["echo", ]) match = mocksession.report.getnext("logpopen") assert match[1].outpath.relto(mocksession.config.logdir) - assert match[1].shell == False + assert match[1].shell is False def test_summary_status(self, initproj, capfd): initproj("logexample123-0.5", filedefs={ @@ -177,6 +182,7 @@ "*created sdist package at*", ]) + def test_minversion(cmd, initproj): initproj("interp123-0.5", filedefs={ 'tests': {'test_hello.py': "def test_hello(): pass"}, @@ -191,6 +197,7 @@ ]) assert result.ret + def test_run_custom_install_command_error(cmd, initproj): initproj("interp123-0.5", filedefs={ 'tox.ini': ''' @@ -204,6 +211,7 @@ ]) assert result.ret + def test_unknown_interpreter_and_env(cmd, initproj): initproj("interp123-0.5", filedefs={ 'tests': {'test_hello.py': "def test_hello(): pass"}, @@ -226,6 +234,7 @@ "*ERROR*unknown*", ]) + def test_unknown_interpreter(cmd, initproj): initproj("interp123-0.5", filedefs={ 'tests': {'test_hello.py': "def test_hello(): pass"}, @@ -242,6 +251,7 @@ "*ERROR*InterpreterNotFound*xyz_unknown_interpreter*", ]) + def test_skip_platform_mismatch(cmd, initproj): initproj("interp123-0.5", filedefs={ 'tests': {'test_hello.py': "def test_hello(): pass"}, @@ -260,6 +270,7 @@ "*python*platform mismatch*" ]) + def test_skip_unknown_interpreter(cmd, initproj): initproj("interp123-0.5", filedefs={ 'tests': {'test_hello.py': "def test_hello(): pass"}, @@ -276,6 +287,7 @@ "*SKIPPED*InterpreterNotFound*xyz_unknown_interpreter*", ]) + def test_unknown_dep(cmd, initproj): initproj("dep123-0.7", filedefs={ 'tests': {'test_hello.py': "def test_hello(): pass"}, @@ -291,6 +303,7 @@ "*ERROR*could not install*qweqwe123*", ]) + def test_unknown_environment(cmd, initproj): initproj("env123-0.7", filedefs={ 'tox.ini': '' @@ -301,13 +314,13 @@ "*ERROR*unknown*environment*qpwoei*", ]) + def test_skip_sdist(cmd, initproj): initproj("pkg123-0.7", filedefs={ 'tests': {'test_hello.py': "def test_hello(): pass"}, 'setup.py': """ syntax error - """ - , + """, 'tox.ini': ''' [tox] skipsdist=True @@ -318,12 +331,12 @@ result = cmd.run("tox", ) assert result.ret == 0 + def test_minimal_setup_py_empty(cmd, initproj): initproj("pkg123-0.7", filedefs={ 'tests': {'test_hello.py': "def test_hello(): pass"}, 'setup.py': """ - """ - , + """, 'tox.ini': '' }) @@ -333,13 +346,13 @@ "*ERROR*empty*", ]) + def test_minimal_setup_py_comment_only(cmd, initproj): initproj("pkg123-0.7", filedefs={ 'tests': {'test_hello.py': "def test_hello(): pass"}, 'setup.py': """\n# some comment - """ - , + """, 'tox.ini': '' }) @@ -349,14 +362,14 @@ "*ERROR*empty*", ]) + def test_minimal_setup_py_non_functional(cmd, initproj): initproj("pkg123-0.7", filedefs={ 'tests': {'test_hello.py': "def test_hello(): pass"}, 'setup.py': """ import sys - """ - , + """, 'tox.ini': '' }) @@ -366,13 +379,13 @@ "*ERROR*check setup.py*", ]) + def test_sdist_fails(cmd, initproj): initproj("pkg123-0.7", filedefs={ 'tests': {'test_hello.py': "def test_hello(): pass"}, 'setup.py': """ syntax error - """ - , + """, 'tox.ini': '', }) result = cmd.run("tox", ) @@ -381,6 +394,7 @@ "*FAIL*could not package project*", ]) + def test_package_install_fails(cmd, initproj): initproj("pkg123-0.7", filedefs={ 'tests': {'test_hello.py': "def test_hello(): pass"}, @@ -395,8 +409,7 @@ packages=['pkg123',], install_requires=['qweqwe123'], ) - """ - , + """, 'tox.ini': '', }) result = cmd.run("tox", ) @@ -406,14 +419,14 @@ ]) - class TestToxRun: @pytest.fixture def example123(self, initproj): initproj("example123-0.5", filedefs={ - 'tests': {'test_hello.py': """ - def test_hello(pytestconfig): - pass + 'tests': { + 'test_hello.py': """ + def test_hello(pytestconfig): + pass """, }, 'tox.ini': ''' @@ -475,6 +488,7 @@ assert not result.ret assert "sdist-make" not in result.stdout.str() + def test_usedevelop(initproj, cmd): initproj("example123", filedefs={'tox.ini': """ [testenv] @@ -484,6 +498,7 @@ assert not result.ret assert "sdist-make" not in result.stdout.str() + def test_usedevelop_mixed(initproj, cmd): initproj("example123", filedefs={'tox.ini': """ [testenv:devenv] @@ -502,11 +517,13 @@ assert not result.ret assert "sdist-make" in result.stdout.str() + def test_test_usedevelop(cmd, initproj): initproj("example123-0.5", filedefs={ - 'tests': {'test_hello.py': """ - def test_hello(pytestconfig): - pass + 'tests': { + 'test_hello.py': """ + def test_hello(pytestconfig): + pass """, }, 'tox.ini': ''' @@ -568,6 +585,7 @@ result = cmd.run("tox") assert not result.ret + def test_notest(initproj, cmd): initproj("example123", filedefs={'tox.ini': """ # content of: tox.ini @@ -586,6 +604,7 @@ "*py26*reusing*", ]) + def test_PYC(initproj, cmd, monkeypatch): initproj("example123", filedefs={'tox.ini': ''}) monkeypatch.setenv("PYTHONDOWNWRITEBYTECODE", 1) @@ -595,6 +614,7 @@ "*create*", ]) + def test_env_VIRTUALENV_PYTHON(initproj, cmd, monkeypatch): initproj("example123", filedefs={'tox.ini': ''}) monkeypatch.setenv("VIRTUALENV_PYTHON", '/FOO') @@ -604,6 +624,7 @@ "*create*", ]) + def test_sdistonly(initproj, cmd): initproj("example123", filedefs={'tox.ini': """ """}) @@ -614,6 +635,7 @@ ]) assert "-mvirtualenv" not in result.stdout.str() + def test_separate_sdist_no_sdistfile(cmd, initproj): distshare = cmd.tmpdir.join("distshare") initproj(("pkg123-foo", "0.7"), filedefs={ @@ -629,6 +651,7 @@ sdistfile = l[0] assert 'pkg123-foo-0.7.zip' in str(sdistfile) + def test_separate_sdist(cmd, initproj): distshare = cmd.tmpdir.join("distshare") initproj("pkg123-0.7", filedefs={ @@ -663,6 +686,7 @@ sdist_path = session.sdist() assert sdist_path == p + def test_installpkg(tmpdir, newconfig): p = tmpdir.ensure("pkg123-1.0.zip") config = newconfig(["--installpkg=%s" % p], "") @@ -670,6 +694,7 @@ sdist_path = session.sdist() assert sdist_path == p + @pytest.mark.xfail("sys.platform == 'win32' and sys.version_info < (2,6)", reason="test needs better impl") def test_envsitepackagesdir(cmd, initproj): @@ -685,6 +710,7 @@ X:*tox*site-packages* """) + def verify_json_report_format(data, testenvs=True): assert data["reportversion"] == "1" assert data["toxversion"] == tox.__version__ @@ -700,4 +726,3 @@ assert isinstance(pyinfo["version_info"], list) assert pyinfo["version"] assert pyinfo["executable"] - diff -r d3b25d3d9d603ac562030d12e18216f3b6268fd2 -r 37151bb27e530549ef2a17d3920f2bfea2421a87 tox.ini --- a/tox.ini +++ b/tox.ini @@ -20,8 +20,29 @@ [testenv:flakes] deps = pytest-flakes>=0.2 -commands = py.test --flakes -m flakes tox tests + pytest-pep8 + +commands = py.test -x --flakes --pep8 tox tests + +[testenv:dev] +# required to make looponfail reload on every source code change +usedevelop = True + +deps = + pytest-xdist>=1.11 +commands = {posargs:py.test -s -x -f -v} [pytest] -rsyncdirs=tests tox -addopts = -rsxXf +rsyncdirs = tests tox +addopts = -rsxX +# pytest-xdist plugin configuration +looponfailroots = tox tests +norecursedirs = .hg .tox + +# pytest-pep8 plugin configuration +pep8maxlinelength = 99 +# W503 - line break before binary operator +# E402 - module level import not at top of file +# E731 - do not assign a lambda expression, use a def +pep8ignore = + *.py W503 E402 E731 diff -r d3b25d3d9d603ac562030d12e18216f3b6268fd2 -r 37151bb27e530549ef2a17d3920f2bfea2421a87 tox/__init__.py --- a/tox/__init__.py +++ b/tox/__init__.py @@ -1,10 +1,12 @@ # __version__ = '2.0.0.dev1' + class exception: class Error(Exception): def __str__(self): - return "%s: %s" %(self.__class__.__name__, self.args[0]) + return "%s: %s" % (self.__class__.__name__, self.args[0]) + class ConfigError(Error): """ error in tox configuration. """ class UnsupportedInterpreter(Error): diff -r d3b25d3d9d603ac562030d12e18216f3b6268fd2 -r 37151bb27e530549ef2a17d3920f2bfea2421a87 tox/_cmdline.py --- a/tox/_cmdline.py +++ b/tox/_cmdline.py @@ -17,9 +17,11 @@ from tox.result import ResultLog from subprocess import STDOUT + def now(): return py.std.time.time() + def main(args=None): try: config = parseconfig(args, 'tox') @@ -28,6 +30,7 @@ except KeyboardInterrupt: raise SystemExit(2) + class Action(object): def __init__(self, session, venv, msg, args): self.venv = venv @@ -55,12 +58,10 @@ def setactivity(self, name, msg): self.activity = name - self.report.verbosity0("%s %s: %s" %(self.venvname, name, msg), - bold=True) + self.report.verbosity0("%s %s: %s" % (self.venvname, name, msg), bold=True) def info(self, name, msg): - self.report.verbosity1("%s %s: %s" %(self.venvname, name, msg), - bold=True) + self.report.verbosity1("%s %s: %s" % (self.venvname, name, msg), bold=True) def _initlogpath(self, actionid): if self.venv: @@ -83,8 +84,8 @@ resultjson = self.session.config.option.resultjson if resultjson or redirect: fout = self._initlogpath(self.id) - fout.write("actionid=%s\nmsg=%s\ncmdargs=%r\nenv=%s\n" %( - self.id, self.msg, args, env)) + fout.write("actionid=%s\nmsg=%s\ncmdargs=%r\nenv=%s\n" % ( + self.id, self.msg, args, env)) fout.flush() self.popen_outpath = outpath = py.path.local(fout.name) fin = outpath.open() @@ -154,9 +155,9 @@ if hasattr(self, "commandlog"): self.commandlog.add_command(popen.args, out, ret) raise tox.exception.InvocationError( - "%s (see %s)" %(invoked, outpath), ret) + "%s (see %s)" % (invoked, outpath), ret) else: - raise tox.exception.InvocationError("%r" %(invoked, )) + raise tox.exception.InvocationError("%r" % (invoked, )) if not out and outpath: out = outpath.read() if hasattr(self, "commandlog"): @@ -170,8 +171,8 @@ arg = cwd.bestrelpath(arg) newargs.append(str(arg)) - #subprocess does not always take kindly to .py scripts - #so adding the interpreter here. + # subprocess does not always take kindly to .py scripts + # so adding the interpreter here. if sys.platform == "win32": ext = os.path.splitext(str(newargs[0]))[1].lower() if ext == '.py' and self.venv: @@ -184,39 +185,37 @@ if env is None: env = os.environ.copy() return self.session.popen(args, shell=False, cwd=str(cwd), - universal_newlines=True, - stdout=stdout, stderr=stderr, env=env) - + universal_newlines=True, + stdout=stdout, stderr=stderr, env=env) class Reporter(object): actionchar = "-" + def __init__(self, session): self.tw = py.io.TerminalWriter() self.session = session self._reportedlines = [] - #self.cumulated_time = 0.0 + # self.cumulated_time = 0.0 def logpopen(self, popen, env): """ log information about the action.popen() created process. """ cmd = " ".join(map(str, popen.args)) if popen.outpath: - self.verbosity1(" %s$ %s >%s" %(popen.cwd, cmd, - popen.outpath, - )) + self.verbosity1(" %s$ %s >%s" % (popen.cwd, cmd, popen.outpath,)) else: - self.verbosity1(" %s$ %s " %(popen.cwd, cmd)) + self.verbosity1(" %s$ %s " % (popen.cwd, cmd)) def logaction_start(self, action): msg = action.msg + " " + " ".join(map(str, action.args)) - self.verbosity2("%s start: %s" %(action.venvname, msg), bold=True) + self.verbosity2("%s start: %s" % (action.venvname, msg), bold=True) assert not hasattr(action, "_starttime") action._starttime = now() def logaction_finish(self, action): duration = now() - action._starttime - #self.cumulated_time += duration - self.verbosity2("%s finish: %s after %.2f seconds" %( + # self.cumulated_time += duration + self.verbosity2("%s finish: %s after %.2f seconds" % ( action.venvname, action.msg, duration), bold=True) def startsummary(self): @@ -228,8 +227,7 @@ def using(self, msg): if self.session.config.option.verbosity >= 1: - self.logline("using %s" %(msg,), bold=True) - + self.logline("using %s" % (msg,), bold=True) def keyboard_interrupt(self): self.error("KEYBOARDINTERRUPT") @@ -275,7 +273,7 @@ if self.session.config.option.verbosity >= 2: self.logline("%s" % msg, **opts) - #def log(self, msg): + # def log(self, msg): # py.builtin.print_(msg, file=sys.stderr) @@ -288,13 +286,15 @@ self.report = Report(self) self.make_emptydir(config.logdir) config.logdir.ensure(dir=1) - #self.report.using("logdir %s" %(self.config.logdir,)) - self.report.using("tox.ini: %s" %(self.config.toxinipath,)) + # self.report.using("logdir %s" %(self.config.logdir,)) + self.report.using("tox.ini: %s" % (self.config.toxinipath,)) self._spec2pkg = {} self._name2venv = {} try: - self.venvlist = [self.getvenv(x) - for x in self.config.envlist] + self.venvlist = [ + self.getvenv(x) + for x in self.config.envlist + ] except LookupError: raise SystemExit(1) self._actions = [] @@ -321,15 +321,14 @@ return action def runcommand(self): - self.report.using("tox-%s from %s" %(tox.__version__, - tox.__file__)) + self.report.using("tox-%s from %s" % (tox.__version__, tox.__file__)) if self.config.minversion: minversion = NormalizedVersion(self.config.minversion) toxversion = NormalizedVersion(tox.__version__) if toxversion < minversion: self.report.error( - "tox version is %s, required is at least %s" %( - toxversion, minversion)) + "tox version is %s, required is at least %s" % ( + toxversion, minversion)) raise SystemExit(1) if self.config.option.showconfig: self.showconfig() @@ -342,7 +341,7 @@ for relpath in pathlist: src = srcdir.join(relpath) if not src.check(): - self.report.error("missing source file: %s" %(src,)) + self.report.error("missing source file: %s" % (src,)) raise SystemExit(1) target = destdir.join(relpath) target.dirpath().ensure(dir=1) @@ -358,7 +357,7 @@ self.make_emptydir(self.config.distdir) action.popen([sys.executable, setup, "sdist", "--formats=zip", "--dist-dir", self.config.distdir, ], - cwd=self.config.setupdir) + cwd=self.config.setupdir) try: return self.config.distdir.listdir()[0] except py.error.ENOENT: @@ -375,12 +374,11 @@ ) raise SystemExit(1) self.report.error( - 'No dist directory found. Please check setup.py, e.g with:\n'\ + 'No dist directory found. Please check setup.py, e.g with:\n' ' python setup.py sdist' - ) + ) raise SystemExit(1) - def make_emptydir(self, path): if path.check(): self.report.info(" removing %s" % path) @@ -446,25 +444,25 @@ :rtype: py.path.local """ if not self.config.option.sdistonly and (self.config.sdistsrc or - self.config.option.installpkg): + self.config.option.installpkg): sdist_path = self.config.option.installpkg if not sdist_path: sdist_path = self.config.sdistsrc sdist_path = self._resolve_pkg(sdist_path) self.report.info("using package %r, skipping 'sdist' activity " % - str(sdist_path)) + str(sdist_path)) else: try: sdist_path = self._makesdist() except tox.exception.InvocationError: v = sys.exc_info()[1] self.report.error("FAIL could not package project - v = %r" % - v) + v) return sdistfile = self.config.distshare.join(sdist_path.basename) if sdistfile != sdist_path: self.report.info("copying new sdistfile to %r" % - str(sdistfile)) + str(sdistfile)) try: sdistfile.dirpath().ensure(dir=1) except py.error.Error: @@ -513,24 +511,23 @@ for venv in self.venvlist: status = venv.status if isinstance(status, tox.exception.InterpreterNotFound): - msg = " %s: %s" %(venv.envconfig.envname, str(status)) + msg = " %s: %s" % (venv.envconfig.envname, str(status)) if self.config.option.skip_missing_interpreters: self.report.skip(msg) else: retcode = 1 self.report.error(msg) elif status == "platform mismatch": - msg = " %s: %s" %(venv.envconfig.envname, str(status)) + msg = " %s: %s" % (venv.envconfig.envname, str(status)) self.report.verbosity1(msg) elif status and status != "skipped tests": - msg = " %s: %s" %(venv.envconfig.envname, str(status)) + msg = " %s: %s" % (venv.envconfig.envname, str(status)) self.report.error(msg) retcode = 1 else: if not status: status = "commands succeeded" - self.report.good(" %s: %s" %(venv.envconfig.envname, - status)) + self.report.good(" %s: %s" % (venv.envconfig.envname, status)) if not retcode: self.report.good(" congratulations :)") @@ -586,7 +583,6 @@ versions.append("virtualenv-%s" % version.strip()) self.report.keyvalue("tool-versions:", " ".join(versions)) - def _resolve_pkg(self, pkgspec): try: return self._spec2pkg[pkgspec] @@ -614,7 +610,7 @@ items.append((ver, x)) else: self.report.warning("could not determine version of: %s" % - str(x)) + str(x)) items.sort() if not items: raise tox.exception.MissingDependency(pkgspec) @@ -624,6 +620,8 @@ _rex_getversion = py.std.re.compile("[\w_\-\+\.]+-(.*)(\.zip|\.tar.gz)") + + def getversion(basename): m = _rex_getversion.match(basename) if m is None: diff -r d3b25d3d9d603ac562030d12e18216f3b6268fd2 -r 37151bb27e530549ef2a17d3920f2bfea2421a87 tox/_config.py --- a/tox/_config.py +++ b/tox/_config.py @@ -45,7 +45,7 @@ if inipath.check(): break else: - feedback("toxini file %r not found" %(basename), sysexit=True) + feedback("toxini file %r not found" % (basename), sysexit=True) try: parseini(config, inipath) except tox.exception.InterpreterNotFound: @@ -54,98 +54,104 @@ py.builtin.print_("ERROR: " + str(exn)) return config + def feedback(msg, sysexit=False): py.builtin.print_("ERROR: " + msg, file=sys.stderr) if sysexit: raise SystemExit(1) + class VersionAction(argparse.Action): def __call__(self, argparser, *args, **kwargs): name = argparser.pkgname mod = __import__(name) version = mod.__version__ - py.builtin.print_("%s imported from %s" %(version, mod.__file__)) + py.builtin.print_("%s imported from %s" % (version, mod.__file__)) raise SystemExit(0) + class CountAction(argparse.Action): def __call__(self, parser, namespace, values, option_string=None): if hasattr(namespace, self.dest): - setattr(namespace, self.dest, int(getattr(namespace, self.dest))+1) + setattr(namespace, self.dest, int(getattr(namespace, self.dest)) + 1) else: setattr(namespace, self.dest, 0) + def prepare_parse(pkgname): parser = argparse.ArgumentParser(description=__doc__,) - #formatter_class=argparse.ArgumentDefaultsHelpFormatter) + # formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.pkgname = pkgname parser.add_argument("--version", nargs=0, action=VersionAction, - dest="version", - help="report version information to stdout.") + dest="version", + help="report version information to stdout.") parser.add_argument("-v", nargs=0, action=CountAction, default=0, - dest="verbosity", - help="increase verbosity of reporting output.") + dest="verbosity", + help="increase verbosity of reporting output.") parser.add_argument("--showconfig", action="store_true", - help="show configuration information for all environments. ") + help="show configuration information for all environments. ") parser.add_argument("-l", "--listenvs", action="store_true", - dest="listenvs", help="show list of test environments") + dest="listenvs", help="show list of test environments") parser.add_argument("-c", action="store", default="tox.ini", - dest="configfile", - help="use the specified config file name.") + dest="configfile", + help="use the specified config file name.") parser.add_argument("-e", action="append", dest="env", - metavar="envlist", - help="work against specified environments (ALL selects all).") + metavar="envlist", + help="work against specified environments (ALL selects all).") parser.add_argument("--notest", action="store_true", dest="notest", - help="skip invoking test commands.") + help="skip invoking test commands.") parser.add_argument("--sdistonly", action="store_true", dest="sdistonly", - help="only perform the sdist packaging activity.") + help="only perform the sdist packaging activity.") parser.add_argument("--installpkg", action="store", default=None, - metavar="PATH", - help="use specified package for installation into venv, instead of " - "creating an sdist.") + metavar="PATH", + help="use specified package for installation into venv, instead of " + "creating an sdist.") parser.add_argument("--develop", action="store_true", dest="develop", - help="install package in the venv using 'setup.py develop' via " - "'pip -e .'") + help="install package in the venv using 'setup.py develop' via " + "'pip -e .'") parser.add_argument("--set-home", action="store_true", dest="sethome", - help="(experimental) force creating a new $HOME for each test " - "environment and create .pydistutils.cfg|pip.conf files " - "if index servers are specified with tox. ") + help="(experimental) force creating a new $HOME for each test " + "environment and create .pydistutils.cfg|pip.conf files " + "if index servers are specified with tox. ") parser.add_argument('-i', action="append", - dest="indexurl", metavar="URL", - help="set indexserver url (if URL is of form name=url set the " - "url for the 'name' indexserver, specifically)") + dest="indexurl", metavar="URL", + help="set indexserver url (if URL is of form name=url set the " + "url for the 'name' indexserver, specifically)") parser.add_argument("--pre", action="store_true", dest="pre", - help="install pre-releases and development versions of dependencies. " - "This will pass the --pre option to install_command (pip by default).") + help="install pre-releases and development versions of dependencies. " + "This will pass the --pre option to install_command " + "(pip by default).") parser.add_argument("-r", "--recreate", action="store_true", - dest="recreate", - help="force recreation of virtual environments") + dest="recreate", + help="force recreation of virtual environments") parser.add_argument("--result-json", action="store", - dest="resultjson", metavar="PATH", - help="write a json file with detailed information about " - "all commands and results involved. This will turn off " - "pass-through output from running test commands which is " - "instead captured into the json result file.") + dest="resultjson", metavar="PATH", + help="write a json file with detailed information about " + "all commands and results involved. This will turn off " + "pass-through output from running test commands which is " + "instead captured into the json result file.") # We choose 1 to 4294967295 because it is the range of PYTHONHASHSEED. parser.add_argument("--hashseed", action="store", - metavar="SEED", default=None, - help="set PYTHONHASHSEED to SEED before running commands. " - "Defaults to a random integer in the range [1, 4294967295] " - "([1, 1024] on Windows). " - "Passing 'noset' suppresses this behavior.") + metavar="SEED", default=None, + help="set PYTHONHASHSEED to SEED before running commands. " + "Defaults to a random integer in the range [1, 4294967295] " + "([1, 1024] on Windows). " + "Passing 'noset' suppresses this behavior.") parser.add_argument("--force-dep", action="append", - metavar="REQ", default=None, - help="Forces a certain version of one of the dependencies " - "when configuring the virtual environment. REQ Examples " - "'pytest<2.7' or 'django>=1.6'.") + metavar="REQ", default=None, + help="Forces a certain version of one of the dependencies " + "when configuring the virtual environment. REQ Examples " + "'pytest<2.7' or 'django>=1.6'.") parser.add_argument("--sitepackages", action="store_true", - help="override sitepackages setting to True in all envs") + help="override sitepackages setting to True in all envs") parser.add_argument("--skip-missing-interpreters", action="store_true", - help="don't fail tests for missing interpreters") + help="don't fail tests for missing interpreters") parser.add_argument("args", nargs="*", - help="additional arguments available to command positional substitution") + help="additional arguments available to command positional substitution") return parser + class Config(object): def __init__(self): self.envconfigs = {} @@ -167,8 +173,9 @@ @property def envbindir(self): - if (sys.platform == "win32" and "jython" not in self.basepython - and "pypy" not in self.basepython): + if (sys.platform == "win32" + and "jython" not in self.basepython + and "pypy" not in self.basepython): return self.envdir.join("Scripts") else: return self.envdir.join("bin") @@ -185,8 +192,8 @@ def envsitepackagesdir(self): self.getsupportedinterpreter() # for throwing exceptions x = self.config.interpreters.get_sitepackagesdir( - info=self._basepython_info, - envdir=self.envdir) + info=self._basepython_info, + envdir=self.envdir) return x def getsupportedinterpreter(self): @@ -200,14 +207,14 @@ if not info.version_info: raise tox.exception.InvocationError( 'Failed to get version_info for %s: %s' % (info.name, info.err)) - if info.version_info < (2,6): + if info.version_info < (2, 6): raise tox.exception.UnsupportedInterpreter( "python2.5 is not supported anymore, sorry") return info.executable +testenvprefix = "testenv:" -testenvprefix = "testenv:" def get_homedir(): try: @@ -215,12 +222,14 @@ except Exception: return None + def make_hashseed(): max_seed = 4294967295 if sys.platform == 'win32': max_seed = 1024 return str(random.randint(1, max_seed)) + class parseini: def __init__(self, config, inipath): config.toxinipath = inipath @@ -287,8 +296,7 @@ config.indexserver[name] = IndexServerConfig(name, override) reader.addsubstitutions(toxworkdir=config.toxworkdir) - config.distdir = reader.getpath(toxsection, "distdir", - "{toxworkdir}/dist") + config.distdir = reader.getpath(toxsection, "distdir", "{toxworkdir}/dist") reader.addsubstitutions(distdir=config.distdir) config.distshare = reader.getpath(toxsection, "distshare", distshare_default) @@ -335,18 +343,18 @@ def _makeenvconfig(self, name, section, subs, config): vc = VenvConfig(config=config, envname=name) factors = set(name.split('-')) - reader = IniReader(self._cfg, fallbacksections=["testenv"], - factors=factors) + reader = IniReader(self._cfg, fallbacksections=["testenv"], factors=factors) reader.addsubstitutions(**subs) - vc.develop = not config.option.installpkg and \ - reader.getbool(section, "usedevelop", config.option.develop) + vc.develop = ( + not config.option.installpkg + and reader.getbool(section, "usedevelop", config.option.develop)) vc.envdir = reader.getpath(section, "envdir", "{toxworkdir}/%s" % name) vc.args_are_paths = reader.getbool(section, "args_are_paths", True) if reader.getdefault(section, "python", None): raise tox.exception.ConfigError( "'python=' key was renamed to 'basepython='") bp = next((default_factors[f] for f in factors if f in default_factors), - sys.executable) + sys.executable) vc.basepython = reader.getdefault(section, "basepython", bp) vc._basepython_info = config.interpreters.get_info(vc.basepython) reader.addsubstitutions(envdir=vc.envdir, envname=vc.envname, @@ -410,8 +418,9 @@ break vc.platform = platform - vc.sitepackages = self.config.option.sitepackages or \ - reader.getbool(section, "sitepackages", False) + vc.sitepackages = ( + self.config.option.sitepackages + or reader.getbool(section, "sitepackages", False)) vc.downloadcache = None downloadcache = reader.getdefault(section, "downloadcache") @@ -424,10 +433,10 @@ section, "install_command", "pip install {opts} {packages}", - ) + ) if '{packages}' not in vc.install_command: raise tox.exception.ConfigError( - "'install_command' must contain '{packages}' substitution") + "'install_command' must contain '{packages}' substitution") vc.pip_pre = config.option.pre or reader.getbool( section, "pip_pre", False) @@ -488,10 +497,12 @@ env = [env] return mapcat(_expand_envstr, env) + def _split_factor_expr(expr): partial_envs = _expand_envstr(expr) return [set(e.split('-')) for e in partial_envs] + def _expand_envstr(envstr): # split by commas not in groups tokens = re.split(r'((?:\{[^}]+\})+)|,', envstr) @@ -505,9 +516,11 @@ return mapcat(expand, envlist) + def mapcat(f, seq): return list(itertools.chain.from_iterable(map(f, seq))) + class DepConfig: def __init__(self, name, indexserver=None): self.name = name @@ -710,7 +723,7 @@ x = self._replace(x) finally: assert self._subststack.pop() == (section, name) - #print "getdefault", section, name, "returned", repr(x) + # print "getdefault", section, name, "returned", repr(x) return x def _apply_factors(self, s): @@ -740,7 +753,7 @@ else: envkey = match_value - if not envkey in os.environ and default is None: + if envkey not in os.environ and default is None: raise tox.exception.ConfigError( "substitution env:%r: unkown environment variable %r" % (envkey, envkey)) @@ -750,11 +763,11 @@ def _substitute_from_other_section(self, key): if key.startswith("[") and "]" in key: i = key.find("]") - section, item = key[1:i], key[i+1:] + section, item = key[1:i], key[i + 1:] if section in self._cfg and item in self._cfg[section]: if (section, item) in self._subststack: - raise ValueError('%s already in %s' %( - (section, item), self._subststack)) + raise ValueError('%s already in %s' % ( + (section, item), self._subststack)) x = str(self._cfg[section][item]) self._subststack.append((section, item)) try: @@ -785,13 +798,14 @@ return '{%s}' % sub_value handlers = { - 'env' : self._replace_env, - None : self._replace_substitution, - } + 'env': self._replace_env, + None: self._replace_substitution, + } try: sub_type = g['sub_type'] except KeyError: - raise tox.exception.ConfigError("Malformed substitution; no substitution type provided") + raise tox.exception.ConfigError( + "Malformed substitution; no substitution type provided") try: handler = handlers[sub_type] @@ -808,6 +822,7 @@ def _parse_command(self, command): pass + class CommandParser(object): class State(object): @@ -824,11 +839,11 @@ def word_has_ended(): return ((cur_char in string.whitespace and ps.word and - ps.word[-1] not in string.whitespace) or - (cur_char == '{' and ps.depth == 0 and not ps.word.endswith('\\')) or - (ps.depth == 0 and ps.word and ps.word[-1] == '}') or - (cur_char not in string.whitespace and ps.word and - ps.word.strip() == '')) + ps.word[-1] not in string.whitespace) or + (cur_char == '{' and ps.depth == 0 and not ps.word.endswith('\\')) or + (ps.depth == 0 and ps.word and ps.word[-1] == '}') or + (cur_char not in string.whitespace and ps.word and + ps.word.strip() == '')) def yield_this_word(): yieldword = ps.word @@ -869,8 +884,8 @@ yield_this_word() return ps.yield_words + def getcontextname(): if any(env in os.environ for env in ['JENKINS_URL', 'HUDSON_URL']): return 'jenkins' return None - diff -r d3b25d3d9d603ac562030d12e18216f3b6268fd2 -r 37151bb27e530549ef2a17d3920f2bfea2421a87 tox/_exception.py --- a/tox/_exception.py +++ b/tox/_exception.py @@ -1,16 +1,28 @@ class Error(Exception): def __str__(self): - return "%s: %s" %(self.__class__.__name__, self.args[0]) + return "%s: %s" % (self.__class__.__name__, self.args[0]) + + class UnsupportedInterpreter(Error): "signals an unsupported Interpreter" + + class InterpreterNotFound(Error): "signals that an interpreter could not be found" + + class InvocationError(Error): """ an error while invoking a script. """ + + class MissingFile(Error): """ an error while invoking a script. """ + + class MissingDirectory(Error): """ a directory did not exist. """ + + class MissingDependency(Error): """ a dependency could not be found or determined. """ This diff is so big that we needed to truncate the remainder. Repository URL: https://bitbucket.org/hpk42/tox/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email. _______________________________________________ pytest-commit mailing list pytest-commit@python.org https://mail.python.org/mailman/listinfo/pytest-commit