-
Notifications
You must be signed in to change notification settings - Fork 993
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* initial metadata proposal * fix * remove conf * hooks tests * removed test
- Loading branch information
1 parent
f01fc3b
commit cca46e0
Showing
8 changed files
with
178 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
import os | ||
import textwrap | ||
|
||
import pytest | ||
|
||
from conans.model.recipe_ref import RecipeReference | ||
from conans.test.utils.tools import TestClient | ||
from conans.util.files import load, save | ||
|
||
|
||
class TestRecipeMetadataLogs: | ||
|
||
conanfile = textwrap.dedent(""" | ||
import os | ||
from conan import ConanFile | ||
from conan.tools.files import save, copy | ||
class Pkg(ConanFile): | ||
name = "pkg" | ||
version = "0.1" | ||
def export(self): | ||
copy(self, "*.log", src=self.recipe_folder, | ||
dst=os.path.join(self.recipe_metadata_folder, "logs")) | ||
def layout(self): | ||
self.folders.build = "mybuild" | ||
self.folders.generators = "mybuild/generators" | ||
def source(self): | ||
save(self, os.path.join(self.recipe_metadata_folder, "logs", "src.log"), "srclog!!") | ||
def build(self): | ||
save(self, "mylogs.txt", "some logs!!!") | ||
copy(self, "mylogs.txt", src=self.build_folder, | ||
dst=os.path.join(self.pkg_metadata_folder, "logs")) | ||
""") | ||
|
||
def test_metadata_logs(self): | ||
c = TestClient(default_server_user=True) | ||
c.save({"conanfile.py": self.conanfile, | ||
"file.log": "log contents!"}) | ||
c.run("create .") | ||
# Test local cache looks good | ||
ref = RecipeReference.loads("pkg/0.1") | ||
ref_layout = c.get_latest_ref_layout(ref) | ||
assert os.listdir(ref_layout.metadata()) == ["logs"] | ||
assert os.listdir(os.path.join(ref_layout.metadata(), "logs")) == ["file.log", "src.log"] | ||
assert load(os.path.join(ref_layout.metadata(), "logs", "file.log")) == "log contents!" | ||
assert load(os.path.join(ref_layout.metadata(), "logs", "src.log")) == "srclog!!" | ||
|
||
pref = c.get_latest_package_reference(ref) | ||
pref_layout = c.get_latest_pkg_layout(pref) | ||
assert os.listdir(pref_layout.metadata()) == ["logs"] | ||
assert os.listdir(os.path.join(pref_layout.metadata(), "logs")) == ["mylogs.txt"] | ||
assert load(os.path.join(pref_layout.metadata(), "logs", "mylogs.txt")) == "some logs!!!" | ||
|
||
def test_metadata_logs_local(self): | ||
c = TestClient(default_server_user=True) | ||
c.save({"conanfile.py": self.conanfile, | ||
"file.log": "log contents!"}) | ||
c.run("source .") | ||
assert c.load("metadata/logs/src.log") == "srclog!!" | ||
c.run("build .") | ||
assert c.load("mybuild/metadata/logs/mylogs.txt") == "some logs!!!" | ||
|
||
|
||
class TestHooksMetadataLogs: | ||
|
||
@pytest.fixture() | ||
def _client(self): | ||
c = TestClient(default_server_user=True) | ||
my_hook = textwrap.dedent("""\ | ||
import os | ||
from conan.tools.files import copy | ||
def post_export(conanfile): | ||
conanfile.output.info("post_export") | ||
copy(conanfile, "*.log", src=conanfile.recipe_folder, | ||
dst=os.path.join(conanfile.recipe_metadata_folder, "logs")) | ||
def post_source(conanfile): | ||
conanfile.output.info("post_source") | ||
copy(conanfile, "*", src=os.path.join(conanfile.source_folder, "logs"), | ||
dst=os.path.join(conanfile.recipe_metadata_folder, "logs")) | ||
def post_build(conanfile): | ||
conanfile.output.info("post_build") | ||
copy(conanfile, "*", src=os.path.join(conanfile.build_folder, "logs"), | ||
dst=os.path.join(conanfile.pkg_metadata_folder, "logs")) | ||
""") | ||
hook_path = os.path.join(c.cache.hooks_path, "my_hook", "hook_my_hook.py") | ||
save(hook_path, my_hook) | ||
conanfile = textwrap.dedent(""" | ||
import os | ||
from conan import ConanFile | ||
from conan.tools.files import save, copy | ||
class Pkg(ConanFile): | ||
name = "pkg" | ||
version = "0.1" | ||
no_copy_source = True | ||
def layout(self): | ||
self.folders.build = "mybuild" | ||
self.folders.generators = "mybuild/generators" | ||
def source(self): | ||
save(self, "logs/src.log", "srclog!!") | ||
def build(self): | ||
save(self, "logs/mylogs.txt", "some logs!!!") | ||
""") | ||
c.save({"conanfile.py": conanfile, | ||
"file.log": "log contents!"}) | ||
return c | ||
|
||
def test_metadata_logs_hook(self, _client): | ||
c = _client | ||
c.run("create .") | ||
# Test local cache looks good | ||
ref = RecipeReference.loads("pkg/0.1") | ||
ref_layout = c.get_latest_ref_layout(ref) | ||
assert os.listdir(ref_layout.metadata()) == ["logs"] | ||
assert os.listdir(os.path.join(ref_layout.metadata(), "logs")) == ["file.log", "src.log"] | ||
assert load(os.path.join(ref_layout.metadata(), "logs", "file.log")) == "log contents!" | ||
assert load(os.path.join(ref_layout.metadata(), "logs", "src.log")) == "srclog!!" | ||
|
||
pref = c.get_latest_package_reference(ref) | ||
pref_layout = c.get_latest_pkg_layout(pref) | ||
assert os.listdir(pref_layout.metadata()) == ["logs"] | ||
assert os.listdir(os.path.join(pref_layout.metadata(), "logs")) == ["mylogs.txt"] | ||
assert load(os.path.join(pref_layout.metadata(), "logs", "mylogs.txt")) == "some logs!!!" | ||
|
||
def test_metadata_logs_local(self, _client): | ||
c = _client | ||
c.run("source .") | ||
assert c.load("metadata/logs/src.log") == "srclog!!" | ||
c.run("build .") | ||
assert c.load("mybuild/metadata/logs/mylogs.txt") == "some logs!!!" |