From d6ff9e57dda4ecc7199ad1875147aedee60f812e Mon Sep 17 00:00:00 2001 From: Uilian Ries Date: Wed, 14 Nov 2018 13:11:15 -0200 Subject: [PATCH] Fix Upload only when stable Signed-off-by: Uilian Ries --- bincrafters/__init__.py | 2 +- bincrafters/build_shared.py | 6 +++++- tests/test_package_tools.py | 29 +++++++++++++++++++++++------ 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/bincrafters/__init__.py b/bincrafters/__init__.py index 921c447..98e595c 100644 --- a/bincrafters/__init__.py +++ b/bincrafters/__init__.py @@ -1 +1 @@ -__version__ = '0.17.5' +__version__ = '0.17.6' diff --git a/bincrafters/build_shared.py b/bincrafters/build_shared.py index e63213d..e654593 100644 --- a/bincrafters/build_shared.py +++ b/bincrafters/build_shared.py @@ -8,6 +8,10 @@ from cpt.tools import split_colon_env +def get_bool_from_env(var_name, default="1"): + val = os.getenv(var_name, default) + return str(val).lower() in ("1", "true", "yes", "y") + def get_value_from_recipe(search_string, recipe="conanfile.py"): with open(recipe, "r") as conanfile: contents = conanfile.read() @@ -114,7 +118,7 @@ def get_conan_remotes(username): def get_upload_when_stable(): - return os.getenv("CONAN_UPLOAD_ONLY_WHEN_STABLE", True) + return get_bool_from_env("CONAN_UPLOAD_ONLY_WHEN_STABLE") def get_os(): diff --git a/tests/test_package_tools.py b/tests/test_package_tools.py index de2b22c..3d4b909 100644 --- a/tests/test_package_tools.py +++ b/tests/test_package_tools.py @@ -1,15 +1,15 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +import os +import platform +import pytest from bincrafters import build_shared from bincrafters import build_template_boost_default from bincrafters import build_template_boost_header_only from bincrafters import build_template_default from bincrafters import build_template_header_only from bincrafters import build_template_installer -import os -import platform -import pytest @pytest.fixture(autouse=True) @@ -31,6 +31,13 @@ def set_minimal_build_environment(): del os.environ["CONAN_BUILD_TYPES"] +@pytest.fixture() +def set_upload_when_stable_false(): + os.environ["CONAN_UPLOAD_ONLY_WHEN_STABLE"] = "0" + yield + del os.environ["CONAN_UPLOAD_ONLY_WHEN_STABLE"] + + def test_build_template_boost_default(): builder = build_template_boost_default.get_builder() @@ -47,7 +54,7 @@ def test_build_template_boost_default(): elif platform.system() == "Darwin": assert 4 == len(builder.items) - assert builder.upload_only_when_stable == "" + assert False == builder.upload_only_when_stable def test_build_template_default(): @@ -64,7 +71,7 @@ def test_build_template_default(): elif platform.system() == "Darwin": assert 4 == len(builder.items) - assert builder.upload_only_when_stable + assert True == builder.upload_only_when_stable def test_build_template_default_minimal(set_minimal_build_environment): @@ -118,7 +125,7 @@ def test_build_boost_header_only(): for settings, options, env_vars, build_requires, reference in builder.items: assert 0 == len(options) assert 1 == len(builder.items) - assert builder.upload_only_when_stable == "" + assert builder.upload_only_when_stable == False def test_get_os(): @@ -144,3 +151,13 @@ def test_build_policy_set_in_args(): def test_build_policy_set_header_only(): builder = build_template_header_only.get_builder(build_policy='missing') assert 'missing' == builder.build_policy + + +def test_upload_only_when_stable_builder(set_upload_when_stable_false): + builder = build_template_default.get_builder() + assert False == builder.upload_only_when_stable + + +def test_upload_only_when_stable_header_only(set_upload_when_stable_false): + builder = build_template_header_only.get_builder() + assert False == builder.upload_only_when_stable \ No newline at end of file