コード例 #1
0
def test_outdated_venv(mocker):
    try:
        venv_path = tempfile.mkdtemp()
        dephash.create_virtualenv('virtualenv', venv_path, PROD_REQ_PATH)
        mocker.patch.object(sys, 'argv', new=["dephash", "outdated", venv_path])
        try:
            dephash.main()
        except SystemExit as e:
            assert e.code == 0, "This test may fail if there are new dependencies on pypi"
    finally:
        shutil.rmtree(venv_path)
コード例 #2
0
def test_outdated_old_venv(mocker):
    try:
        # make sure we have an outdated requirement
        _, tmppath = tempfile.mkstemp()
        with open(DEV_REQ_PATH, "r") as dev_fh:
            contents = dev_fh.read().rstrip()
        with open(tmppath, "w") as tmp_fh:
            for line in contents.split('\n'):
                if line.startswith('virtualenv'):
                    line = "virtualenv==15.0.1"
                print(line, file=tmp_fh)
        mocker.patch.object(sys, 'argv', new=["dephash", "outdated", tmppath])
        try:
            dephash.main()
        except SystemExit as e:
            assert e.code == 1
    finally:
        os.remove(tmppath)
コード例 #3
0
def test_gen_cmdln(req_path, mocker):
    logger = logging.getLogger(''.join(
        random.SystemRandom().choice(string.ascii_uppercase + string.digits)
        for _ in range(6)))
    mocker.patch.object(dephash, 'log', new=logger)
    try:
        _, logfile = tempfile.mkstemp()
        _, output_file = tempfile.mkstemp()
        mocker.patch.object(
            sys, 'argv', new=["dephash", "-v", "-l", logfile, "gen", req_path])
        with open(output_file, "w") as fh:
            mocker.patch.object(sys, 'stdout', new=fh)
            with pytest.raises(SystemExit):
                dephash.main()
        output = read_file(output_file)
        assert output == read_file(req_path)
    finally:
        os.remove(output_file)
        os.remove(logfile)