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

Tests maintenance, fix some xfail, remove other xfails #15234

Merged
merged 1 commit into from
Dec 7, 2023
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
459 changes: 0 additions & 459 deletions conans/test/integration/build_requires/build_requires_test.py

Large diffs are not rendered by default.

90 changes: 21 additions & 69 deletions conans/test/integration/command/export/export_dirty_test.py
Original file line number Diff line number Diff line change
@@ -1,89 +1,41 @@
import os
import platform
import textwrap
import unittest

import pytest

from conans.model.recipe_ref import RecipeReference
from conans.test.assets.genconanfile import GenConanfile
from conans.test.utils.tools import TestClient
from conans.util.files import load


@pytest.mark.xfail(reason="cache2.0")
class SourceDirtyTest(unittest.TestCase):
class TestSourceDirty:
def test_keep_failing_source_folder(self):
# https://github.com/conan-io/conan/issues/4025
client = TestClient()
conanfile = textwrap.dedent("""\
from conan import ConanFile
from conans.tools import save
from conan.tools.files import save
class Pkg(ConanFile):
def source(self):
save("somefile.txt", "hello world!!!")
save(self, "somefile.txt", "hello world!!!")
raise Exception("boom")
""")
client.save({"conanfile.py": conanfile})
client.run("create . --name=pkg --version=1.0 --user=user --channel=channel", assert_error=True)
self.assertIn("ERROR: pkg/1.0@user/channel: Error in source() method, line 6", client.out)
ref = RecipeReference.loads("pkg/1.0@user/channel")
client.run("create . --name=pkg --version=1.0", assert_error=True)
assert "ERROR: pkg/1.0: Error in source() method, line 6" in client.out
# Check that we can debug and see the folder
self.assertEqual(load(os.path.join(client.get_latest_ref_layout(ref).source(),
"somefile.txt")),
"hello world!!!")
client.run("create . --name=pkg --version=1.0 --user=user --channel=channel", assert_error=True)
self.assertIn("pkg/1.0@user/channel: Source folder is corrupted, forcing removal",
client.out)
source_file = os.path.join(client.exported_layout().source(), "somefile.txt")
assert load(source_file) == "hello world!!!"
# Without any change, the export will generate same recipe revision, reuse source folder
client.run("create . --name=pkg --version=1.0", assert_error=True)
assert "pkg/1.0: Source folder is corrupted, forcing removal" in client.out
assert "ERROR: pkg/1.0: Error in source() method, line 6" in client.out

# The install also removes corrupted source folder before proceeding, then call source
client.run("install --requires=pkg/1.0 --build=missing", assert_error=True)
assert "pkg/1.0: WARN: Trying to remove corrupted source folder" in client.out
assert "ERROR: pkg/1.0: Error in source() method, line 6" in client.out

# This creates a new revision that doesn't need removal, different source folder
client.save({"conanfile.py": conanfile.replace("source(", "source2(")})
client.run("create . --name=pkg --version=1.0 --user=user --channel=channel")
self.assertIn("pkg/1.0@user/channel: Source folder is corrupted, forcing removal",
client.out)
client.run("create . --name=pkg --version=1.0")
assert "corrupted, forcing removal" not in client.out
# Check that it is empty
self.assertEqual(os.listdir(os.path.join(client.get_latest_ref_layout(ref).source())), [])


@pytest.mark.skipif(platform.system() != "Windows", reason="Needs windows for rmdir block")
@pytest.mark.xfail(reason="cache2.0: revisit tests")
class ExportDirtyTest(unittest.TestCase):
""" Make sure than when the source folder becomes dirty, due to a export of
a new recipe with a rmdir failure, or to an uncomplete execution of source(),
it is marked as dirty and removed when necessary
"""

def setUp(self):
self.client = TestClient()
self.client.save({"conanfile.py": GenConanfile().with_exports("main.cpp"),
"main.cpp": ""})
self.client.run("create . --name=pkg --version=0.1 --user=user --channel=stable")
ref = RecipeReference.loads("pkg/0.1@user/stable")
source_path = self.client.get_latest_ref_layout(ref).source()
file_open = os.path.join(source_path, "main.cpp")

self.f = open(file_open, 'wb')
self.f.write(b"Hello world")

self.client.save({"conanfile.py": GenConanfile().with_exports("main.cpp", "other.h"),
"main.cpp": ""})
self.client.run("export . --name=pkg --version=0.1 --user=user --channel=stable")
self.assertIn("ERROR: Unable to delete source folder. "
"Will be marked as corrupted for deletion",
self.client.out)

self.client.run("install --requires=pkg/0.1@user/stable --build", assert_error=True)
self.assertIn("ERROR: Unable to remove source folder", self.client.out)

def test_export_remove(self):
# export is able to remove dirty source folders
self.f.close()
self.client.run("export . --name=pkg --version=0.1 --user=user --channel=stable")
self.assertIn("Source folder is corrupted, forcing removal", self.client.out)
self.client.run("install --requires=pkg/0.1@user/stable --build")
self.assertNotIn("WARN: Trying to remove corrupted source folder", self.client.out)

def test_install_remove(self):
# install is also able to remove dirty source folders
# Now, release the handle to the file
self.f.close()
self.client.run("install --requires=pkg/0.1@user/stable --build")
self.assertIn("WARN: Trying to remove corrupted source folder", self.client.out)
assert os.listdir(os.path.join(client.exported_layout().source())) == []
20 changes: 9 additions & 11 deletions conans/test/integration/command/install/install_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,6 @@ def test_install_with_path_errors(client):
assert "Conanfile not found" in client.out


@pytest.mark.xfail(reason="cache2.0: outputs building will never be the same because the uuid "
"of the folders")
def test_install_argument_order(client):
# https://github.com/conan-io/conan/issues/2520
conanfile_boost = textwrap.dedent("""
Expand All @@ -209,30 +207,30 @@ class BoostConan(ConanFile):
name = "boost"
version = "0.1"
options = {"shared": [True, False]}
default_options = "shared=True"
default_options = {"shared": True}
""")
conanfile = GenConanfile().with_require("boost/0.1@conan/stable")
conanfile = GenConanfile().with_require("boost/0.1")

client.save({"conanfile.py": conanfile,
"conanfile_boost.py": conanfile_boost})
client.run("create conanfile_boost.py conan/stable")
client.run("create conanfile_boost.py ")
client.run("install . -o boost/*:shared=True --build=missing")
output_0 = "%s" % client.out
output_0 = client.out
client.run("install . -o boost/*:shared=True --build missing")
output_1 = "%s" % client.out
output_1 = client.out
client.run("install -o boost/*:shared=True . --build missing")
output_2 = "%s" % client.out
output_2 = client.out
client.run("install -o boost/*:shared=True --build missing .")
output_3 = "%s" % client.out
output_3 = client.out
assert "ERROR" not in output_3
assert output_0 == output_1
assert output_1 == output_2
assert output_2 == output_3

client.run("install -o boost/*:shared=True --build boost . --build missing")
output_4 = "%s" % client.out
output_4 = client.out
client.run("install -o boost/*:shared=True --build missing --build boost .")
output_5 = "%s" % client.out
output_5 = client.out
assert output_4 == output_5


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import pytest

from conans.model.info import ConanInfo, load_binary_info
from conans.model.package_ref import PkgReference
from conans.model.info import load_binary_info
from conans.model.recipe_ref import RecipeReference
from conans.paths import CONANFILE_TXT, CONANINFO
from conans.test.utils.tools import TestClient, GenConanfile
Expand Down Expand Up @@ -54,30 +53,6 @@ def test_partials(client):
assert "No package matching" not in client.out


@pytest.mark.xfail(reason="changing package-ids")
def test_reuse(client):
# FIXME: package-ids will change
for lang, id0, id1 in [(0, "3475bd55b91ae904ac96fde0f106a136ab951a5e",
"c27896c40136be4bb5fd9c759d9abffaee6756a0"),
(1, "f43bd822487baa4ed2426c279c27b2811870499a",
"9f15cc4352ab4f46f118942394adc52a2cdbcffc")]:

client.run("install . -o *:language=%d --build missing" % lang)
assert "Configuration:[settings]", "".join(str(client.out).splitlines())
ref = RecipeReference.loads("hello0/0.1@lasote/stable")

hello0 = client.get_latest_pkg_layout(PkgReference(ref, id0)).package()
hello0_info = os.path.join(hello0, CONANINFO)
hello0_conan_info = load_binary_info(load(hello0_info))
assert lang == hello0_conan_info["options"]["language"]

pref1 = PkgReference(RecipeReference.loads("hello1/0.1@lasote/stable"), id1)
hello1 = client.get_latest_pkg_layout(pref1).package()
hello1_info = os.path.join(hello1, CONANINFO)
hello1_conan_info = load_binary_info(load(hello1_info))
assert lang == hello1_conan_info["options"]["language"]


def test_upper_option(client):
client.run("install conanfile.py -o hello2*:language=1 -o hello1*:language=0 "
"-o hello0*:language=1 --build missing")
Expand Down
129 changes: 40 additions & 89 deletions conans/test/integration/conanfile/no_copy_source_test.py
Original file line number Diff line number Diff line change
@@ -1,94 +1,45 @@
import os
import unittest
import textwrap

import pytest

from conans.model.recipe_ref import RecipeReference
from conans.test.utils.tools import TestClient


class NoCopySourceTest(unittest.TestCase):

def test_basic(self):
conanfile = '''
from conan import ConanFile
from conan.tools.files import copy
from conans.util.files import save, load
import os

class ConanFileToolsTest(ConanFile):
name = "pkg"
version = "0.1"
exports_sources = "*"
no_copy_source = True

def build(self):
self.output.info("Source files: %s" % load(os.path.join(self.source_folder, "file.h")))
save("myartifact.lib", "artifact contents!")

def package(self):
copy(self, "*", self.source_folder, self.package_folder)
copy(self, "*", self.build_folder, self.package_folder)
'''

client = TestClient()
client.save({"conanfile.py": conanfile,
"file.h": "myfile.h contents"})
client.run("export . --user=lasote --channel=testing")
client.run("install --requires=pkg/0.1@lasote/testing --build='*'")
self.assertIn("Source files: myfile.h contents", client.out)
ref = RecipeReference.loads("pkg/0.1@lasote/testing")

latest_rrev = client.cache.get_latest_recipe_reference(ref)
pkg_ids = client.cache.get_package_references(latest_rrev)
latest_prev = client.cache.get_latest_package_reference(pkg_ids[0])
layout = client.cache.pkg_layout(latest_prev)
build_folder = layout.build()
package_folder = layout.package()

self.assertNotIn("file.h", os.listdir(build_folder))
self.assertIn("file.h", os.listdir(package_folder))
self.assertIn("myartifact.lib", os.listdir(package_folder))

@pytest.mark.xfail(reason="cache2.0 create --build not considered yet")
def test_source_folder(self):
conanfile = '''
from conan import ConanFile
from conans.util.files import save, load
from conan.tools.files import copy
import os

class ConanFileToolsTest(ConanFile):
name = "pkg"
version = "0.1"
no_copy_source = %s

def source(self):
save("header.h", "artifact contents!")

def package(self):
copy(self, "*.h", self.source_folder, os.path.join(self.package_folder, "include"))
'''
client = TestClient()
client.save({"conanfile.py": conanfile % "True"})
client.run("create . --user=lasote --channel=testing --build")
ref = RecipeReference.loads("pkg/0.1@lasote/testing")

latest_rrev = client.cache.get_latest_recipe_reference(ref)
latest_prev = client.cache.get_latest_package_reference(latest_rrev)
layout = client.cache.pkg_layout(latest_prev)
package_folder = layout.package()

self.assertIn("header.h", os.listdir(package_folder))

client = TestClient()
client.save({"conanfile.py": conanfile % "False"})
client.run("create . --user=lasote --channel=testing --build")
ref = RecipeReference.loads("pkg/0.1@lasote/testing")

latest_rrev = client.cache.get_latest_recipe_reference(ref)
latest_prev = client.cache.get_latest_package_reference(latest_rrev)
layout = client.cache.pkg_layout(latest_prev)
package_folder = layout.package()

self.assertIn("header.h", os.listdir(package_folder))
def test_no_copy_source():
conanfile = textwrap.dedent('''
from conan import ConanFile
from conan.tools.files import copy, save, load
import os

class ConanFileToolsTest(ConanFile):
name = "pkg"
version = "0.1"
exports_sources = "*"
no_copy_source = True

def source(self):
save(self, "header.h", "artifact contents!")

def build(self):
self.output.info("Source files: %s" % load(self,
os.path.join(self.source_folder, "file.h")))
save(self, "myartifact.lib", "artifact contents!")

def package(self):
copy(self, "*", self.source_folder, self.package_folder)
copy(self, "*", self.build_folder, self.package_folder)
''')

client = TestClient()
client.save({"conanfile.py": conanfile,
"file.h": "myfile.h contents"})
client.run("create .")
assert "Source files: myfile.h contents" in client.out
layout = client.created_layout()
build_folder = layout.build()
package_folder = layout.package()

assert "file.h" not in os.listdir(build_folder)
assert "header.h" not in os.listdir(build_folder)
assert "file.h" in os.listdir(package_folder)
assert "header.h" in os.listdir(package_folder)
assert "myartifact.lib" in os.listdir(package_folder)
59 changes: 0 additions & 59 deletions conans/test/integration/configuration/conan_trace_file_test.py

This file was deleted.

Loading