|
| 1 | +import re |
| 2 | + |
| 3 | +from tox.config import parseconfig |
| 4 | +from tox.package import get_package |
| 5 | +from tox.session import Session |
| 6 | + |
| 7 | + |
| 8 | +def test_make_sdist(initproj): |
| 9 | + initproj( |
| 10 | + "example123-0.5", |
| 11 | + filedefs={ |
| 12 | + "tests": {"test_hello.py": "def test_hello(): pass"}, |
| 13 | + "tox.ini": """ |
| 14 | + """, |
| 15 | + }, |
| 16 | + ) |
| 17 | + config = parseconfig([]) |
| 18 | + session = Session(config) |
| 19 | + sdist = get_package(session) |
| 20 | + assert sdist.check() |
| 21 | + assert sdist.ext == ".zip" |
| 22 | + assert sdist == config.distdir.join(sdist.basename) |
| 23 | + sdist2 = get_package(session) |
| 24 | + assert sdist2 == sdist |
| 25 | + sdist.write("hello") |
| 26 | + assert sdist.stat().size < 10 |
| 27 | + sdist_new = get_package(Session(config)) |
| 28 | + assert sdist_new == sdist |
| 29 | + assert sdist_new.stat().size > 10 |
| 30 | + |
| 31 | + |
| 32 | +def test_make_sdist_distshare(tmpdir, initproj): |
| 33 | + distshare = tmpdir.join("distshare") |
| 34 | + initproj( |
| 35 | + "example123-0.6", |
| 36 | + filedefs={ |
| 37 | + "tests": {"test_hello.py": "def test_hello(): pass"}, |
| 38 | + "tox.ini": """ |
| 39 | + [tox] |
| 40 | + distshare={} |
| 41 | + """.format( |
| 42 | + distshare |
| 43 | + ), |
| 44 | + }, |
| 45 | + ) |
| 46 | + config = parseconfig([]) |
| 47 | + session = Session(config) |
| 48 | + sdist = get_package(session) |
| 49 | + assert sdist.check() |
| 50 | + assert sdist.ext == ".zip" |
| 51 | + assert sdist == config.distdir.join(sdist.basename) |
| 52 | + sdist_share = config.distshare.join(sdist.basename) |
| 53 | + assert sdist_share.check() |
| 54 | + assert sdist_share.read("rb") == sdist.read("rb"), (sdist_share, sdist) |
| 55 | + |
| 56 | + |
| 57 | +def test_sdistonly(initproj, cmd): |
| 58 | + initproj( |
| 59 | + "example123", |
| 60 | + filedefs={ |
| 61 | + "tox.ini": """ |
| 62 | + """ |
| 63 | + }, |
| 64 | + ) |
| 65 | + result = cmd("-v", "--sdistonly") |
| 66 | + assert not result.ret |
| 67 | + assert re.match(r".*sdist-make.*setup.py.*", result.out, re.DOTALL) |
| 68 | + assert "-mvirtualenv" not in result.out |
| 69 | + |
| 70 | + |
| 71 | +def test_separate_sdist_no_sdistfile(cmd, initproj, tmpdir): |
| 72 | + distshare = tmpdir.join("distshare") |
| 73 | + initproj( |
| 74 | + ("pkg123-foo", "0.7"), |
| 75 | + filedefs={ |
| 76 | + "tox.ini": """ |
| 77 | + [tox] |
| 78 | + distshare={} |
| 79 | + """.format( |
| 80 | + distshare |
| 81 | + ) |
| 82 | + }, |
| 83 | + ) |
| 84 | + result = cmd("--sdistonly") |
| 85 | + assert not result.ret |
| 86 | + distshare_files = distshare.listdir() |
| 87 | + assert len(distshare_files) == 1 |
| 88 | + sdistfile = distshare_files[0] |
| 89 | + assert "pkg123-foo-0.7.zip" in str(sdistfile) |
| 90 | + |
| 91 | + |
| 92 | +def test_separate_sdist(cmd, initproj, tmpdir): |
| 93 | + distshare = tmpdir.join("distshare") |
| 94 | + initproj( |
| 95 | + "pkg123-0.7", |
| 96 | + filedefs={ |
| 97 | + "tox.ini": """ |
| 98 | + [tox] |
| 99 | + distshare={} |
| 100 | + sdistsrc={{distshare}}/pkg123-0.7.zip |
| 101 | + """.format( |
| 102 | + distshare |
| 103 | + ) |
| 104 | + }, |
| 105 | + ) |
| 106 | + result = cmd("--sdistonly") |
| 107 | + assert not result.ret |
| 108 | + sdistfiles = distshare.listdir() |
| 109 | + assert len(sdistfiles) == 1 |
| 110 | + sdistfile = sdistfiles[0] |
| 111 | + result = cmd("-v", "--notest") |
| 112 | + assert not result.ret |
| 113 | + assert "python inst: {}".format(sdistfile) in result.out |
| 114 | + |
| 115 | + |
| 116 | +def test_sdist_latest(tmpdir, newconfig): |
| 117 | + distshare = tmpdir.join("distshare") |
| 118 | + config = newconfig( |
| 119 | + [], |
| 120 | + """ |
| 121 | + [tox] |
| 122 | + distshare={} |
| 123 | + sdistsrc={{distshare}}/pkg123-* |
| 124 | + """.format( |
| 125 | + distshare |
| 126 | + ), |
| 127 | + ) |
| 128 | + p = distshare.ensure("pkg123-1.4.5.zip") |
| 129 | + distshare.ensure("pkg123-1.4.5a1.zip") |
| 130 | + session = Session(config) |
| 131 | + sdist_path = get_package(session) |
| 132 | + assert sdist_path == p |
| 133 | + |
| 134 | + |
| 135 | +def test_installpkg(tmpdir, newconfig): |
| 136 | + p = tmpdir.ensure("pkg123-1.0.zip") |
| 137 | + config = newconfig(["--installpkg={}".format(p)], "") |
| 138 | + session = Session(config) |
| 139 | + sdist_path = get_package(session) |
| 140 | + assert sdist_path == p |
0 commit comments