From 4a2e7fbb494e26f1901edaf86f5cb00ec78de449 Mon Sep 17 00:00:00 2001 From: "Javier G. Sogo" Date: Wed, 19 Jun 2019 12:49:47 +0200 Subject: [PATCH] Accept a list for the requires attribute (#5371) * accept a list for the requires attribute * use list for requires in a real conanfile --- conans/model/conan_file.py | 2 +- conans/test/integration/conan_test_test.py | 2 +- conans/test/integration/order_libs_test.py | 2 +- .../unittests/model/conan_file/__init__.py | 0 .../conan_file/create_requirements_test.py | 49 +++++++++++++++++++ 5 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 conans/test/unittests/model/conan_file/__init__.py create mode 100644 conans/test/unittests/model/conan_file/create_requirements_test.py diff --git a/conans/model/conan_file.py b/conans/model/conan_file.py index fe5c271b995..ce6c39940aa 100644 --- a/conans/model/conan_file.py +++ b/conans/model/conan_file.py @@ -42,7 +42,7 @@ def create_requirements(conanfile): else: if not conanfile.requires: return Requirements() - if isinstance(conanfile.requires, tuple): + if isinstance(conanfile.requires, (tuple, list)): return Requirements(*conanfile.requires) else: return Requirements(conanfile.requires, ) diff --git a/conans/test/integration/conan_test_test.py b/conans/test/integration/conan_test_test.py index 6b5a8770929..2e37513fdec 100644 --- a/conans/test/integration/conan_test_test.py +++ b/conans/test/integration/conan_test_test.py @@ -39,7 +39,7 @@ def test(conanfile_test, test_reference, path=None): from conans import ConanFile class HelloTestConan(ConanFile): - requires = "Hello/0.1@conan/stable" + requires = ["Hello/0.1@conan/stable", ] def test(self): self.output.warn("Tested ok!") ''', "Hello/0.1@conan/stable") diff --git a/conans/test/integration/order_libs_test.py b/conans/test/integration/order_libs_test.py index ae6616ae565..8a24903a1f5 100644 --- a/conans/test/integration/order_libs_test.py +++ b/conans/test/integration/order_libs_test.py @@ -33,7 +33,7 @@ def package_info(self): conanfile = """from conans import ConanFile class LibCConan(ConanFile): - requires = ("LibB/0.1@user/channel", "private"), "LibC/0.1@user/channel" + requires = [("LibB/0.1@user/channel", "private"), "LibC/0.1@user/channel"] """ client.save({"conanfile.py": conanfile}) client.run("install . -g cmake") diff --git a/conans/test/unittests/model/conan_file/__init__.py b/conans/test/unittests/model/conan_file/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/conans/test/unittests/model/conan_file/create_requirements_test.py b/conans/test/unittests/model/conan_file/create_requirements_test.py new file mode 100644 index 00000000000..15854e14ec0 --- /dev/null +++ b/conans/test/unittests/model/conan_file/create_requirements_test.py @@ -0,0 +1,49 @@ +# coding=utf-8 + +import unittest +from collections import namedtuple + +from conans.model.conan_file import create_requirements + +MockConanFile = namedtuple("MockConanFile", ["requires", ]) + + +class TupleTest(unittest.TestCase): + + def test_implicit_tuple(self): + requires = "req/1.0@user/version", "req2/1.0@user/version" + self.assertEqual(type(requires), tuple) + conanfile = MockConanFile(requires=requires) + r = create_requirements(conanfile) + self.assertListEqual(list(r.keys()), ["req", "req2"]) + + def test_tuple(self): + requires = ("req/1.0@user/version", "req2/1.0@user/version") + self.assertEqual(type(requires), tuple) + conanfile = MockConanFile(requires=requires) + r = create_requirements(conanfile) + self.assertListEqual(list(r.keys()), ["req", "req2"]) + + def test_config_tuple(self): + requires = (("req/1.0@user/version", "private"), ) + self.assertEqual(type(requires), tuple) + conanfile = MockConanFile(requires=requires) + r = create_requirements(conanfile) + self.assertListEqual(list(r.keys()), ["req", ]) + + +class ListTest(unittest.TestCase): + + def test_list(self): + requires = ["req/1.0@user/version", "req2/1.0@user/version"] + self.assertEqual(type(requires), list) + conanfile = MockConanFile(requires=requires) + r = create_requirements(conanfile) + self.assertListEqual(list(r.keys()), ["req", "req2"]) + + def test_config_list(self): + requires = [("req/1.0@user/version", "private"), ] + self.assertEqual(type(requires), list) + conanfile = MockConanFile(requires=requires) + r = create_requirements(conanfile) + self.assertListEqual(list(r.keys()), ["req", ])