2018-05-23 23:06:05 +00:00
|
|
|
import os
|
|
|
|
import io
|
2018-05-24 05:10:50 +00:00
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
2018-05-23 23:06:05 +00:00
|
|
|
from release import cibuild
|
|
|
|
|
|
|
|
|
2018-05-24 05:10:50 +00:00
|
|
|
def test_buildenviron_live():
|
|
|
|
be = cibuild.BuildEnviron.from_env()
|
|
|
|
assert be.release_dir
|
|
|
|
|
|
|
|
|
2018-05-23 23:06:05 +00:00
|
|
|
def test_buildenviron_common():
|
|
|
|
be = cibuild.BuildEnviron(
|
|
|
|
system = "Linux",
|
|
|
|
root_dir = "/foo",
|
|
|
|
|
|
|
|
travis_tag = "v0.0.1",
|
|
|
|
travis_branch = "v0.x",
|
|
|
|
)
|
|
|
|
assert be.release_dir == os.path.join(be.root_dir, "release")
|
|
|
|
assert be.dist_dir == os.path.join(be.root_dir, "release", "dist")
|
|
|
|
assert be.build_dir == os.path.join(be.root_dir, "release", "build")
|
|
|
|
assert be.is_pull_request is False
|
2018-05-24 05:10:50 +00:00
|
|
|
assert not be.has_docker_creds
|
2018-05-23 23:06:05 +00:00
|
|
|
|
|
|
|
cs = io.StringIO()
|
|
|
|
be.dump_info(cs)
|
|
|
|
assert cs.getvalue()
|
|
|
|
|
2018-05-24 05:10:50 +00:00
|
|
|
be = cibuild.BuildEnviron(
|
|
|
|
system = "Unknown",
|
|
|
|
root_dir = "/foo",
|
|
|
|
)
|
|
|
|
with pytest.raises(cibuild.BuildError):
|
|
|
|
be.version
|
|
|
|
with pytest.raises(cibuild.BuildError):
|
|
|
|
be.platform_tag
|
|
|
|
|
2018-05-23 23:06:05 +00:00
|
|
|
|
|
|
|
def test_buildenviron_pr():
|
2018-05-24 10:32:31 +00:00
|
|
|
# Simulates a PR. We build everything, but don't have access to secret
|
|
|
|
# credential env variables.
|
2018-05-23 23:06:05 +00:00
|
|
|
be = cibuild.BuildEnviron(
|
2018-05-24 10:58:33 +00:00
|
|
|
travis_tag = "",
|
|
|
|
travis_branch = "master",
|
2018-05-23 23:06:05 +00:00
|
|
|
travis_pull_request = "true",
|
2018-05-24 10:32:31 +00:00
|
|
|
|
|
|
|
should_build_wheel = True,
|
|
|
|
should_build_pyinstaller = True,
|
|
|
|
should_build_docker = True,
|
2018-05-23 23:06:05 +00:00
|
|
|
)
|
|
|
|
assert be.is_pull_request
|
|
|
|
|
2018-05-24 10:32:31 +00:00
|
|
|
# Mini test for appveyor
|
2018-05-23 23:06:05 +00:00
|
|
|
be = cibuild.BuildEnviron(
|
|
|
|
appveyor_pull_request_number = "xxxx",
|
|
|
|
)
|
|
|
|
assert be.is_pull_request
|
|
|
|
|
|
|
|
|
2018-05-24 09:59:45 +00:00
|
|
|
def test_buildenviron_commit():
|
2018-05-24 10:32:31 +00:00
|
|
|
# Simulates an ordinary commit on the master branch.
|
2018-05-24 09:59:45 +00:00
|
|
|
be = cibuild.BuildEnviron(
|
2018-05-24 10:32:31 +00:00
|
|
|
travis_tag = "",
|
2018-05-24 09:59:45 +00:00
|
|
|
travis_branch = "master",
|
|
|
|
travis_pull_request = "false",
|
2018-05-24 10:32:31 +00:00
|
|
|
|
|
|
|
should_build_wheel = True,
|
|
|
|
should_build_pyinstaller = True,
|
|
|
|
should_build_docker = True,
|
|
|
|
docker_username = "foo",
|
|
|
|
docker_password = "bar",
|
2018-05-24 09:59:45 +00:00
|
|
|
)
|
|
|
|
assert be.docker_tag == "dev"
|
2018-05-24 10:15:55 +00:00
|
|
|
assert be.should_upload_docker
|
|
|
|
assert not be.should_upload_pypi
|
2018-05-24 10:32:31 +00:00
|
|
|
assert be.should_upload_docker
|
2018-05-24 09:59:45 +00:00
|
|
|
|
|
|
|
|
2018-05-24 10:15:55 +00:00
|
|
|
def test_buildenviron_rleasetag():
|
2018-05-24 10:32:31 +00:00
|
|
|
# Simulates a tagged release on a release branch.
|
2018-05-23 23:06:05 +00:00
|
|
|
be = cibuild.BuildEnviron(
|
|
|
|
system = "Linux",
|
|
|
|
root_dir = "/foo",
|
|
|
|
|
|
|
|
travis_tag = "v0.0.1",
|
|
|
|
travis_branch = "v0.x",
|
2018-05-24 10:32:31 +00:00
|
|
|
|
2018-05-24 10:15:55 +00:00
|
|
|
should_build_wheel = True,
|
|
|
|
should_build_docker = True,
|
|
|
|
should_build_pyinstaller = True,
|
|
|
|
has_twine_creds = True,
|
2018-05-24 10:32:31 +00:00
|
|
|
docker_username = "foo",
|
|
|
|
docker_password = "bar",
|
2018-05-23 23:06:05 +00:00
|
|
|
)
|
|
|
|
assert be.tag == "v0.0.1"
|
|
|
|
assert be.branch == "v0.x"
|
|
|
|
assert be.version == "0.0.1"
|
|
|
|
assert be.upload_dir == "0.0.1"
|
2018-05-24 09:59:45 +00:00
|
|
|
assert be.docker_tag == "0.0.1"
|
2018-05-24 10:15:55 +00:00
|
|
|
assert be.should_upload_pypi
|
2018-05-24 10:32:31 +00:00
|
|
|
assert be.should_upload_docker
|
2018-05-23 23:06:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_buildenviron_branch():
|
2018-05-24 10:32:31 +00:00
|
|
|
# Simulates a development branch on the main repo
|
2018-05-23 23:06:05 +00:00
|
|
|
be = cibuild.BuildEnviron(
|
|
|
|
system = "Linux",
|
|
|
|
root_dir = "/foo",
|
|
|
|
|
|
|
|
travis_tag = "",
|
2018-05-24 10:32:31 +00:00
|
|
|
travis_branch = "mybranch",
|
|
|
|
|
|
|
|
should_build_wheel = True,
|
|
|
|
should_build_docker = True,
|
|
|
|
should_build_pyinstaller = True,
|
|
|
|
has_twine_creds = True,
|
|
|
|
docker_username = "foo",
|
|
|
|
docker_password = "bar",
|
2018-05-23 23:06:05 +00:00
|
|
|
)
|
|
|
|
assert be.tag == ""
|
2018-05-24 10:32:31 +00:00
|
|
|
assert be.branch == "mybranch"
|
|
|
|
assert be.version == "mybranch"
|
|
|
|
assert be.upload_dir == "branches/mybranch"
|
|
|
|
assert not be.should_upload_pypi
|
|
|
|
assert not be.should_upload_docker
|
2018-05-23 23:06:05 +00:00
|
|
|
|
|
|
|
|
2018-05-24 05:10:50 +00:00
|
|
|
def test_buildenviron_osx(tmpdir):
|
2018-05-23 23:06:05 +00:00
|
|
|
be = cibuild.BuildEnviron(
|
|
|
|
system = "Darwin",
|
|
|
|
root_dir = "/foo",
|
|
|
|
|
|
|
|
travis_tag = "v0.0.1",
|
|
|
|
travis_branch = "v0.x",
|
|
|
|
)
|
|
|
|
assert be.platform_tag == "osx"
|
|
|
|
assert be.bdists == {
|
|
|
|
"mitmproxy": ["mitmproxy", "mitmdump", "mitmweb"],
|
|
|
|
"pathod": ["pathoc", "pathod"],
|
|
|
|
}
|
|
|
|
assert be.archive_name("mitmproxy") == "mitmproxy-0.0.1-osx.tar.gz"
|
|
|
|
|
2018-05-24 05:10:50 +00:00
|
|
|
a = be.archive(os.path.join(tmpdir, "arch"))
|
|
|
|
assert a
|
|
|
|
a.close()
|
2018-05-23 23:06:05 +00:00
|
|
|
|
2018-05-24 05:10:50 +00:00
|
|
|
|
|
|
|
def test_buildenviron_windows(tmpdir):
|
2018-05-23 23:06:05 +00:00
|
|
|
be = cibuild.BuildEnviron(
|
|
|
|
system = "Windows",
|
|
|
|
root_dir = "/foo",
|
|
|
|
|
|
|
|
travis_tag = "v0.0.1",
|
|
|
|
travis_branch = "v0.x",
|
|
|
|
)
|
|
|
|
assert be.platform_tag == "windows"
|
|
|
|
assert be.bdists == {
|
|
|
|
"mitmproxy": ["mitmdump", "mitmweb"],
|
|
|
|
"pathod": ["pathoc", "pathod"],
|
|
|
|
}
|
2018-05-24 05:10:50 +00:00
|
|
|
assert be.archive_name("mitmproxy") == "mitmproxy-0.0.1-windows.zip"
|
|
|
|
|
|
|
|
a = be.archive(os.path.join(tmpdir, "arch"))
|
|
|
|
assert a
|
|
|
|
a.close()
|