Skip to content

Commit 68e03bb

Browse files
authored
Test/test (#17803)
* wip * faster tests * wip * wip * fix * fixes * fix tests
1 parent 8488bcb commit 68e03bb

File tree

10 files changed

+141
-198
lines changed

10 files changed

+141
-198
lines changed

conan/api/model/list.py

-8
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ class MultiPackagesList:
1616
def __init__(self):
1717
self.lists = {}
1818

19-
def setdefault(self, key, default):
20-
return self.lists.setdefault(key, default)
21-
2219
def __getitem__(self, name):
2320
try:
2421
return self.lists[name]
@@ -57,11 +54,6 @@ def load(file):
5754
pkglist.lists = result
5855
return pkglist
5956

60-
@staticmethod
61-
def from_graph(graph, graph_recipes=None, graph_binaries=None):
62-
graph = {"graph": graph.serialize()}
63-
return MultiPackagesList._define_graph(graph, graph_recipes, graph_binaries)
64-
6557
@staticmethod
6658
def load_graph(graphfile, graph_recipes=None, graph_binaries=None):
6759
if not os.path.isfile(graphfile):

conan/test/utils/profiles.py

+1-19
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@
55
from conans.util.files import save
66

77

8-
def create_profile(folder, name, settings=None, package_settings=None, env=None,
9-
package_env=None, options=None, conf=None):
10-
11-
package_env = package_env or {}
12-
8+
def create_profile(folder, name, settings=None, package_settings=None, options=None):
139
profile = Profile()
1410
profile.settings = settings or {}
1511

@@ -19,18 +15,4 @@ def create_profile(folder, name, settings=None, package_settings=None, env=None,
1915
if options:
2016
profile.options = Options(options_values=options)
2117

22-
if conf:
23-
_conf = "\n".join(conf) if isinstance(conf, list) else conf
24-
profile.conf.loads(_conf)
25-
26-
"""for package_name, envs in package_env.items():
27-
for var_name, value in envs:
28-
# Initialize Environment without Conanfile, what else can we do
29-
profile._environments.set_default(package_name, Environment(conanfile=None))\
30-
.define(var_name, value)
31-
32-
for var_name, value in env or {}:
33-
profile._environments.set_default(None, Environment(conanfile=None)) \
34-
.define(var_name, value)"""
35-
3618
save(os.path.join(folder, name), profile.dumps())

conan/test/utils/tools.py

+10-58
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,16 @@
88
import socket
99
import sys
1010
import textwrap
11-
import threading
12-
import time
1311
import traceback
1412
import uuid
1513
import zipfile
1614
from collections import OrderedDict
1715
from contextlib import contextmanager
16+
from inspect import getframeinfo, stack
1817
from urllib.parse import urlsplit, urlunsplit
1918

20-
import bottle
2119
import mock
20+
import pytest
2221
import requests
2322
from mock import Mock
2423
from requests.exceptions import HTTPError
@@ -35,11 +34,8 @@
3534
from conan.cli.cli import Cli, _CONAN_INTERNAL_CUSTOM_COMMANDS_PATH
3635
from conan.test.utils.env import environment_update
3736
from conan.internal.errors import NotFoundException
38-
from conan.internal.model.manifest import FileTreeManifest
3937
from conan.api.model import PkgReference
40-
from conan.internal.model.profile import Profile
4138
from conan.api.model import RecipeReference
42-
from conan.internal.model.settings import Settings
4339
from conan.test.assets.genconanfile import GenConanfile
4440
from conan.test.utils.artifactory import ArtifactoryServer
4541
from conan.test.utils.mocks import RedirectedInputStream
@@ -83,28 +79,6 @@
8379
""")
8480
}
8581

86-
def inc_recipe_manifest_timestamp(cache, reference, inc_time):
87-
ref = RecipeReference.loads(reference)
88-
path = cache.get_latest_recipe_reference(ref).export()
89-
manifest = FileTreeManifest.load(path)
90-
manifest.time += inc_time
91-
manifest.save(path)
92-
93-
94-
def inc_package_manifest_timestamp(cache, package_reference, inc_time):
95-
path = cache.get_latest_package_reference(package_reference).package()
96-
manifest = FileTreeManifest.load(path)
97-
manifest.time += inc_time
98-
manifest.save(path)
99-
100-
101-
def create_profile(profile=None, settings=None):
102-
if profile is None:
103-
profile = Profile()
104-
if profile.processed_settings is None:
105-
profile.processed_settings = settings or Settings()
106-
return profile
107-
10882

10983
class TestingResponse(object):
11084
"""Wraps a response from TestApp external tool
@@ -629,15 +603,15 @@ def _handle_cli_result(self, command, assert_error, error, trace=None):
629603
msg = " Command succeeded (failure expected): "
630604
else:
631605
msg = " Command failed (unexpectedly): "
632-
exc_message = "\n{header}\n{cmd}\n{output_header}\n{output}\n".format(
633-
header='{:=^80}'.format(msg),
634-
output_header='{:=^80}'.format(" Output: "),
635-
cmd=command,
636-
output=str(self.stderr) + str(self.stdout) + "\n" + str(self.out)
637-
)
606+
607+
output = str(self.stderr) + str(self.stdout) + "\n"
608+
exc_message = f"\n{msg:=^80}\n{command}\n{' Output: ':=^80}\n{output}\n"
638609
if trace:
639-
exc_message += '{:=^80}'.format(" Traceback: ") + f"\n{trace}"
640-
raise Exception(exc_message)
610+
exc_message += f'{" Traceback: ":=^80}\n{trace}'
611+
612+
caller = getframeinfo(stack()[3][0])
613+
exc_message = f"{caller.filename}:{caller.lineno}" + exc_message
614+
pytest.fail(exc_message, pytrace=False)
641615

642616
def save(self, files, path=None, clean_first=False):
643617
""" helper metod, will store files in the current folder
@@ -853,28 +827,6 @@ def get_free_port():
853827
return ret
854828

855829

856-
class StoppableThreadBottle(threading.Thread):
857-
"""
858-
Real server to test download endpoints
859-
"""
860-
861-
def __init__(self, host=None, port=None):
862-
self.host = host or "127.0.0.1"
863-
self.server = bottle.Bottle()
864-
self.port = port or get_free_port()
865-
super(StoppableThreadBottle, self).__init__(target=self.server.run,
866-
kwargs={"host": self.host, "port": self.port})
867-
self.daemon = True
868-
self._stop = threading.Event()
869-
870-
def stop(self):
871-
self._stop.set()
872-
873-
def run_server(self):
874-
self.start()
875-
time.sleep(1)
876-
877-
878830
def zipdir(path, zipfilename):
879831
with zipfile.ZipFile(zipfilename, 'w', zipfile.ZIP_DEFLATED) as z:
880832
for root, _, files in os.walk(path):

test/functional/toolchains/cmake/test_cmake_and_no_soname_flag.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ def test_no_soname_flag(nosoname_property):
6464
# If `nosoname_property` is False, and we have a library without the SONAME flag,
6565
# then it should fail
6666
if nosoname_property is False:
67-
with pytest.raises(Exception, match=r"libnosoname.so: cannot open shared object "
68-
r"file: No such file or directory"):
69-
client.run_command(command)
67+
client.run_command(command, assert_error=True)
68+
assert "libnosoname.so: cannot open shared object file: " \
69+
"No such file or directory" in client.out
7070
else:
7171
client.run_command(command)
7272
assert "nosoname/0.1: Hello World Release!" in client.out

test/functional/tools/scm/test_git.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -596,9 +596,8 @@ def test_clone_invalid_branch_argument(self):
596596
c = TestClient()
597597
git_args = ['--branch', 'foobar']
598598
c.save({"conanfile.py": self.conanfile.format(url=url, commit=commit, args=str(git_args))})
599-
with pytest.raises(Exception):
600-
c.run("create .")
601-
assert "Remote branch foobar not found" in c.out
599+
c.run("create .", assert_error=True)
600+
assert "Remote branch foobar not found" in c.out
602601

603602

604603
@pytest.mark.tool("git")

0 commit comments

Comments
 (0)