Skip to content

Commit

Permalink
move test to integration and pytest-modernize (#8595)
Browse files Browse the repository at this point in the history
* move test to integration and pytest-modernize

* fix test
  • Loading branch information
memsharded committed Mar 4, 2021
1 parent 03b3d71 commit 1c4cd6a
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 128 deletions.
Empty file.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import os

import pytest

from conans.model.ref import ConanFileReference, PackageReference
from conans.test.assets.genconanfile import GenConanfile
from conans.test.utils.tools import TestClient
from conans.util.files import load


@pytest.fixture(scope="module")
def setup():
client = TestClient(default_server_user=True)
conanfile = GenConanfile().with_settings("os", "arch").with_package_file("helloHello0.h", "x")
client.save({"conanfile.py": conanfile})
ref = ConanFileReference.loads("Hello0/0.1@lasote/stable")
client.run("export . {}".format(ref))
client.run("install {} -s os=Windows --build missing".format(ref))
client.run("install {} -s os=Linux --build missing".format(ref))
client.run("install {} -s os=Linux -s arch=x86 --build missing".format(ref))
client.run("upload {} --all".format(ref))

package_ids = os.listdir(client.cache.package_layout(ref).packages())
return client, ref, package_ids, str(conanfile)


def test_download_all(setup):
client, ref, package_ids, _ = setup
new_client = TestClient(servers=client.servers, users=client.users)
# Should retrieve the three packages
new_client.run("download Hello0/0.1@lasote/stable")
packages = os.listdir(os.path.join(new_client.cache.package_layout(ref).packages()))
assert set(packages) == set(package_ids)


def test_download_some_reference(setup):
client, ref, package_ids, _ = setup
new_client = TestClient(servers=client.servers, users=client.users)
# Should retrieve the specified packages
new_client.run("download Hello0/0.1@lasote/stable -p %s" % package_ids[0])
packages = os.listdir(new_client.cache.package_layout(ref).packages())
assert len(packages) == 1
assert packages[0] in package_ids

new_client.run("download Hello0/0.1@lasote/stable -p %s -p %s" % (package_ids[0],
package_ids[1]))
packages = os.listdir(new_client.cache.package_layout(ref).packages())
assert len(packages) == 2
assert packages[0] in package_ids
assert packages[1] in package_ids


def test_download_recipe_twice(setup):
client, ref, package_ids, conanfile = setup
new_client = TestClient(servers=client.servers, users=client.users)
new_client.run("download Hello0/0.1@lasote/stable")
conanfile_path = new_client.cache.package_layout(ref).conanfile()
assert conanfile == load(conanfile_path)

new_client.run("download Hello0/0.1@lasote/stable")
assert conanfile == load(conanfile_path)

new_client.run("download Hello0/0.1@lasote/stable")
assert conanfile == load(conanfile_path)


def test_download_packages_twice(setup):
client, ref, package_ids, _ = setup
new_client = TestClient(servers=client.servers, users=client.users)
expected_header_contents = "x"
pref = PackageReference(ref, package_ids[0])
package_folder = new_client.cache.package_layout(ref).package(pref)

new_client.run("download Hello0/0.1@lasote/stable")
got_header = load(os.path.join(package_folder, "helloHello0.h"))
assert expected_header_contents == got_header

new_client.run("download Hello0/0.1@lasote/stable")
got_header = load(os.path.join(package_folder, "helloHello0.h"))
assert expected_header_contents == got_header

new_client.run("download Hello0/0.1@lasote/stable")
got_header = load(os.path.join(package_folder, "helloHello0.h"))
assert expected_header_contents == got_header


def test_download_all_but_no_packages():
# Remove all from remote
new_client = TestClient(default_server_user=True)

# Try to install all
new_client.run("download Hello0/0.1@lasote/stable", assert_error=True)
assert "Recipe not found: 'Hello0/0.1@lasote/stable'" in new_client.out

# Upload only the recipe
new_client.save({"conanfile.py": GenConanfile()})
new_client.run("export . Hello0/0.1@lasote/stable ")
new_client.run("upload Hello0/0.1@lasote/stable --all")

# And try to download all
new_client.run("download Hello0/0.1@lasote/stable")
assert "No remote binary packages found in remote" in new_client.out
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import os
import platform
import textwrap
import unittest

import pytest

from conans.model.ref import ConanFileReference
from conans.paths import CONANFILE
from conans.test.assets.cpp_test_files import cpp_hello_conan_files
from conans.test.assets.genconanfile import GenConanfile
from conans.test.utils.tools import TestClient
from conans.util.files import load

Expand All @@ -15,13 +15,14 @@ class SourceDirtyTest(unittest.TestCase):
def test_keep_failing_source_folder(self):
# https://github.com/conan-io/conan/issues/4025
client = TestClient()
conanfile = """from conans import ConanFile
from conans.tools import save
class Pkg(ConanFile):
def source(self):
save("somefile.txt", "hello world!!!")
raise Exception("boom")
"""
conanfile = textwrap.dedent("""\
from conans import ConanFile
from conans.tools import save
class Pkg(ConanFile):
def source(self):
save("somefile.txt", "hello world!!!")
raise Exception("boom")
""")
client.save({"conanfile.py": conanfile})
client.run("create . pkg/1.0@user/channel", assert_error=True)
self.assertIn("ERROR: pkg/1.0@user/channel: Error in source() method, line 6", client.out)
Expand Down Expand Up @@ -50,40 +51,37 @@ class ExportDirtyTest(unittest.TestCase):

def setUp(self):
self.client = TestClient()
files = cpp_hello_conan_files("Hello0", "0.1", build=False)

self.client.save(files)
self.client.run("export . lasote/stable")
self.client.run("install Hello0/0.1@lasote/stable --build")
ref = ConanFileReference.loads("Hello0/0.1@lasote/stable")
self.client.save({"conanfile.py": GenConanfile().with_exports("main.cpp"),
"main.cpp": ""})
self.client.run("create . pkg/0.1@user/stable")
ref = ConanFileReference.loads("pkg/0.1@user/stable")
source_path = self.client.cache.package_layout(ref).source()
file_open = os.path.join(source_path, "main.cpp")

self.f = open(file_open, 'wb')
self.f.write(b"Hello world")
files[CONANFILE] = files[CONANFILE].replace("build2(", "build3(")
self.client.save(files)
self.client.run("export . lasote/stable")

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

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

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

@pytest.mark.tool_compiler
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 Hello0/0.1@lasote/stable --build")
self.client.run("install pkg/0.1@user/stable --build")
self.assertIn("WARN: Trying to remove corrupted source folder", self.client.out)

0 comments on commit 1c4cd6a

Please sign in to comment.