Ejemplo n.º 1
0
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 = session.report
    report.expect("using")
    venv = session.getvenv("mypython")
    venv.update()
    report.expect("logpopen")
Ejemplo n.º 2
0
 def test_summary_status(self, initproj, capfd):
     initproj(
         "logexample123-0.5",
         filedefs={
             "tests": {
                 "test_hello.py": "def test_hello(): pass"
             },
             "tox.ini":
             """
         [testenv:hello]
         [testenv:world]
         """,
         },
     )
     config = parseconfig([])
     session = Session(config)
     envs = list(session.venv_dict.values())
     assert len(envs) == 2
     env1, env2 = envs
     env1.status = "FAIL XYZ"
     assert env1.status
     env2.status = 0
     assert not env2.status
     session._summary()
     out, err = capfd.readouterr()
     exp = "{}: FAIL XYZ".format(env1.envconfig.envname)
     assert exp in out
     exp = "{}: commands succeeded".format(env2.envconfig.envname)
     assert exp in out
Ejemplo n.º 3
0
 def test_summary_status(self, initproj, capfd):
     initproj(
         "logexample123-0.5",
         filedefs={
             "tests": {"test_hello.py": "def test_hello(): pass"},
             "tox.ini": """
         [testenv:hello]
         [testenv:world]
         """,
         },
     )
     config = parseconfig([])
     session = Session(config)
     envs = session.venvlist
     assert len(envs) == 2
     env1, env2 = envs
     env1.status = "FAIL XYZ"
     assert env1.status
     env2.status = 0
     assert not env2.status
     session._summary()
     out, err = capfd.readouterr()
     exp = "%s: FAIL XYZ" % env1.envconfig.envname
     assert exp in out
     exp = "%s: commands succeeded" % env2.envconfig.envname
     assert exp in out
Ejemplo n.º 4
0
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 = session.report
    report.expect("using")
    venv = session.getvenv("mypython")
    action = session.newaction(venv, "update")
    venv.update(action)
    report.expect("logpopen")
Ejemplo n.º 5
0
 def test_summary_status(self, initproj, capfd):
     initproj("logexample123-0.5",
              filedefs={
                  'tests': {
                      'test_hello.py': "def test_hello(): pass"
                  },
                  'tox.ini':
                  '''
         [testenv:hello]
         [testenv:world]
         '''
              })
     config = parseconfig([])
     session = Session(config)
     envs = session.venvlist
     assert len(envs) == 2
     env1, env2 = envs
     env1.status = "FAIL XYZ"
     assert env1.status
     env2.status = 0
     assert not env2.status
     session._summary()
     out, err = capfd.readouterr()
     exp = "%s: FAIL XYZ" % env1.envconfig.envname
     assert exp in out
     exp = "%s: commands succeeded" % env2.envconfig.envname
     assert exp in out
Ejemplo n.º 6
0
def test_sdist_latest(tmpdir, newconfig):
    distshare = tmpdir.join("distshare")
    config = newconfig([], """
            [tox]
            distshare=%s
            sdistsrc={distshare}/pkg123-*
    """ % distshare)
    p = distshare.ensure("pkg123-1.4.5.zip")
    distshare.ensure("pkg123-1.4.5a1.zip")
    session = Session(config)
    sdist_path = session.get_installpkg_path()
    assert sdist_path == p
Ejemplo n.º 7
0
def test_sdist_latest(tmpdir, newconfig):
    distshare = tmpdir.join("distshare")
    config = newconfig([], """
            [tox]
            distshare=%s
            sdistsrc={distshare}/pkg123-*
    """ % distshare)
    p = distshare.ensure("pkg123-1.4.5.zip")
    distshare.ensure("pkg123-1.4.5a1.zip")
    session = Session(config)
    sdist_path = session.get_installpkg_path()
    assert sdist_path == p
Ejemplo n.º 8
0
def test_make_sdist_distshare(tmpdir, initproj):
    distshare = tmpdir.join("distshare")
    initproj(
        "example123-0.6",
        filedefs={
            "tests": {"test_hello.py": "def test_hello(): pass"},
            "tox.ini": """
        [tox]
        distshare={}
        """.format(
                distshare
            ),
        },
    )
    config = parseconfig([])
    session = Session(config)
    package, dist = get_package(session)
    assert package.check()
    assert package.ext == ".zip"
    assert package == config.temp_dir.join("package", "1", package.basename)

    assert dist == config.distdir.join(package.basename)
    assert dist.check()
    assert os.stat(str(dist)).st_ino == os.stat(str(package)).st_ino

    sdist_share = config.distshare.join(package.basename)
    assert sdist_share.check()
    assert sdist_share.read("rb") == dist.read("rb"), (sdist_share, package)
Ejemplo n.º 9
0
 def test_getvenv(self, initproj, capfd):
     initproj("logexample123-0.5", filedefs={
         'tests': {'test_hello.py': "def test_hello(): pass"},
         'tox.ini': '''
         [testenv:hello]
         [testenv:world]
         '''
     })
     config = parseconfig([])
     session = Session(config)
     venv1 = session.getvenv("hello")
     venv2 = session.getvenv("hello")
     assert venv1 is venv2
     venv1 = session.getvenv("world")
     venv2 = session.getvenv("world")
     assert venv1 is venv2
     pytest.raises(LookupError, lambda: session.getvenv("qwe"))
Ejemplo n.º 10
0
 def test_getvenv(self, initproj, capfd):
     initproj("logexample123-0.5", filedefs={
         'tests': {'test_hello.py': "def test_hello(): pass"},
         'tox.ini': '''
         [testenv:hello]
         [testenv:world]
         '''
     })
     config = parseconfig([])
     session = Session(config)
     venv1 = session.getvenv("hello")
     venv2 = session.getvenv("hello")
     assert venv1 is venv2
     venv1 = session.getvenv("world")
     venv2 = session.getvenv("world")
     assert venv1 is venv2
     pytest.raises(LookupError, lambda: session.getvenv("qwe"))
Ejemplo n.º 11
0
 def test_make_sdist_distshare(self, tmpdir, initproj):
     distshare = tmpdir.join("distshare")
     initproj("example123-0.6", filedefs={
         'tests': {'test_hello.py': "def test_hello(): pass"},
         'tox.ini': '''
         [tox]
         distshare=%s
         ''' % distshare
     })
     config = parseconfig([])
     session = Session(config)
     sdist = session.get_installpkg_path()
     assert sdist.check()
     assert sdist.ext == ".zip"
     assert sdist == config.distdir.join(sdist.basename)
     sdist_share = config.distshare.join(sdist.basename)
     assert sdist_share.check()
     assert sdist_share.read("rb") == sdist.read("rb"), (sdist_share, sdist)
Ejemplo n.º 12
0
 def test_make_sdist_distshare(self, tmpdir, initproj):
     distshare = tmpdir.join("distshare")
     initproj("example123-0.6", filedefs={
         'tests': {'test_hello.py': "def test_hello(): pass"},
         'tox.ini': '''
         [tox]
         distshare=%s
         ''' % distshare
     })
     config = parseconfig([])
     session = Session(config)
     sdist = session.get_installpkg_path()
     assert sdist.check()
     assert sdist.ext == ".zip"
     assert sdist == config.distdir.join(sdist.basename)
     sdist_share = config.distshare.join(sdist.basename)
     assert sdist_share.check()
     assert sdist_share.read("rb") == sdist.read("rb"), (sdist_share, sdist)
Ejemplo n.º 13
0
 def test_make_sdist(self, initproj):
     initproj("example123-0.5", filedefs={
         'tests': {'test_hello.py': "def test_hello(): pass"},
         'tox.ini': '''
         '''
     })
     config = parseconfig([])
     session = Session(config)
     sdist = session.get_installpkg_path()
     assert sdist.check()
     assert sdist.ext == ".zip"
     assert sdist == config.distdir.join(sdist.basename)
     sdist2 = session.get_installpkg_path()
     assert sdist2 == sdist
     sdist.write("hello")
     assert sdist.stat().size < 10
     sdist_new = Session(config).get_installpkg_path()
     assert sdist_new == sdist
     assert sdist_new.stat().size > 10
Ejemplo n.º 14
0
def test_install_special_deps(toxconfig, mocker, actioncls, tmpdir):
    """
    Test that nothing is called when there are no deps
    """
    action = actioncls()
    p = tmpdir.join("tox.ini")
    p.write(toxconfig)
    with tmpdir.as_cwd():
        config = parseconfig([])

        for env, envconfig in config.envconfigs.items():
            session = Session(config)
            venv = tox.venv.VirtualEnv(envconfig, session=session)
            mocker.patch("subprocess.Popen")
            result = session.runtestenv(venv)
            assert result == True
            assert subprocess.Popen.call_count == 1
            call_list = [sys.executable, "-m", "pipenv", "install", "--dev"]
            call_list.extend([package for package in venv._getresolvedeps()])
            assert subprocess.Popen.call_args_list[0][0] == (call_list,)
Ejemplo n.º 15
0
 def test_make_sdist_distshare(self, tmpdir, initproj):
     distshare = tmpdir.join("distshare")
     initproj(
         "example123-0.6",
         filedefs={
             "tests": {"test_hello.py": "def test_hello(): pass"},
             "tox.ini": """
         [tox]
         distshare={}
         """.format(
                 distshare
             ),
         },
     )
     config = parseconfig([])
     session = Session(config)
     sdist = session.get_installpkg_path()
     assert sdist.check()
     assert sdist.ext == ".zip"
     assert sdist == config.distdir.join(sdist.basename)
     sdist_share = config.distshare.join(sdist.basename)
     assert sdist_share.check()
     assert sdist_share.read("rb") == sdist.read("rb"), (sdist_share, sdist)
Ejemplo n.º 16
0
def test_make_sdist(initproj):
    initproj(
        "example123-0.5",
        filedefs={
            "tests": {
                "test_hello.py": "def test_hello(): pass"
            },
            "tox.ini": """
        """,
        },
    )
    config = parseconfig([])
    session = Session(config)
    _, sdist = get_package(session)
    assert sdist.check()
    assert sdist.ext == ".zip"
    assert sdist == config.distdir.join(sdist.basename)
    _, sdist2 = get_package(session)
    assert sdist2 == sdist
    sdist.write("hello")
    assert sdist.stat().size < 10
    _, sdist_new = get_package(Session(config))
    assert sdist_new == sdist
    assert sdist_new.stat().size > 10
Ejemplo n.º 17
0
def test_sdist_latest(tmpdir, newconfig):
    distshare = tmpdir.join("distshare")
    config = newconfig(
        [],
        """
            [tox]
            distshare={}
            sdistsrc={{distshare}}/pkg123-*
    """.format(distshare, ),
    )
    p = distshare.ensure("pkg123-1.4.5.zip")
    distshare.ensure("pkg123-1.4.5a1.zip")
    session = Session(config)
    _, dist = get_package(session)
    assert dist == p
Ejemplo n.º 18
0
def tox_package(session: session.Session, venv: VirtualEnv) -> Any:
    with venv.new_action("buildpkg") as action:
        tox_testenv_create(venv, action)
    if not detect_pdm_files(venv.path):
        return
    if not hasattr(session, "package"):
        session.package, session.dist = get_package(session, venv)
    # Patch the install command to install to local __pypackages__ folder
    for i, arg in enumerate(venv.envconfig.install_command):
        if arg == "python":
            venv.envconfig.install_command[i] = venv.getsupportedinterpreter()
    venv.envconfig.install_command.extend(
        ["-t",
         get_env_lib_path(venv.envconfig.config.option.pdm, venv.path)])
    return session.package
Ejemplo n.º 19
0
 def test_make_sdist(self, initproj):
     initproj("example123-0.5", filedefs={
         'tests': {'test_hello.py': "def test_hello(): pass"},
         'tox.ini': '''
         '''
     })
     config = parseconfig([])
     session = Session(config)
     sdist = session.get_installpkg_path()
     assert sdist.check()
     assert sdist.ext == ".zip"
     assert sdist == config.distdir.join(sdist.basename)
     sdist2 = session.get_installpkg_path()
     assert sdist2 == sdist
     sdist.write("hello")
     assert sdist.stat().size < 10
     sdist_new = Session(config).get_installpkg_path()
     assert sdist_new == sdist
     assert sdist_new.stat().size > 10
Ejemplo n.º 20
0
    def run_tests(self):
        fails = []
        from tox.config import parseconfig
        from tox.session import Session

        config = parseconfig(self.test_args)
        retcode = Session(config).runcommand()
        if retcode != 0:
            fails.append('tox returned errors')

        import pep8
        style_guide = pep8.StyleGuide(config_file=BASE_PATH + '/.pep8')
        style_guide.input_dir(BASE_PATH + '/rw')
        if style_guide.options.report.get_count() != 0:
            fails.append('pep8 returned errros for rw/')

        style_guide = pep8.StyleGuide(config_file=BASE_PATH + '/.pep8')
        style_guide.input_dir(BASE_PATH + '/test')
        if style_guide.options.report.get_count() != 0:
            fails.append('pep8 returned errros for test/')

        if fails:
            print('\n'.join(fails))
            sys.exit(1)
Ejemplo n.º 21
0
 def test_getvenv(self, initproj):
     initproj(
         "logexample123-0.5",
         filedefs={
             "tests": {"test_hello.py": "def test_hello(): pass"},
             "tox.ini": """
         [testenv:hello]
         [testenv:world]
         """,
         },
     )
     config = parseconfig([])
     session = Session(config)
     venv1 = session.getvenv("hello")
     venv2 = session.getvenv("hello")
     assert venv1 is venv2
     venv1 = session.getvenv("world")
     venv2 = session.getvenv("world")
     assert venv1 is venv2
     with pytest.raises(LookupError):
         session.getvenv("qwe")
Ejemplo n.º 22
0
def test_installpkg(tmpdir, newconfig):
    p = tmpdir.ensure("pkg123-1.0.zip")
    config = newconfig(["--installpkg={}".format(p)], "")
    session = Session(config)
    _, sdist_path = get_package(session)
    assert sdist_path == p
Ejemplo n.º 23
0
def test_installpkg(tmpdir, newconfig):
    p = tmpdir.ensure("pkg123-1.0.zip")
    config = newconfig(["--installpkg=%s" % p], "")
    session = Session(config)
    sdist_path = session.get_installpkg_path()
    assert sdist_path == p
Ejemplo n.º 24
0
        if command[0] != "nosetests":
            return None
        return [bin, os.path.join(helpers_dir, "noserunner.py")] + command[1:]


_RUNNERS = [_Unit2(), _PyTest(), _Nose()]

import sys

config = tox_config.parseconfig(args=sys.argv[1:])
config.pluginmanager.register(JbToxHook(config), "jbtoxplugin")
for env, tmp_config in config.envconfigs.items():
    if not tmp_config.setenv:
        tmp_config.setenv = dict()
    tmp_config.setenv["_jb_do_not_call_enter_matrix"] = "1"
    commands = tmp_config.commands
    if not isinstance(commands, list) or not len(commands):
        continue
    for fixer in _RUNNERS:
        _env = config.envconfigs[env]
        for i, command in enumerate(commands):
            if command:
                fixed_command = fixer.fix(command, str(_env.envpython))
                if fixed_command:
                    commands[i] = fixed_command
    tmp_config.commands = commands

session = Session(config)
teamcity.testMatrixEntered()
session.runcommand()
Ejemplo n.º 25
0
 def build_session(config):
     session = Session(config, popen=popen)
     res[id(session)] = Result(session)
     return session
Ejemplo n.º 26
0
def test_installpkg(tmpdir, newconfig):
    p = tmpdir.ensure("pkg123-1.0.zip")
    config = newconfig(["--installpkg=%s" % p], "")
    session = Session(config)
    sdist_path = session.get_installpkg_path()
    assert sdist_path == p
durationStrategy = "automatic"
config = tox_config.parseconfig(args=sys.argv[1:])
hook = JbToxHook(config)
config.pluginmanager.register(hook, "jbtoxplugin")
offset = 1
for env, tmp_config in config.envconfigs.items():
    hook.offsets[env] = offset
    if not tmp_config.setenv:
        tmp_config.setenv = dict()
    tmp_config.setenv["_jb_do_not_call_enter_matrix"] = "1"
    commands = tmp_config.commands

    if "_jb_do_not_patch_test_runners" not in os.environ and isinstance(
            commands, list):
        for fixer in _RUNNERS:
            _env = config.envconfigs[env]
            for i, command in enumerate(commands):
                if command:
                    fixed_command = fixer.fix(command, str(_env.envpython),
                                              offset)
                    if fixer.is_parallel(tmp_config):
                        durationStrategy = "manual"
                    if fixed_command:
                        commands[i] = fixed_command
    tmp_config.commands = commands
    offset += 10000

session = Session(config)
teamcity.testMatrixEntered(durationStrategy=durationStrategy)
session.runcommand()
Ejemplo n.º 28
0
durationStrategy = "automatic"
config = tox_config.parseconfig(args=sys.argv[1:])
hook = JbToxHook(config)
config.pluginmanager.register(hook, "jbtoxplugin")
offset = 1
for env, tmp_config in config.envconfigs.items():
    hook.offsets[env] = offset
    if not tmp_config.setenv:
        tmp_config.setenv = dict()
    tmp_config.setenv["_jb_do_not_call_enter_matrix"] = "1"
    commands = tmp_config.commands

    if "_jb_do_not_patch_test_runners" not in os.environ and isinstance(
            commands, list):
        for fixer in _RUNNERS:
            _env = config.envconfigs[env]
            for i, command in enumerate(commands):
                if command:
                    fixed_command = fixer.fix(command, str(_env.envpython),
                                              offset)
                    if fixer.is_parallel(tmp_config):
                        durationStrategy = "manual"
                    if fixed_command:
                        commands[i] = fixed_command
    tmp_config.commands = commands
    offset += 10000

session = Session(config)
teamcity.testMatrixEntered(durationStrategy=durationStrategy)
sys.exit(session.runcommand())