diff --git a/conans/test/integration/command/upload/upload_complete_test.py b/conans/test/integration/command/upload/upload_complete_test.py index c985d00e2cb..ff9e20b6272 100644 --- a/conans/test/integration/command/upload/upload_complete_test.py +++ b/conans/test/integration/command/upload/upload_complete_test.py @@ -1,16 +1,12 @@ -import json import os -import textwrap import unittest -import pytest from requests import ConnectionError from conans.paths import CONAN_MANIFEST -from conans.test.utils.tools import (NO_SETTINGS_PACKAGE_ID, TestClient, TestRequester, TestServer, +from conans.test.utils.tools import (TestClient, TestRequester, TestServer, GenConanfile) from conans.util.env import environment_update -from conans.util.files import load class BadConnectionUploader(TestRequester): @@ -242,75 +238,3 @@ def test_upload_same_package_dont_compress(self): client.run("upload foo/1.0 -r default") self.assertNotIn("Compressing", client.out) self.assertIn("already in server, skipping upload", client.out) - - @pytest.mark.xfail(reason="No output json available yet for upload. Also old test, has to be " - "upgraded") - def test_upload_json(self): - conanfile = textwrap.dedent(""" - from conan import ConanFile - from conan.tools.files import copy - - class TestConan(ConanFile): - name = "test" - version = "0.1" - - def package(self): - copy(self, "mylib.so", self.build_folder, os.path.join(self.package_folder, "lib")) - """) - - client = self._get_client() - client.save({"conanfile.py": conanfile, - "mylib.so": ""}) - client.run("create . danimtb/testing") - - # Test conflict parameter error - client.run("upload test/0.1@danimtb/* -p ewvfw --json upload.json", assert_error=True) - - json_path = os.path.join(client.current_folder, "upload.json") - self.assertTrue(os.path.exists(json_path)) - json_content = load(json_path) - output = json.loads(json_content) - self.assertTrue(output["error"]) - self.assertEqual(0, len(output["uploaded"])) - - # Test invalid reference error - client.run("upload fake/0.1@danimtb/testing --json upload.json", assert_error=True) - json_path = os.path.join(client.current_folder, "upload.json") - self.assertTrue(os.path.exists(json_path)) - json_content = load(json_path) - output = json.loads(json_content) - self.assertTrue(output["error"]) - self.assertEqual(0, len(output["uploaded"])) - - # Test normal upload - client.run("upload test/0.1@danimtb/testing --json upload.json") - self.assertTrue(os.path.exists(json_path)) - json_content = load(json_path) - output = json.loads(json_content) - output_expected = {"error": False, - "uploaded": [ - { - "recipe": { - "id": "test/0.1@danimtb/testing", - "remote_url": "unknown", - "remote_name": "default", - "time": "unknown" - }, - "packages": [ - { - "id": NO_SETTINGS_PACKAGE_ID, - "time": "unknown" - } - ] - } - ]} - self.assertEqual(output_expected["error"], output["error"]) - self.assertEqual(len(output_expected["uploaded"]), len(output["uploaded"])) - - for i, item in enumerate(output["uploaded"]): - self.assertEqual(output_expected["uploaded"][i]["recipe"]["id"], item["recipe"]["id"]) - self.assertEqual(output_expected["uploaded"][i]["recipe"]["remote_name"], - item["recipe"]["remote_name"]) - for j, subitem in enumerate(item["packages"]): - self.assertEqual(output_expected["uploaded"][i]["packages"][j]["id"], - subitem["id"]) diff --git a/conans/test/integration/cross_building/build_requires_from_profile_test.py b/conans/test/integration/cross_building/build_requires_from_profile_test.py index 208b38cbcf2..b2fbba458af 100644 --- a/conans/test/integration/cross_building/build_requires_from_profile_test.py +++ b/conans/test/integration/cross_building/build_requires_from_profile_test.py @@ -1,8 +1,6 @@ import unittest import textwrap -import pytest - from conans.test.utils.tools import TestClient, GenConanfile @@ -109,7 +107,6 @@ def build(self): os = Windows """) - @pytest.mark.xfail(reason="cache2.0 revisit test") def test_br_from_profile_host_and_profile_build(self): t = TestClient() t.save({'profile_host': self.profile_host, @@ -117,30 +114,23 @@ def test_br_from_profile_host_and_profile_build(self): 'library.py': self.library_conanfile, 'mytoolchain.py': self.toolchain, "gtest.py": self.gtest}) - t.run("create mytoolchain.py --profile=profile_build") - t.run("create mytoolchain.py --profile=profile_host") - - # old way, the toolchain will have the same profile (profile_host=Linux) only - t.run("create gtest.py --profile:host=profile_host --profile:build=profile_host") - self.assertIn("mytoolchain/1.0: PackageInfo OS=Linux", t.out) - self.assertIn("gtest/1.0: Build OS=Linux", t.out) + t.run("create mytoolchain.py -pr:h=profile_host -pr:b=profile_build --build-require") - # new way, the toolchain can now run in Windows, but gtest in Linux - t.run("create gtest.py --profile=profile_host --profile:build=profile_build") + t.run("create gtest.py -pr=profile_host -pr:b=profile_build") self.assertIn("mytoolchain/1.0: PackageInfo OS=Windows", t.out) self.assertIn("gtest/1.0: PackageInfo OS=Linux", t.out) - t.run("create gtest.py --profile=profile_host --profile:build=profile_build --build") + t.run("create gtest.py -pr=profile_host -pr:b=profile_build --build=*") self.assertIn("mytoolchain/1.0: PackageInfo OS=Windows", t.out) self.assertIn("gtest/1.0: Build OS=Linux", t.out) self.assertIn("gtest/1.0: PackageInfo OS=Linux", t.out) - t.run("create library.py --profile:host=profile_host --profile:build=profile_build") + t.run("create library.py -pr:h=profile_host -pr:b=profile_build") self.assertIn("gtest/1.0: PackageInfo OS=Linux", t.out) self.assertIn("library/version: Build OS=Linux", t.out) self.assertIn("mytoolchain/1.0: PackageInfo OS=Windows", t.out) - t.run("create library.py --profile:host=profile_host --profile:build=profile_build --build") + t.run("create library.py -pr:h=profile_host -pr:b=profile_build --build=*") self.assertIn("gtest/1.0: Build OS=Linux", t.out) self.assertIn("gtest/1.0: PackageInfo OS=Linux", t.out) self.assertIn("library/version: Build OS=Linux", t.out) @@ -212,10 +202,9 @@ def build(self): [settings] os = Windows [tool_requires] - creator/1.0 + mytoolchain*:creator/1.0 """) - @pytest.mark.xfail(reason="cache2.0 revisit test") def test_build_requires_both_contexts(self): t = TestClient() t.save({'profile_host': self.profile_host, @@ -224,8 +213,8 @@ def test_build_requires_both_contexts(self): 'creator.py': self.toolchain_creator, 'mytoolchain.py': self.toolchain, "gtest.py": self.gtest}) - t.run("create creator.py --profile=profile_build -pr:b=profile_build") - t.run("create mytoolchain.py --profile:host=profile_build -pr:b=profile_build") + t.run("create creator.py -pr=profile_build") + t.run("create mytoolchain.py -pr:h=profile_host -pr:b=profile_build --build-require") self.assertIn("creator/1.0: PackageInfo OS=Windows", t.out) self.assertIn("mytoolchain/1.0: Build OS=Windows", t.out) @@ -234,7 +223,7 @@ def test_build_requires_both_contexts(self): self.assertNotIn("creator/1.0: PackageInfo", t.out) # Creator is skipped now, not needed self.assertIn("gtest/1.0: PackageInfo OS=Linux", t.out) - t.run("create gtest.py --profile=profile_host --profile:build=profile_build --build") + t.run("create gtest.py --profile=profile_host --profile:build=profile_build --build=*") self.assertIn("creator/1.0: PackageInfo OS=Windows", t.out) self.assertIn("gtest/1.0: PackageInfo OS=Linux", t.out) @@ -260,12 +249,12 @@ def package_info(self): self.assertIn("creator/1.0: PackageInfo OS=Windows", t.out) self.assertIn("mytoolchain/1.0: Build OS=Windows", t.out) - t.run("create gtest.py --profile=profile_host --profile:build=profile_build --build") + t.run("create gtest.py --profile=profile_host --profile:build=profile_build --build=*") self.assertIn("creator/1.0: PackageInfo OS=Windows", t.out) self.assertIn("mytoolchain/1.0: Build OS=Windows", t.out) self.assertIn("gtest/1.0: Build OS=Linux", t.out) - t.run("create library.py --profile:host=profile_host --profile:build=profile_build --build") + t.run("create library.py -pr:h=profile_host --profile:build=profile_build --build=*") self.assertIn("creator/1.0: PackageInfo OS=Windows", t.out) self.assertIn("mytoolchain/1.0: Build OS=Windows", t.out) self.assertIn("gtest/1.0: Build OS=Linux", t.out) diff --git a/conans/test/integration/graph/core/test_build_requires.py b/conans/test/integration/graph/core/test_build_requires.py index ad6d249f0ab..573a6bde083 100644 --- a/conans/test/integration/graph/core/test_build_requires.py +++ b/conans/test/integration/graph/core/test_build_requires.py @@ -222,66 +222,28 @@ def test_build_require_transitive_shared(self): self._check_node(mingw, "mingw/0.1#123", deps=[zlib2], dependents=[lib]) self._check_node(zlib2, "zlib/0.2#123", deps=[], dependents=[mingw]) - @pytest.mark.xfail(reason="Not updated yet") def test_build_require_conflict(self): # https://github.com/conan-io/conan/issues/4931 # cheetah -> gazelle -> grass/0.1 # \--(br)----------> grass/0.2 - grass01_ref = RecipeReference.loads("grass/0.1@user/testing") - grass02_ref = RecipeReference.loads("grass/0.2@user/testing") - gazelle_ref = RecipeReference.loads("gazelle/0.1@user/testing") - self._cache_recipe(grass01_ref, GenConanfile().with_name("grass").with_version("0.1")) - self._cache_recipe(grass02_ref, GenConanfile().with_name("grass").with_version("0.2")) - self._cache_recipe(gazelle_ref, GenConanfile().with_name("gazelle").with_version("0.1") - .with_require(grass01_ref)) + self._cache_recipe("grass/0.1", GenConanfile()) + self._cache_recipe("grass/0.2", GenConanfile()) + self._cache_recipe("gazelle/0.1", GenConanfile().with_require("grass/0.1")) - deps_graph = self.build_graph(GenConanfile().with_name("cheetah").with_version("0.1") - .with_require(gazelle_ref) - .with_tool_requires(grass02_ref)) + deps_graph = self.build_graph(GenConanfile("cheetah", "0.1") + .with_require("gazelle/0.1") + .with_tool_requires("grass/0.2")) self.assertEqual(4, len(deps_graph.nodes)) - app = deps_graph.root - libb = app.dependencies[0].dst - libc = app.dependencies[1].dst - liba1 = libb.dependencies[0].dst - liba2 = libc.dependencies[0].dst - self._check_node(app, "app/0.1", deps=[libb, libc]) - self._check_node(libb, "libb/0.1#123", deps=[liba1], dependents=[app]) - self._check_node(libc, "libc/0.1#123", deps=[liba2], dependents=[app]) - - self._check_node(liba1, "liba/0.1#123", dependents=[libb]) - # TODO: Conflicted without revision - self._check_node(liba2, "liba/0.2", dependents=[libc]) - - assert liba1.conflict == liba2 - assert liba2.conflict == liba1 - - @pytest.mark.xfail(reason="Not updated yet") - def test_build_require_link_order(self): - # https://github.com/conan-io/conan/issues/4931 - # cheetah -> gazelle -> grass - # \--(br)------------/ - grass01_ref = RecipeReference.loads("grass/0.1@user/testing") - gazelle_ref = RecipeReference.loads("gazelle/0.1@user/testing") - - self._cache_recipe(grass01_ref, GenConanfile().with_name("grass").with_version("0.1")) - self._cache_recipe(gazelle_ref, GenConanfile().with_name("gazelle").with_version("0.1") - .with_require(grass01_ref)) - - deps_graph = self.build_graph(GenConanfile().with_name("cheetah").with_version("0.1") - .with_require(gazelle_ref) - .with_tool_requires(grass01_ref)) - - self.assertEqual(3, len(deps_graph.nodes)) cheetah = deps_graph.root gazelle = cheetah.dependencies[0].dst - grass = gazelle.dependencies[0].dst grass2 = cheetah.dependencies[1].dst - - self._check_node(cheetah, "cheetah/0.1@", deps=[gazelle], dependents=[]) - self.assertListEqual(list(cheetah.conanfile.deps_cpp_info.libs), - ['mylibgazelle0.1lib', 'mylibgrass0.1lib']) + grass1 = gazelle.dependencies[0].dst + self._check_node(cheetah, "cheetah/0.1", deps=[gazelle, grass2]) + self._check_node(gazelle, "gazelle/0.1#123", deps=[grass1], dependents=[cheetah]) + self._check_node(grass1, "grass/0.1#123", deps=[], dependents=[gazelle]) + self._check_node(grass2, "grass/0.2#123", dependents=[cheetah]) class TestTestRequire(GraphManagerTest): diff --git a/conans/test/integration/graph/version_ranges/version_ranges_diamond_test.py b/conans/test/integration/graph/version_ranges/version_ranges_diamond_test.py index 61f73d8c5ee..9a648cd075e 100644 --- a/conans/test/integration/graph/version_ranges/version_ranges_diamond_test.py +++ b/conans/test/integration/graph/version_ranges/version_ranges_diamond_test.py @@ -1,299 +1,92 @@ -import textwrap -import unittest from collections import OrderedDict -import pytest -from parameterized import parameterized - -from conans.paths import CONANFILE from conans.test.assets.genconanfile import GenConanfile -from conans.test.utils.tools import NO_SETTINGS_PACKAGE_ID, TestClient, TestServer, \ - inc_package_manifest_timestamp, inc_recipe_manifest_timestamp +from conans.test.utils.tools import TestClient, TestServer -@pytest.mark.xfail(reason="Version ranges have changed") -class VersionRangesUpdatingTest(unittest.TestCase): +class TestVersionRangesUpdatingTest: def test_update_remote(self): # https://github.com/conan-io/conan/issues/5333 - client = TestClient(servers={"default": TestServer()}, inputs=["admin", "password"]) - conanfile = textwrap.dedent(""" - from conan import ConanFile - class Boost(ConanFile): - pass - """) - client.save({"conanfile.py": conanfile}) - client.run("create . --name=boost --version=1.68.0 --user=lasote --channel=stable") - client.run("create . --name=boost --version=1.69.0 --user=lasote --channel=stable") - client.run("create . --name=boost --version=1.70.0 --user=lasote --channel=stable") + client = TestClient(default_server_user=True) + client.save({"conanfile.py": GenConanfile("boost")}) + client.run("create . --version=1.69.0") + client.run("create . --version=1.70.0") client.run("upload * -r=default --confirm") client.run("remove * -c") - conanfile = textwrap.dedent(""" - [requires] - boost/[>=1.68.0]@lasote/stable - """) - client.save({"conanfile.txt": conanfile}, clean_first=True) + + client.save({"conanfile.txt": "[requires]\nboost/[*]"}, clean_first=True) client.run("install .") - self.assertIn("boost/*@lasote/stable versions found in 'default' remote", client.out) - self.assertIn("resolved to 'boost/1.70.0@lasote/stable' in remote 'default'", client.out) - self.assertNotIn("boost/1.69.0", client.out) - self.assertNotIn("boost/1.68.0", client.out) + assert "boost/1.70" in client.out + assert "boost/1.69" not in client.out + client.run("install .") - self.assertIn("resolved to 'boost/1.70.0@lasote/stable' in local cache", client.out) - self.assertIn("boost/1.70.0", client.out) - self.assertNotIn("boost/1.69.0", client.out) - self.assertNotIn("boost/1.68.0", client.out) + assert "boost/1.70" in client.out + assert "boost/1.69" not in client.out client.run("install . --update") - self.assertIn("resolved to 'boost/1.70.0@lasote/stable' in remote 'default'", client.out) - self.assertIn("boost/1.70.0", client.out) - self.assertNotIn("boost/1.69.0", client.out) - self.assertNotIn("boost/1.68.0", client.out) + assert "boost/1.70" in client.out + assert "boost/1.69" not in client.out def test_update(self): - client = TestClient(servers={"default": TestServer()}, inputs=["admin", "password"]) + client = TestClient(default_server_user=True) - client.save({"pkg.py": GenConanfile()}) - client.run("create pkg.py --name=pkg --veersion=1.1 --user=lasote --channel=testing") - client.run("create pkg.py --name=pkg --veersion=1.2 --user=lasote --channel=testing") - client.run("upload pkg* -r=default --confirm") - client.run("remove pkg/1.2@lasote/testing -c") + client.save({"pkg/conanfile.py": GenConanfile("pkg"), + "app/conanfile.py": GenConanfile().with_requirement("pkg/[~1]")}) + client.run("create pkg --version=1.1") + client.run("create pkg --version=1.2") + client.run("upload * -r=default --confirm") + client.run("remove pkg/1.2* -c") - client.save({"consumer.py": GenConanfile().with_requirement("pkg/[~1]@lasote/testing")}) - client.run("install consumer.py") + client.run("install app") # Resolves to local package - self.assertIn("pkg/1.1@lasote/testing: Already installed!", client.out) - client.run("install consumer.py --update") + assert "pkg/1.1" in client.out + assert "pkg/1.2" not in client.out + + client.run("install app --update") # Resolves to remote package - self.assertIn("pkg/1.2@lasote/testing: Package installed", client.out) - self.assertNotIn("pkg/1.1", client.out) + assert "pkg/1.1" not in client.out + assert "pkg/1.2" in client.out # newer in cache that in remotes and updating, should resolve the cache one - client.run("create pkg.py --name=pkg --veersion=1.3 --user=lasote --channel=testing") - client.run("install consumer.py --update") - self.assertIn("pkg/1.3@lasote/testing: Already installed!", client.out) - client.run("remove pkg/1.3@lasote/testing -c") + client.run("create pkg --version=1.3") + client.run("install app --update") + assert "pkg/1.2" not in client.out + assert "pkg/1.3" in client.out + client.run("remove pkg/1.3* -c") # removes remote - client.run("remove Pkg* -r=default --c") - # Resolves to local package - client.run("install consumer.py") - self.assertIn("pkg/1.2@lasote/testing: Already installed!", client.out) - # Update also resolves to local package - client.run("install consumer.py --update") - self.assertIn("pkg/1.2@lasote/testing: Already installed!", client.out) - self.assertNotIn("pkg/1.1", client.out) - - @pytest.mark.xfail(reason="cache2.0 revisit test") - def test_update_pkg(self): - server = TestServer() - client = TestClient(servers={"default": server}, inputs=["admin", "password"]) - conanfile = """from conan import ConanFile -class HelloReuseConan(ConanFile): - def package_info(self): - self.output.info("PACKAGE_INFO {}") -""" - client.save({"conanfile.py": conanfile.format("1.1")}) - client.run("create . --name=pkg --version=1.1 --user=lasote --channel=testing") - client.save({"conanfile.py": conanfile.format("1.2")}) - client.run("create . --name=pkg --version=1.2 --user=lasote --channel=testing") - client.run("upload pkg* -r=default --confirm") - consumer = """from conan import ConanFile -class HelloReuseConan(ConanFile): - requires = "pkg/[~1]@lasote/testing" -""" - client.save({"conanfile.py": consumer}) - client.run("install .") - # Resolves to local package - self.assertIn("pkg/1.2@lasote/testing: Already installed!", client.out) - self.assertIn("pkg/1.2@lasote/testing: PACKAGE_INFO 1.2", client.out) - - # modify remote 1.2 - client2 = TestClient(servers={"default": server}, inputs=["admin", "password"]) - client2.save({"conanfile.py": conanfile.format("*1.2*")}) - client2.run("create . --name=pkg --version=1.2 --user=lasote --channel=testing") - - # Make sure timestamp increases, in some machines in testing, - # it can fail due to same timestamp - inc_recipe_manifest_timestamp(client2.cache, "pkg/1.2@lasote/testing", 1) - inc_package_manifest_timestamp(client2.cache, - "pkg/1.2@lasote/testing:%s" % NO_SETTINGS_PACKAGE_ID, - 1) - - client2.run("upload pkg* -r=default --confirm") - - client.run("install .") + client.run("remove pkg* -r=default --c") # Resolves to local package - self.assertIn("pkg/1.2@lasote/testing: Already installed!", client.out) - self.assertIn("pkg/1.2@lasote/testing: PACKAGE_INFO 1.2", client.out) - - client.run("install . --update") - # Resolves to remote new recipe and package - self.assertIn("pkg/1.2@lasote/testing: Package installed", client.out) - self.assertNotIn("pkg/1.2@lasote/testing: PACKAGE_INFO 1.2", client.out) - self.assertIn("pkg/1.2@lasote/testing: PACKAGE_INFO *1.2*", client.out) - - -@pytest.mark.xfail(reason="Overrides Output have changed") -class VersionRangesMultiRemoteTest(unittest.TestCase): - - def setUp(self): - self.servers = OrderedDict() - self.servers["default"] = TestServer() - self.servers["other"] = TestServer() - self.client = TestClient(servers=self.servers, inputs=2*["admin", "password"]) - - def _export(self, name, version, deps=None, export=True, upload=True, remote="default"): - deps = ", ".join(['"%s"' % d for d in deps or []]) or '""' - conanfile = """ -from conan import ConanFile, CMake -import os - -class HelloReuseConan(ConanFile): - name = "%s" - version = "%s" - requires = %s -""" % (name, version, deps) - files = {CONANFILE: conanfile} - self.client.save(files, clean_first=True) - if export: - self.client.run("export . --user=lasote --channel=stable") - if upload: - self.client.run("upload %s/%s@lasote/stable -r=%s --only-recipe" % (name, version, - remote)) - - def test_resolve_from_remotes(self): - self._export("hello0", "0.1") - self._export("hello0", "0.2") - self._export("hello0", "0.3", remote="other") - self._export("hello1", "0.1", ["hello0/[>0.1,<0.4]@lasote/stable"], export=False, - upload=False) - - for remote, solution in [("default", "0.2"), ("other", "0.3")]: - self.client.run('remove "hello0/0.*" -c') - self.client.run("install . --build missing -r=%s" % remote) - self.assertIn("Version range '>0.1,<0.4' required by " - "'conanfile.py (hello1/0.1)' " - "resolved to 'hello0/%s@lasote/stable'" % solution, - self.client.out) - - -@pytest.mark.xfail(reason="Overrides Output have changed") -class VersionRangesDiamondTest(unittest.TestCase): - - def setUp(self): - test_server = TestServer() - self.servers = {"default": test_server} - self.client = TestClient(servers=self.servers, inputs=["admin", "password"]) - - def _export(self, name, version, deps=None, export=True, upload=True): - deps = ", ".join(['"%s"' % d for d in deps or []]) or '""' - conanfile = """ -from conan import ConanFile, CMake -import os - -class HelloReuseConan(ConanFile): - name = "%s" - version = "%s" - requires = %s -""" % (name, version, deps) - files = {CONANFILE: conanfile} - self.client.save(files, clean_first=True) - if export: - self.client.run("export . --user=lasote --channel=stable") - if upload: - self.client.run("upload %s/%s@lasote/stable -r default --only-recipe" % (name, - version)) - - def test_local_then_remote(self): - self._export("hello0", "0.1") - self._export("hello0", "0.2") - self._export("hello0", "0.3") - self._export("hello0", "1.4") - self._export("hello1", "0.1", ["hello0/[>0.1,<0.3]@lasote/stable"], export=False, - upload=False) - - self.client.run('remove "hello0/0.*" -c') - self.client.run("install . --build missing") - self.assertIn("Version range '>0.1,<0.3' required by 'conanfile.py (hello1/0.1)' " - "resolved to 'hello0/0.2@lasote/stable'", self.client.out) - - @parameterized.expand([(False, ), (True,)]) - def test_reuse(self, upload): - self._export("hello0", "0.1", upload=upload) - self._export("hello0", "0.2", upload=upload) - self._export("hello0", "0.3", upload=upload) - self._export("hello1", "0.1", ["hello0/[>0.1,<0.3]@lasote/stable"], upload=upload) - self._export("Hello2", "0.1", ["hello0/[0.2]@lasote/stable"], upload=upload) - self._export("Hello3", "0.1", ["hello1/[>=0]@lasote/stable", "hello2/[~=0]@lasote/stable"], - export=False, upload=upload) - - if upload: - self.client.run('remove "*" -c') - - self.client.run("install . --build missing") - - def check1(): - self.assertIn("Version range '~=0' required by 'conanfile.py (Hello3/0.1)' " - "resolved to 'hello2/0.1@lasote/stable'", self.client.out) - self.assertIn("Version range '>0.1,<0.3' required by 'hello1/0.1@lasote/stable' " - "resolved to 'hello0/0.2@lasote/stable'", self.client.out) - self.assertIn("Version range '0.2' required by 'hello2/0.1@lasote/stable' resolved " - "to 'hello0/0.2@lasote/stable'", self.client.out) - self.assertNotIn("Conflict", self.client.out) - - check1() - - if upload: - self._export("hello0", "0.2.1", upload=upload) - self.client.run('remove hello0/0.2.1@lasote/stable -c') - self._export("Hello3", "0.1", ["hello1/[>=0]@lasote/stable", - "hello2/[~=0]@lasote/stable"], - export=False, upload=upload) - self.client.run("install . --build missing") - check1() - # Now update - self.client.run("install . --update --build missing") - self.assertIn("Version range '~=0' required by 'conanfile.py (Hello3/0.1)' " - "resolved to 'hello2/0.1@lasote/stable'", self.client.out) - self.assertIn("Version range '>0.1,<0.3' required by 'hello1/0.1@lasote/stable' " - "resolved to 'hello0/0.2.1@lasote/stable'", self.client.out) - self.assertIn("Version range '0.2' required by 'hello2/0.1@lasote/stable' resolved " - "to 'hello0/0.2.1@lasote/stable'", self.client.out) - self.assertNotIn("Conflict", self.client.out) - - def test_no_joint_compatibility_resolved(self): - """Test to verify that conan is not resolving using joint-compatibility of the full graph - and you need to specify the right order or override downstream the conflict""" - self._export("ProblemRequirement", "1.0.0", upload=True) - self._export("ProblemRequirement", "1.1.0", upload=True) - self._export("RequirementOne", "1.2.3", - ["ProblemRequirement/[=1.0.0]@lasote/stable"], upload=True) - self._export("RequirementTwo", "4.5.6", - ["ProblemRequirement/[~1]@lasote/stable"], upload=True) - self._export("Project", "1.0.0", - ["RequirementTwo/[=4.5.6]@lasote/stable", - "RequirementOne/[=1.2.3]@lasote/stable"], upload=True) - - self.client.run("remove '*' -c") - self.client.run("install --requires=Project/1.0.0@lasote/stable --build missing", assert_error=True) - self.assertIn("Conflict in RequirementOne/1.2.3@lasote/stable:\n" - " 'RequirementOne/1.2.3@lasote/stable' requires " - "'ProblemRequirement/1.0.0@lasote/stable' while 'RequirementTwo/4.5.6@lasote/stable'" - " requires 'ProblemRequirement/1.1.0@lasote/stable'.\n" - " To fix this conflict you need to override the package 'ProblemRequirement' in " - "your root package.", self.client.out) - - # Change the order, still conflicts, message in different order, but same conflict - self._export("Project", "1.0.0", - ["RequirementOne/[=1.2.3]@lasote/stable", - "RequirementTwo/[=4.5.6]@lasote/stable", - ], upload=True) - self.client.run("remove '*' -c") - self.client.run("install --requires=Project/1.0.0@lasote/stable --build missing", assert_error=True) - self.assertIn("Conflict in RequirementTwo/4.5.6@lasote/stable:\n" - " 'RequirementTwo/4.5.6@lasote/stable' requires " - "'ProblemRequirement/1.1.0@lasote/stable' while 'RequirementOne/1.2.3@lasote/stable'" - " requires 'ProblemRequirement/1.0.0@lasote/stable'.\n" - " To fix this conflict you need to override the package 'ProblemRequirement' in " - "your root package.", self.client.out) + client.run("install app") + assert "pkg/1.1" not in client.out + assert "pkg/1.2" in client.out + + client.run("install app --update") + assert "pkg/1.1" not in client.out + assert "pkg/1.2" in client.out + + +class TestVersionRangesMultiRemote: + + def test_multi_remote(self): + servers = OrderedDict() + servers["default"] = TestServer() + servers["other"] = TestServer() + client = TestClient(servers=servers, inputs=2*["admin", "password"]) + client.save({"hello0/conanfile.py": GenConanfile("hello0"), + "hello1/conanfile.py": GenConanfile("hello1").with_requires("hello0/[*]")}) + client.run("export hello0 --version=0.1") + client.run("export hello0 --version=0.2") + client.run("upload * -r=default -c") + client.run("export hello0 --version=0.3") + client.run("upload hello0/0.3 -r=other -c") + client.run('remove "hello0/*" -c') + + client.run("install hello1 --build missing -r=default") + assert "hello0/0.2" in client.out + assert "hello0/0.3" not in client.out + client.run("remove hello0/* -c") + client.run("install hello1 --build missing -r=other") + assert "hello0/0.2" not in client.out + assert "hello0/0.3" in client.out diff --git a/conans/test/integration/hooks/test_post_export.py b/conans/test/integration/hooks/test_post_export.py index 4f9e0643ba7..bc65421fc98 100644 --- a/conans/test/integration/hooks/test_post_export.py +++ b/conans/test/integration/hooks/test_post_export.py @@ -1,45 +1,27 @@ -# coding=utf-8 - import os import textwrap -import pytest -from mock import patch - -from conans.client.hook_manager import HookManager from conans.model.manifest import FileTreeManifest -from conans.model.recipe_ref import RecipeReference -from conans.paths import CONAN_MANIFEST +from conans.test.assets.genconanfile import GenConanfile from conans.test.utils.tools import TestClient +from conans.util.files import save -@pytest.mark.xfail(reason="cache2.0 revisit test") -def test_called_before_digest(self): +def test_called_before_digest(): """ Test that 'post_export' hook is called before computing the digest of the exported folders """ - - ref = RecipeReference.loads("name/version@user/channel") - conanfile = textwrap.dedent("""\ - from conan import ConanFile - - class MyLib(ConanFile): - pass - """) - t = TestClient() - t.save({'conanfile.py': conanfile}) - ref_layout = t.get_latest_ref_layout(ref) - - def mocked_post_export(*args, **kwargs): - # There shouldn't be a digest yet - with self.assertRaisesRegex(IOError, "No such file or directory"): - FileTreeManifest.load(ref_layout.export()) - self.assertFalse(os.path.exists(os.path.join(ref_layout.export(), CONAN_MANIFEST))) - - def mocked_load_hooks(hook_manager): - hook_manager.hooks["post_export"] = [("_", mocked_post_export)] - - with patch.object(HookManager, "load_hooks", new=mocked_load_hooks): - t.run(f"export . --name={ref.name} --version={ref.version} --user={ref.user} --channel={ref.channel}") - self.assertTrue(os.path.exists(os.path.join(ref_layout.export(), CONAN_MANIFEST))) + complete_hook = textwrap.dedent("""\ + import os + from conan.tools.files import save + def post_export(conanfile): + save(conanfile, os.path.join(conanfile.export_folder, "myfile.txt"), "content!!") + """) + hook_path = os.path.join(t.cache.hooks_path, "complete_hook", "hook_complete.py") + save(hook_path, complete_hook) + t.save({'conanfile.py': GenConanfile("pkg", "0.1")}) + t.run("export .") + ref_layout = t.exported_layout() + manifest = FileTreeManifest.load(ref_layout.export()) + assert "myfile.txt" in manifest.file_sums diff --git a/conans/test/integration/hooks/test_post_package.py b/conans/test/integration/hooks/test_post_package.py index 4e5f6579659..84b51548e4a 100644 --- a/conans/test/integration/hooks/test_post_package.py +++ b/conans/test/integration/hooks/test_post_package.py @@ -1,76 +1,32 @@ -# coding=utf-8 - import os -import unittest - -import pytest -from mock import patch - -from conans.client.hook_manager import HookManager -from conans.model.recipe_ref import RecipeReference -from conans.paths import CONAN_MANIFEST -from conans.test.utils.tools import TurboTestClient - - -class PostPackageTestCase(unittest.TestCase): - - @pytest.mark.xfail(reason="cache2.0 revisit test") - def test_create_command(self): - """ Test that 'post_package' hook is called before computing the manifest - """ - t = TurboTestClient() - filename = "hook_file" - - def post_package_hook(conanfile, **kwargs): - # There shouldn't be a manifest yet - post_package_hook.manifest_path = os.path.join(conanfile.package_folder, CONAN_MANIFEST) - self.assertFalse(os.path.exists(post_package_hook.manifest_path)) - # Add a file - open(os.path.join(conanfile.package_folder, filename), "w").close() - - def mocked_load_hooks(hook_manager): - hook_manager.hooks["post_package"] = [("_", post_package_hook)] - - with patch.object(HookManager, "load_hooks", new=mocked_load_hooks): - pref = t.create(RecipeReference.loads("name/version@user/channel")) - - # Check that we are considering the same file - pkg_layout = t.get_latest_pkg_layout(pref) - self.assertEqual(post_package_hook.manifest_path, - os.path.join(pkg_layout.package(), CONAN_MANIFEST)) - # Now the file exists and contains info about created file - self.assertTrue(os.path.exists(post_package_hook.manifest_path)) - with open(post_package_hook.manifest_path) as f: - content = f.read() - self.assertIn(filename, content) - - @pytest.mark.xfail(reason="cache2.0 revisit test") - def test_export_pkg_command(self): - """ Test that 'post_package' hook is called before computing the manifest - """ - t = TurboTestClient() - filename = "hook_file" - - def post_package_hook(conanfile, **kwargs): - # There shouldn't be a manifest yet - post_package_hook.manifest_path = os.path.join(conanfile.package_folder, CONAN_MANIFEST) - self.assertFalse(os.path.exists(post_package_hook.manifest_path)) - # Add a file - open(os.path.join(conanfile.package_folder, filename), "w").close() - - def mocked_load_hooks(hook_manager): - hook_manager.hooks["post_package"] = [("_", post_package_hook)] - - with patch.object(HookManager, "load_hooks", new=mocked_load_hooks): - pref = t.export_pkg(ref=RecipeReference.loads("name/version@user/channel"), - args="--package-folder=.") - - # Check that we are considering the same file - pkg_layout = t.get_latest_pkg_layout(pref) - self.assertEqual(post_package_hook.manifest_path, - os.path.join(pkg_layout.package(), CONAN_MANIFEST)) - # Now the file exists and contains info about created file - self.assertTrue(os.path.exists(post_package_hook.manifest_path)) - with open(post_package_hook.manifest_path) as f: - content = f.read() - self.assertIn(filename, content) +import textwrap + +from conans.model.manifest import FileTreeManifest +from conans.test.assets.genconanfile import GenConanfile +from conans.test.utils.tools import TestClient +from conans.util.files import save + + +def test_post_package(): + """ Test that 'post_package' hook is called before computing the manifest + """ + t = TestClient() + complete_hook = textwrap.dedent("""\ + import os + from conan.tools.files import save + def post_package(conanfile): + save(conanfile, os.path.join(conanfile.package_folder, "myfile.txt"), "content!!") + """) + hook_path = os.path.join(t.cache.hooks_path, "complete_hook", "hook_complete.py") + save(hook_path, complete_hook) + t.save({'conanfile.py': GenConanfile("pkg", "0.1")}) + t.run("create .") + pref_layout = t.created_layout() + manifest = FileTreeManifest.load(pref_layout.package()) + assert "myfile.txt" in manifest.file_sums + + t.run("remove * -c") + t.run("export-pkg .") + pref_layout = t.created_layout() + manifest = FileTreeManifest.load(pref_layout.package()) + assert "myfile.txt" in manifest.file_sums diff --git a/conans/test/integration/package_id/compatible_test.py b/conans/test/integration/package_id/compatible_test.py index cfabda22d83..9199c2ee5be 100644 --- a/conans/test/integration/package_id/compatible_test.py +++ b/conans/test/integration/package_id/compatible_test.py @@ -1,8 +1,6 @@ import textwrap import unittest -import pytest - from conans.test.utils.tools import TestClient, GenConanfile from conans.util.files import save @@ -259,7 +257,6 @@ def compatibility(self): client.assert_listed_binary({"pkg/0.1@user/testing": (package_id, "Cache")}) self.assertIn("pkg/0.1@user/testing: Already installed!", client.out) - @pytest.mark.xfail(reason="lockfiles have been deactivated at the moment") def test_compatible_lockfile(self): # https://github.com/conan-io/conan/issues/9002 client = TestClient() @@ -275,17 +272,17 @@ def package_info(self): """) client.save({"conanfile.py": conanfile}) - client.run("create . --name=pkg --version=0.1 --user=user --channel=stable -s os=Linux") - self.assertIn("pkg/0.1@user/stable: PackageInfo!: OS: Linux!", client.out) - self.assertIn("pkg/0.1@user/stable: Package 'cb054d0b3e1ca595dc66bc2339d40f1f8f04ab31'" - " created", client.out) + client.run("create . --name=pkg --version=0.1 -s os=Linux") + self.assertIn("pkg/0.1: PackageInfo!: OS: Linux!", client.out) + self.assertIn("pkg/0.1: Package '9a4eb3c8701508aa9458b1a73d0633783ecc2270' built", + client.out) - client.save({"conanfile.py": GenConanfile().with_require("pkg/0.1@user/stable")}) - client.run("lock create conanfile.py -s os=Windows --lockfile-out=deps.lock") - client.run("install conanfile.py --lockfile=deps.lock") - self.assertIn("pkg/0.1@user/stable: PackageInfo!: OS: Linux!", client.out) - self.assertIn("pkg/0.1@user/stable:cb054d0b3e1ca595dc66bc2339d40f1f8f04ab31", client.out) - self.assertIn("pkg/0.1@user/stable: Already installed!", client.out) + client.save({"conanfile.py": GenConanfile().with_require("pkg/0.1")}) + client.run("lock create . -s os=Windows --lockfile-out=deps.lock") + client.run("install . --lockfile=deps.lock") + self.assertIn("pkg/0.1: PackageInfo!: OS: Linux!", client.out) + self.assertIn("9a4eb3c8701508aa9458b1a73d0633783ecc2270", client.out) + self.assertIn("pkg/0.1: Already installed!", client.out) def test_compatible_diamond(self): # https://github.com/conan-io/conan/issues/9880 diff --git a/conans/test/integration/package_id/transitive_header_only_test.py b/conans/test/integration/package_id/transitive_header_only_test.py index 6b340d683b7..4a88b9030db 100644 --- a/conans/test/integration/package_id/transitive_header_only_test.py +++ b/conans/test/integration/package_id/transitive_header_only_test.py @@ -1,8 +1,5 @@ -import textwrap import unittest -import pytest - from conans.test.utils.tools import TestClient, GenConanfile from conans.util.files import save @@ -75,7 +72,6 @@ def test_transitive_major_mode(self): "libe/1.0": ("f93a37dd8bc53991d7485235c6b3e448942c52ff", "Build") }) - @pytest.mark.xfail(reason="package_id have changed") def test_transitive_unrelated(self): # https://github.com/conan-io/conan/issues/6450 client = TestClient() @@ -96,14 +92,13 @@ def test_transitive_unrelated(self): client.run("create . --name=libd --version=1.0") # LibE -> LibD, LibA/2.0 client.save({"conanfile.py": GenConanfile().with_require("libd/1.0") - .with_require("liba/2.0")}) + .with_requirement("liba/2.0", force=True)}) client.run("create . --name=libe --version=1.0", assert_error=True) - self.assertIn("liba/2.0:5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9 - Cache", client.out) - self.assertIn("libb/1.0:e71235a6f57633221a2b85f9b6aca14cda69e1fd - Missing", client.out) - self.assertIn("libc/1.0:e3884c6976eb7debb8ec57aada7c0c2beaabe8ac - Missing", client.out) - self.assertIn("libd/1.0:9b0b7b0905c9bc2cb9b7329f842b3b7c6663e8c3 - Missing", client.out) + client.assert_listed_binary({"liba/2.0": ("da39a3ee5e6b4b0d3255bfef95601890afd80709", "Cache"), + "libb/1.0": ("9c5273fc489264e39c2c16494d8a4178f239e6e2", "Missing"), + "libc/1.0": ("9c5273fc489264e39c2c16494d8a4178f239e6e2", "Missing"), + "libd/1.0": ("060865748907651202e4caa396a4c11a11f91e28", "Missing")}) - @pytest.mark.xfail(reason="package_id have changed") def test_transitive_second_level_header_only(self): # https://github.com/conan-io/conan/issues/6450 client = TestClient() @@ -123,19 +118,18 @@ def test_transitive_second_level_header_only(self): # LibD -> LibC client.save({"conanfile.py": GenConanfile().with_require("libc/1.0")}) client.run("create . --name=libd --version=1.0") - self.assertIn("libc/1.0:5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9 - Cache", client.out) + client.assert_listed_binary({"libc/1.0": ("da39a3ee5e6b4b0d3255bfef95601890afd80709", "Cache")}) # LibE -> LibD, LibA/2.0 client.save({"conanfile.py": GenConanfile().with_require("libd/1.0") - .with_require("liba/2.0")}) + .with_requirement("liba/2.0", force=True)}) client.run("create . --name=libe --version=1.0", assert_error=True) # LibD is NOT missing! - self.assertIn("libd/1.0:119e0b2903330cef59977f8976cb82a665b510c1 - Cache", client.out) - # USE THE NEW FIXED PACKAGE_ID - client.run("create . --name=libe --version=1.0", assert_error=True) - self.assertIn("liba/2.0:5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9 - Cache", client.out) - self.assertIn("libb/1.0:e71235a6f57633221a2b85f9b6aca14cda69e1fd - Missing", client.out) - self.assertIn("libc/1.0:5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9 - Cache", client.out) - self.assertIn("libd/1.0:95b14a919aa70f9a7e24afbf48d1101cff344a67 - Missing", client.out) + + client.assert_listed_binary( + {"liba/2.0": ("da39a3ee5e6b4b0d3255bfef95601890afd80709", "Cache"), + "libb/1.0": ("9c5273fc489264e39c2c16494d8a4178f239e6e2", "Missing"), + "libc/1.0": ("da39a3ee5e6b4b0d3255bfef95601890afd80709", "Cache"), + "libd/1.0": ("060865748907651202e4caa396a4c11a11f91e28", "Missing")}) def test_transitive_header_only(self): # https://github.com/conan-io/conan/issues/6450 diff --git a/conans/test/integration/settings/remove_subsetting_test.py b/conans/test/integration/settings/remove_subsetting_test.py index 6a8e570f4c1..b2e4794aa23 100644 --- a/conans/test/integration/settings/remove_subsetting_test.py +++ b/conans/test/integration/settings/remove_subsetting_test.py @@ -2,8 +2,6 @@ import textwrap import unittest -import pytest - from conans.test.utils.tools import TestClient from conans.util.files import mkdir @@ -53,68 +51,6 @@ def build(self): client.run("build ..", assert_error=True) self.assertIn("'settings.build_type' doesn't exist", client.out) - @pytest.mark.xfail(reason="Move this to CMakeToolchain") - def test_remove_subsetting(self): - # https://github.com/conan-io/conan/issues/2049 - client = TestClient() - base = '''from conan import ConanFile -class ConanLib(ConanFile): - name = "lib" - version = "0.1" -''' - test = """from conan import ConanFile, CMake -class ConanLib(ConanFile): - settings = "compiler", "arch" - - def configure(self): - del self.settings.compiler.libcxx - - def test(self): - pass - - def build(self): - cmake = CMake(self) - self.output.info("TEST " + cmake.command_line) -""" - client.save({"conanfile.py": base, - "test_package/conanfile.py": test}) - client.run("create . --user=user --channel=testing -s arch=x86_64 -s compiler=gcc " - "-s compiler.version=4.9 -s compiler.libcxx=libstdc++11") - self.assertNotIn("LIBCXX", client.out) - - @pytest.mark.xfail(reason="Move this to CMakeToolchain") - def test_remove_subsetting_build(self): - # https://github.com/conan-io/conan/issues/2049 - client = TestClient() - - conanfile = """from conan import ConanFile, CMake -class ConanLib(ConanFile): - settings = "compiler", "arch" - - def package(self): - try: - self.settings.compiler.libcxx - except Exception as e: - self.output.error("PACKAGE " + str(e)) - - def configure(self): - del self.settings.compiler.libcxx - - def build(self): - try: - self.settings.compiler.libcxx - except Exception as e: - self.output.error("BUILD " + str(e)) - cmake = CMake(self) - self.output.info("BUILD " + cmake.command_line) -""" - client.save({"conanfile.py": conanfile}) - client.run("build . -s arch=x86_64 -s compiler=gcc -s compiler.version=4.9 " - "-s compiler.libcxx=libstdc++11") - self.assertIn("ERROR: BUILD 'settings.compiler.libcxx' doesn't exist for 'gcc'", - client.out) - self.assertNotIn("LIBCXX", client.out) - def test_settings_and_options_rm_safe(): client = TestClient()