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

Accept a list for the requires attribute #5371

Merged
merged 2 commits into from
Jun 19, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion conans/model/conan_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, )
Expand Down
Empty file.
49 changes: 49 additions & 0 deletions conans/test/unittests/model/conan_file/create_requirements_test.py
Original file line number Diff line number Diff line change
@@ -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", ])