Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve coverage, fix tests bugs #17742

Merged
merged 2 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions test/integration/lockfile/test_ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,7 @@ def test_single_config_decentralized_overrides():
for elem in level:
for package in elem["packages"][0]: # assumes no dependencies between packages
binary = package["binary"]
if binary != "Build":
continue
assert binary == "Build" # All nodes in this case have to be built
build_args = package["build_args"]
c.run(f"install {build_args} --lockfile=pkgc/conan.lock")

Expand Down
18 changes: 6 additions & 12 deletions test/integration/lockfile/test_ci_overrides.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ def test_graph_build_order_override_error():
for level in to_build["order"]:
for package in level:
binary = package["binary"]
if binary != "Build":
continue
assert binary == "Build" # All nodes in this case have to be built
build_args = package["build_args"]
c.run(f"install {build_args} --lockfile=output.lock")
ref = RecipeReference.loads(package["ref"])
Expand Down Expand Up @@ -83,8 +82,7 @@ def test_graph_build_order_override_replace_requires(replace_pattern):
for level in to_build["order"]:
for package in level:
binary = package["binary"]
if binary != "Build":
continue
assert binary == "Build" # All nodes in this case have to be built
build_args = package["build_args"]
c.run(f"install {build_args} --lockfile=output.lock -pr=profile")
ref = RecipeReference.loads(package["ref"])
Expand Down Expand Up @@ -152,8 +150,7 @@ def test_single_config_decentralized_overrides():
for elem in level:
for package in elem["packages"][0]: # assumes no dependencies between packages
binary = package["binary"]
if binary != "Build":
continue
assert binary == "Build" # All nodes in this case have to be built
build_args = package["build_args"]
c.run(f"install {build_args} --lockfile=pkgc/conan.lock")

Expand Down Expand Up @@ -207,8 +204,7 @@ def test_single_config_decentralized_overrides_nested():
pass
for package in elem["packages"][0]: # assumes no dependencies between packages
binary = package["binary"]
if binary != "Build":
continue
assert binary == "Build" # All nodes in this case have to be built
build_args = package["build_args"]
c.run(f"install {build_args} --lockfile=pkga/conan.lock")

Expand Down Expand Up @@ -291,8 +287,7 @@ def test_single_config_decentralized_overrides_multi(forced):
pass
for package in elem["packages"][0]: # assumes no dependencies between packages
binary = package["binary"]
if binary != "Build":
continue
assert binary == "Build" # All nodes in this case have to be built
build_args = package["build_args"]
c.run(f"install {build_args} --lockfile=pkgc/conan.lock")

Expand Down Expand Up @@ -374,8 +369,7 @@ def test_single_config_decentralized_overrides_multi_replace_requires(replace_pa
pass
for package in elem["packages"][0]: # assumes no dependencies between packages
binary = package["binary"]
if binary != "Build":
continue
assert binary == "Build" # All nodes in this case have to be built
build_args = package["build_args"]
c.run(f"install {build_args} --lockfile=pkgc/conan.lock -pr:b=profile")

Expand Down
28 changes: 8 additions & 20 deletions test/integration/remote/auth_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from requests.models import Response

from conan.internal.api.remotes.localdb import LocalDB
from conan.internal.errors import AuthenticationException
from conan.api.model import RecipeReference
from conan.internal.paths import CONANFILE
from conan.test.assets.genconanfile import GenConanfile
Expand Down Expand Up @@ -143,48 +142,37 @@ def test_authorize_disabled_remote(self):
self.assertIn("Changed user of remote 'default' from 'None' (anonymous) to 'pepe' (authenticated)", tc.out)


class AuthenticationTest(unittest.TestCase):
class TestAuthenticationTest:

def test_unauthorized_during_capabilities(self):

class RequesterMock(TestRequester):

@staticmethod
def get(url, **kwargs):
resp_basic_auth = Response()
resp_basic_auth.status_code = 200
if "authenticate" in url:
if kwargs["auth"].password != "PASSWORD!":
raise Exception("Bad password")
assert kwargs["auth"].password == "PASSWORD!"
resp_basic_auth._content = b"TOKEN"
resp_basic_auth.headers = {"Content-Type": "text/plain"}
elif "ping" in url:
resp_basic_auth.headers = {"Content-Type": "application/json",
"X-Conan-Server-Capabilities": "revisions"}
bearer = getattr(kwargs["auth"], "bearer", None)
password = getattr(kwargs["auth"], "password", None)
if bearer and bearer != "Bearer TOKEN":
raise Exception("Bad JWT Token")
if not bearer and not password:
raise AuthenticationException(
"I'm an Artifactory without anonymous access that "
"requires authentication for the ping endpoint and "
"I don't return the capabilities")
elif "search" in url:
if kwargs["auth"].bearer != "Bearer TOKEN":
raise Exception("Bad JWT Token")
assert bearer == "Bearer TOKEN" or password
else:
assert "search" in url
assert kwargs["auth"].bearer == "Bearer TOKEN"
resp_basic_auth._content = b'{"results": []}'
resp_basic_auth.headers = {"Content-Type": "application/json"}
else:
raise Exception("Shouldn't be more remote calls")
return resp_basic_auth

client = TestClient(requester_class=RequesterMock, default_server_user=True)
client.run("remote login default user -p PASSWORD!")
self.assertIn("Changed user of remote 'default' from 'None' (anonymous) to 'user'",
client.out)
assert "Changed user of remote 'default' from 'None' (anonymous) to 'user'" in client.out
client.run("search pkg -r=default")
self.assertIn("ERROR: Recipe 'pkg' not found", client.out)
assert "ERROR: Recipe 'pkg' not found" in client.out


@pytest.mark.xfail(reason="This test is randomly failing")
Expand Down
35 changes: 4 additions & 31 deletions test/integration/remote/download_retries_test.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,9 @@
import unittest

from conan.internal.paths import CONANFILE
from conan.test.assets.genconanfile import GenConanfile
from conan.test.utils.tools import TestClient, TestServer, TestRequester


class DownloadRetriesTest(unittest.TestCase):

def test_do_not_retry_when_missing_file(self):

test_server = TestServer()
client = TestClient(servers={"default": test_server}, inputs=["admin", "password"])
conanfile = '''from conan import ConanFile
class MyConanfile(ConanFile):
pass
'''
client.save({CONANFILE: conanfile})
client.run("create . --name=pkg --version=0.1 --user=lasote --channel=stable")
client.run("upload '*' -c -r default")
self.assertEqual(str(client.out).count("seconds to retry..."), 0)
class TestDownloadRetries:

def test_recipe_download_retry(self):
test_server = TestServer()
Expand All @@ -28,23 +13,11 @@ def test_recipe_download_retry(self):
client.run("create . --name=pkg --version=0.1 --user=lasote --channel=stable")
client.run("upload '*' -c -r default")

class Response(object):
ok = None
status_code = None
charset = None
headers = {"Content-Type": "application/json"}

class Response:
def __init__(self, ok, status_code):
self.ok = ok
self.status_code = status_code

@property
def content(self):
if not self.ok:
raise Exception("Bad boy")

text = content

class BuggyRequester(TestRequester):
def get(self, *args, **kwargs):
if "files/conanfile.py" not in args[0]:
Expand All @@ -56,5 +29,5 @@ def get(self, *args, **kwargs):
client = TestClient(servers={"default": test_server}, inputs=["admin", "password"],
requester_class=BuggyRequester)
client.run("install --requires=pkg/0.1@lasote/stable", assert_error=True)
self.assertEqual(str(client.out).count("Waiting 0 seconds to retry..."), 2)
self.assertEqual(str(client.out).count("Error 200 downloading"), 3)
assert str(client.out).count("Waiting 0 seconds to retry...") == 2
assert str(client.out).count("Error 200 downloading") == 3
8 changes: 1 addition & 7 deletions test/integration/remote/retry_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,8 @@ def __init__(self, status_code, content):

def raise_for_status(self):
"""Raises stored :class:`HTTPError`, if one occurred."""

http_error_msg = ''
if 400 <= self.status_code < 500:
http_error_msg = u'%s Client Error: %s' % (self.status_code, self.content)

elif 500 <= self.status_code < 600:
if 500 <= self.status_code < 600:
http_error_msg = u'%s Server Error: %s' % (self.status_code, self.content)

if http_error_msg:
Expand All @@ -42,8 +38,6 @@ def put(self, *args, **kwargs):


class _ConfigMock:
def __getitem__(self, item):
return 0

def get(self, conf_name, default=None, check_type=None):
return 0
Expand Down
4 changes: 1 addition & 3 deletions test/integration/symlinks/symlinks_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,7 @@ def package(self):

assert "link.txt" in " ".join(lines)
for line in lines:
if ".txt" not in line:
continue

assert ".txt" in line
size = int([i for i in line.split(" ") if i][2])
if "link.txt" in line:
assert int(size) == 0
Expand Down
12 changes: 6 additions & 6 deletions test/integration/toolchains/gnu/test_makedeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ def package_info(self):

lines = makefile_content.splitlines()
for line_no, line in enumerate(lines):
includedir_pattern = "CONAN_INCLUDE_DIRS_MYLIB = $(CONAN_INCLUDE_DIRS_FLAG)"
includedir_pattern = "CONAN_INCLUDE_DIRS_MYLIB = $(CONAN_INCLUDE_DIR_FLAG)"
if line.startswith(includedir_pattern):
assert os.path.isabs(line[len(includedir_pattern):])
assert line.endswith("include")
elif line.startswith("\t$(CONAN_LIB_DIRS_FLAG)") and 'my_absoulte_path' in line:
assert os.path.isabs(line[len("\t$(CONAN_LIB_DIRS_FLAG)"):-2])
elif line.startswith("\t$(CONAN_LIB_DIR_FLAG)") and 'my_absoulte_path' in line:
assert os.path.isabs(line[len("\t$(CONAN_LIB_DIR_FLAG)"):-2])
assert line.endswith("lib \\")
elif line.startswith("\t$(CONAN_LIB_DIRS_FLAG)") and line.endswith('lib2'):
assert "\t$(CONAN_LIB_DIRS_FLAG)$(CONAN_ROOT_MYLIB)/lib2" in line
elif line.startswith("\t$(CONAN_LIB_DIR_FLAG)") and line.endswith('lib2'):
assert "\t$(CONAN_LIB_DIR_FLAG)$(CONAN_ROOT_MYLIB)/lib2" in line


def test_make_empty_dirs():
Expand Down Expand Up @@ -237,7 +237,7 @@ def package_info(self):
'\t$(CONAN_REQUIRES_SECOND_MYFIRSTCOMP)\n' in makefile_content
assert 'SYSROOT' not in makefile_content
assert 'CONAN_REQUIRES_SECOND_MYFIRSTCOMP = mycomponent\n' in makefile_content
assert 'CONAN_LIBS_LIB = $(CONAN_LIBS_LIB_CMP1)\n'in makefile_content
assert 'CONAN_LIBS_LIB = $(CONAN_LIBS_LIB_CMP1)\n' in makefile_content

assert 'CONAN_COMPONENTS_LIB = cmp1\n' in makefile_content
assert 'CONAN_LIBS_LIB_CMP1 = $(CONAN_LIB_FLAG)libcmp1\n' in makefile_content
Expand Down
5 changes: 1 addition & 4 deletions test/integration/toolchains/microsoft/vcvars_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ class TestConan(ConanFile):


@pytest.mark.skipif(platform.system() != "Windows", reason="Requires Windows")
@pytest.mark.xfail(reason="we dont have vs2015 installed in gh actions")
def test_vcvars_platform_x86():
# https://github.com/conan-io/conan/issues/11144
client = TestClient(path_with_spaces=False)
Expand All @@ -118,16 +117,14 @@ class TestConan(ConanFile):
settings = "os", "compiler", "arch", "build_type"
""")
client.save({"conanfile.py": conanfile})
client.run('install . -s os=Windows -s compiler="msvc" -s compiler.version=190 '
client.run('install . -s os=Windows -s compiler="msvc" -s compiler.version=193 '
'-s compiler.cppstd=14 -s compiler.runtime=static -s:b arch=x86')

vcvars = client.load("conanvcvars.bat")
assert 'vcvarsall.bat" x86_amd64' in vcvars
assert "-vcvars_ver" not in vcvars


@pytest.mark.skipif(platform.system() != "Windows", reason="Requires Windows")
@pytest.mark.xfail(reason="we dont have vs2015 installed in gh actions")
def test_vcvars_winsdk_version():
client = TestClient(path_with_spaces=False)

Expand Down
8 changes: 0 additions & 8 deletions test/integration/toolchains/qbs/test_qbsdeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from conans.util.files import load


@pytest.mark.tool("qbs")
def test_empty_package():
# Checks default values generated by conan for cpp_info
client = TestClient()
Expand Down Expand Up @@ -41,7 +40,6 @@ def test_empty_package():
assert module_content.get('options') == {}


@pytest.mark.tool("qbs")
def test_empty_dirs():
# Checks that we can override default values with empty directories
conanfile = textwrap.dedent('''
Expand Down Expand Up @@ -86,7 +84,6 @@ def package_info(self):
assert module_content.get('options') == {}


@pytest.mark.tool("qbs")
def test_pkg_config_name():
# Checks we can override module name using the "pkg_config_name" property
conanfile = textwrap.dedent('''
Expand All @@ -107,7 +104,6 @@ def package_info(self):
assert os.path.exists(module_path)


@pytest.mark.tool("qbs")
@pytest.mark.parametrize('host_os, arch, build_type', [
('Linux', 'x86_64', 'Debug'),
('Linux', 'x86_64', 'Release'),
Expand Down Expand Up @@ -144,7 +140,6 @@ class Recipe(ConanFile):
assert module_content['settings'].get('build_type') == build_type


@pytest.mark.tool("qbs")
@pytest.mark.parametrize('shared', ['False', 'True'])
def test_options(shared):
conanfile = textwrap.dedent('''
Expand All @@ -170,7 +165,6 @@ class Recipe(ConanFile):
assert module_content['options'].get('shared') == shared


@pytest.mark.tool("qbs")
def test_components():
"""
Checks a package with multiple components.
Expand Down Expand Up @@ -223,7 +217,6 @@ def package_info(self):
]


@pytest.mark.tool("qbs")
def test_cpp_info_requires():
"""
Testing a complex structure like:
Expand Down Expand Up @@ -372,7 +365,6 @@ def package_info(self):


# see https://github.com/conan-io/conan/issues/10341
@pytest.mark.tool("qbs")
def test_components_conflict():
""" If component has the same name as the root package, skip root package
"""
Expand Down
Loading
Loading