예제 #1
0
def test_recipe_export_pkg(mock_run, mock_inspect):
    # Test call when export_pkg fails.
    recipe = Conan.Recipe("/foobar.py")
    mock_run.returncode = 1
    output = io.StringIO()
    with redirect_stdout(output):
        with pytest.raises(ValueError):
            recipe.export_pkg("bar",
                              "testing",
                              profiles=['a.p'],
                              pkg_folder="/tmp/pkg",
                              cwd="/ab")
    assert (
        "[/ab] $ conan export-pkg /foobar.py ConanTools/0.1.1-post7+ga21edb7f08@bar/testing "
        "--package-folder=/tmp/pkg --profile a.p --force"
    ) == output.getvalue().strip()

    # Test call when export_pkg succeeds.
    recipe = Conan.Recipe("foobar.py", cwd="/tmp")
    mock_run.returncode = 0
    output = io.StringIO()
    with redirect_stdout(output):
        recipe.export_pkg("bar",
                          "testing",
                          version="5.6.8",
                          options={"key": True},
                          pkg_folder="/tmp/pkg",
                          cwd="/tmp/_build",
                          force=False)
    assert (
        "[/tmp/_build] $ conan export-pkg /tmp/foobar.py ConanTools/5.6.8@bar/testing "
        "--package-folder=/tmp/pkg -o key=True") in output.getvalue()
예제 #2
0
def test_get_recipe_field(mocker, mock_inspect):
    assert Conan.get_recipe_field("does_not_exist.py", "name") is None

    mocker.patch('os.path.exists', return_value=True)
    assert Conan.get_recipe_field("a.py", "name") == "ConanTools"
    assert Conan.get_recipe_field("a.py",
                                  "version") == "0.1.1-post7+ga21edb7f08"
예제 #3
0
    def install(self,
                remote=None,
                profiles=[],
                options={},
                build=["outdated"],
                cwd=None):
        # write a conanfile in txt format with the package ids the imports
        config = configparser.ConfigParser(allow_no_value=True)
        config.optionxform = str
        config["requires"] = {x: None for x in self._package_ids.values()}
        config["imports"] = {
            "., * -> . @ root_package={}".format(x): None
            for x in self._package_ids.keys()
        }
        with open(self._file_name, 'w') as configfile:
            config.write(configfile)

        args = Conan.fmt_build_args("install", [self._file_name],
                                    remote=remote,
                                    profiles=profiles,
                                    options=options,
                                    build=build)
        Conan.run(args, cwd=cwd)

        # remove conan packaging metadata files
        cwd = os.path.abspath(cwd if cwd is not None else os.getcwd())
        files = glob.glob(os.path.join(cwd, "conan*"))
        files += glob.glob(os.path.join(cwd, "graph_info.json"))
        for f in files:
            os.remove(f)
예제 #4
0
def test_recipe_create(mock_run, mock_inspect):
    # Test call when create fails.
    recipe = Conan.Recipe("/foobar.py")
    mock_run.returncode = 1
    output = io.StringIO()
    with redirect_stdout(output):
        with pytest.raises(ValueError):
            recipe.create("bar",
                          "testing",
                          remote="baz",
                          profiles=['a.p'],
                          cwd="/foo/fizz")
    assert (
        "[/foo/fizz] $ conan create /foobar.py ConanTools/0.1.1-post7+ga21edb7f08@bar/testing "
        "--profile a.p --build outdated --remote baz"
    ) == output.getvalue().strip()

    # Test call when create succeeds.
    recipe = Conan.Recipe("foobar.py", cwd="/tmp")
    mock_run.returncode = 0
    output = io.StringIO()
    with redirect_stdout(output):
        recipe.create("bar",
                      "testing",
                      version="5.6.8",
                      build="foo",
                      options={"key": True})
    assert "$ conan create /tmp/foobar.py ConanTools/5.6.8@bar/testing --build foo -o key=True" \
        in output.getvalue()
예제 #5
0
def test_recipe_get_field(mock_inspect):
    recipe = Conan.Recipe("foobar.py")
    assert recipe.get_field("name") == "ConanTools"
    assert recipe.get_field("version") == "0.1.1-post7+ga21edb7f08"
    assert recipe.get_field("url") == "https://github.com/niosHD/ConanTools"
    assert recipe.get_field("license") == "MIT"

    recipe = Conan.Recipe("foobar.py", cwd="/tmp")
    assert recipe.get_field("generators") == ["txt"]
예제 #6
0
def write_helper_scripts(filedir: str,
                         recipe_path: str,
                         src_folder: str = None,
                         build_folder: str = None,
                         pkg_folder: str = None):
    """Generate helper shell scripts for executing the build and package stage.
    """
    Conan.write_conan_sh_file(filedir, "build", [
        "build", recipe_path, "--source-folder=" + src_folder,
        "--package-folder=" + pkg_folder
    ], build_folder)
    Conan.write_conan_sh_file(
        filedir, "package",
        ["package", recipe_path, "--package-folder=" + pkg_folder],
        build_folder)
예제 #7
0
def test_recipe_export(mock_run, mock_inspect):
    # Test call when export fails.
    recipe = Conan.Recipe("/foobar.py")
    mock_run.returncode = 1
    output = io.StringIO()
    with redirect_stdout(output):
        with pytest.raises(ValueError):
            recipe.export("foo", "testing", version="1.1.1")
    assert "$ conan export /foobar.py ConanTools/1.1.1@foo/testing" in output.getvalue(
    )

    # Test call when export succeeds.
    recipe = Conan.Recipe("foobar.py", cwd="/tmp")
    mock_run.returncode = 0
    output = io.StringIO()
    with redirect_stdout(output):
        recipe.export("bar", "testing", version="1.1.1")
    assert "$ conan export /tmp/foobar.py ConanTools/1.1.1@bar/testing" in output.getvalue(
    )
예제 #8
0
def test_recipe_source(mock_run):
    # Test call when install fails.
    recipe = Conan.Recipe("/foobar.py")
    mock_run.returncode = 1
    output = io.StringIO()
    with redirect_stdout(output):
        with pytest.raises(ValueError):
            recipe.source(src_folder="/src", build_folder="/build")
    assert ("[/build] $ conan source /foobar.py "
            "--source-folder=/src") == output.getvalue().strip()

    # Test call when source succeeds.
    recipe = Conan.Recipe("foobar.py", cwd="/tmp")
    mock_run.returncode = 0
    output = io.StringIO()
    with redirect_stdout(output):
        recipe.source(src_folder="src")
    assert ("[/tmp/_build] $ conan source /tmp/foobar.py "
            "--source-folder=src") == output.getvalue().strip()
예제 #9
0
def test_reference_string_formatting_and_clone():
    ref = Conan.Reference("foo", "1.2.3", "bar", "testing")
    assert str(ref) == "foo/1.2.3@bar/testing"

    # Test cloning and formatting for cloned references.
    cpy = ref.clone(name="bla")
    assert ref is not cpy
    assert str(cpy) == "bla/1.2.3@bar/testing"

    # Ensure that the original reference has not been modified.
    assert str(ref) == "foo/1.2.3@bar/testing"
예제 #10
0
def test_recipe_reference(mock_inspect):
    recipe = Conan.Recipe("foobar.py")
    ref = recipe.reference("foo", "testing")
    assert ref.name == "ConanTools"
    assert ref.version == "0.1.1-post7+ga21edb7f08"
    assert ref.user == "foo"
    assert ref.channel == "testing"

    ref = recipe.reference("foo", "testing", name="pkg", version="1.2.3")
    assert ref.name == "pkg"
    assert ref.version == "1.2.3"
예제 #11
0
def test_recipe_build(mock_run, mock_inspect):
    # Test call when build fails.
    recipe = Conan.Recipe("/foobar.py")
    mock_run.returncode = 1
    output = io.StringIO()
    with redirect_stdout(output):
        with pytest.raises(ValueError):
            recipe.build(src_folder="/src",
                         build_folder="/build",
                         pkg_folder="/pkg")
    assert ("[/build] $ conan build /foobar.py --source-folder=/src "
            "--package-folder=/pkg") == output.getvalue().strip()

    # Test call when build succeeds.
    recipe = Conan.Recipe("foobar.py", cwd="/tmp")
    mock_run.returncode = 0
    output = io.StringIO()
    with redirect_stdout(output):
        recipe.build()
    assert ("[/tmp/_build] $ conan build /tmp/foobar.py --source-folder=/tmp "
            "--package-folder=/tmp/_install") == output.getvalue().strip()
예제 #12
0
def test_recipe_install(mock_run):
    # Test call when install fails.
    recipe = Conan.Recipe("/foobar.py")
    mock_run.returncode = 1
    output = io.StringIO()
    with redirect_stdout(output):
        with pytest.raises(ValueError):
            recipe.install(build_folder="/build",
                           profiles=['a.p'],
                           options={"key": True},
                           remote="baz")
    assert ("[/build] $ conan install /foobar.py "
            "--profile a.p --build outdated --remote baz -o key=True"
            ) == output.getvalue().strip()

    # Test call when install succeeds.
    recipe = Conan.Recipe("foobar.py", cwd="/tmp")
    mock_run.returncode = 0
    output = io.StringIO()
    with redirect_stdout(output):
        recipe.install()
    assert ("[/tmp/_build] $ conan install /tmp/foobar.py "
            "--build outdated") == output.getvalue().strip()
예제 #13
0
def test_reference_in_local_cache(mock_run):
    ref = Conan.Reference("foo", "1.2.3", "bar", "testing")

    # Test call when reference is not in the local cache.
    mock_run.returncode = 1
    output = io.StringIO()
    with redirect_stdout(output):
        assert ref.in_local_cache() is False
    assert "$ conan search foo/1.2.3@bar/testing" in output.getvalue()

    # Test call when reference is in the local cache.
    mock_run.returncode = 0
    output = io.StringIO()
    with redirect_stdout(output):
        assert ref.in_local_cache() is True
    assert "$ conan search foo/1.2.3@bar/testing" in output.getvalue()
예제 #14
0
def test_reference_set_remote(mock_run):
    ref = Conan.Reference("foo", "1.2.3", "bar", "testing")

    # Test call when the remote could not be set.
    mock_run.returncode = 1
    output = io.StringIO()
    with redirect_stdout(output):
        with pytest.raises(ValueError):
            ref.set_remote(remote="baz")
    assert "$ conan remote add_ref foo/1.2.3@bar/testing baz" in output.getvalue(
    )

    # Test call when the remote could not be set.
    mock_run.returncode = 0
    output = io.StringIO()
    with redirect_stdout(output):
        ref.set_remote(remote="baz")
    assert "$ conan remote add_ref foo/1.2.3@bar/testing baz" in output.getvalue(
    )
예제 #15
0
def test_reference_download_recipe(mock_run):
    ref = Conan.Reference("foo", "1.2.3", "bar", "testing")

    # Test call when recipe could not be downloaded.
    mock_run.returncode = 1
    output = io.StringIO()
    with redirect_stdout(output):
        with pytest.raises(ValueError):
            ref.download_recipe()
    assert "$ conan download foo/1.2.3@bar/testing --recipe" in output.getvalue(
    )

    # Test call when recipe could be downloaded.
    mock_run.returncode = 0
    output = io.StringIO()
    with redirect_stdout(output):
        ref.download_recipe("bar")
    assert "$ conan download foo/1.2.3@bar/testing --recipe --remote bar" in output.getvalue(
    )
예제 #16
0
def test_reference_upload_all(mock_run):
    ref = Conan.Reference("foo", "1.2.3", "bar", "testing")

    # Test call when the package could not be uploaded.
    mock_run.returncode = 1
    output = io.StringIO()
    with redirect_stdout(output):
        with pytest.raises(ValueError):
            ref.upload_all(remote="baz")
    assert "$ conan upload foo/1.2.3@bar/testing --remote baz --all -c" in output.getvalue(
    )

    # Test call when the package could be uploaded.
    mock_run.returncode = 0
    output = io.StringIO()
    with redirect_stdout(output):
        ref.upload_all(remote="baz")
    assert "$ conan upload foo/1.2.3@bar/testing --remote baz --all -c" in output.getvalue(
    )
예제 #17
0
def test_recipe_create_local(mock_run, mock_inspect):
    # Test call when export_pkg fails.
    recipe = Conan.Recipe("/foobar.py", external_source=True)
    mock_run.returncode = 0
    output = io.StringIO()
    with redirect_stdout(output):
        recipe.create_local("user", "channel")
    commands = output.getvalue().strip().splitlines()
    assert "[/_build] $ conan install /foobar.py --build outdated" == commands[
        0]
    assert "[/_build] $ conan source /foobar.py --source-folder=/_source" == commands[
        1]
    assert ("[/_build] $ conan build /foobar.py --source-folder=/_source "
            "--package-folder=/_install") == commands[2]
    assert ("[/_build] $ conan package /foobar.py --source-folder=/_source "
            "--package-folder=/_install") == commands[3]
    assert (
        "$ conan export-pkg /foobar.py ConanTools/0.1.1-post7+ga21edb7f08@user/channel "
        "--package-folder=/_install") in commands[4]
예제 #18
0
def test_reference_create_alias(mock_run):
    ref = Conan.Reference("foo", "1.2.3", "bar", "testing")

    # Test call when the alias could not be created.
    mock_run.returncode = 1
    output = io.StringIO()
    with redirect_stdout(output):
        with pytest.raises(ValueError):
            ref.create_alias(version="develop", user="******")
    assert "$ conan alias foo/develop@baz/testing foo/1.2.3@bar/testing" in output.getvalue(
    )

    # Test call when the alias could not be created.
    mock_run.returncode = 0
    output = io.StringIO()
    with redirect_stdout(output):
        alias = ref.create_alias(version="develop", user="******")
    assert "$ conan alias foo/develop@baz/testing foo/1.2.3@bar/testing" in output.getvalue(
    )
    assert alias is not ref
예제 #19
0
def test_reference_install(mock_run):
    ref = Conan.Reference("foo", "1.2.3", "bar", "testing")

    # Test call when the package could not be installed.
    mock_run.returncode = 1
    output = io.StringIO()
    with redirect_stdout(output):
        with pytest.raises(ValueError):
            ref.install(remote="baz",
                        profiles=['a.p'],
                        options={"key": True},
                        cwd="/foo/bar")
    assert ("[/foo/bar] $ conan install foo/1.2.3@bar/testing "
            "--profile a.p --build outdated --remote baz -o key=True"
            ) == output.getvalue().strip()

    # Test call when the package could be installed.
    mock_run.returncode = 0
    output = io.StringIO()
    with redirect_stdout(output):
        ref.install(build="foo")
    assert "$ conan install foo/1.2.3@bar/testing --build foo" in output.getvalue(
    )
예제 #20
0
# Setup the default configuration but permit to override the configuration
# variables via the command line.
BINTRAY_API_KEY = os.environ[
    "BINTRAY_API_KEY"]  # has to be defined in environment
BINTRAY_USER = os.environ.get("BINTRAY_USER", "nioshd")
CONAN_USER = os.environ.get("CONAN_USER", BINTRAY_USER)
CONAN_CHANNEL = os.environ.get("CONAN_CHANNEL",
                               "stable" if ConanTools.Git.tag() else "testing")
CONAN_REMOTE_NAME = os.environ.get("CONAN_REMOTE_NAME",
                                   "bintray_{}".format(BINTRAY_USER))

# Add the bintray remote and authenticate against it.
CONAN_REMOTE_URL = "https://api.bintray.com/conan/{}/conan".format(
    BINTRAY_USER)
Conan.run(
    ["remote", "add", CONAN_REMOTE_NAME, CONAN_REMOTE_URL, "--insert", "0"])
Conan.run(
    ["user", BINTRAY_USER, "-p", BINTRAY_API_KEY, "-r", CONAN_REMOTE_NAME])

# Build the package.
ref = Conan.Recipe("conanfile.py").create(user=CONAN_USER,
                                          channel=CONAN_CHANNEL)

# Upload the built package and recipe.
ref.upload_all(CONAN_REMOTE_NAME)

# Create an additional alias with the branch name slug and upload it too.
BRANCH_SLUG = ConanTools.slug(ConanTools.Git.branch())
if BRANCH_SLUG:
    alias_ref = ref.create_alias(version=BRANCH_SLUG)
    alias_ref.upload_all(CONAN_REMOTE_NAME)