def fill_out_resources(self, resources): """Fill out the resources""" for resource in as_list(resources): if isinstance(resource, six.string_types): yield resource elif isinstance(resource, dict): for resource in self.expand_resource(resource): yield resource else: raise BadPolicy("Resource should be a string or a dictionary", resource=resource)
for val in (0, 1, None, True, False, "", "adf", lambda: 1, mock.Mock(name="blah")): dct = {"blah": val} lst = listify(dct, "blah") self.assertEqual(lst, [val]) self.assertEqual(dct, {"blah": lst}) describe TestCase, "listified": it "yields nothing if the key isn't in the dict": self.assertEqual(list(listified({"meh": 1}, "blah")), []) it "yields the thing if the thing is not a list": for val in (0, 1, None, True, False, "", "adf", lambda: 1, mock.Mock(name="blah")): self.assertEqual(list(listified({"blah": val}, "blah")), [val]) it "yields the items in the thing if the thing is a list": item1 = 3 item2 = 1 item3 = 2 lst = [item1, item2, item3] self.assertEqual(list(listified({"blah": lst}, "blah")), [item1, item2, item3]) describe TestCase, "as_list": it "yields the things in the thing if it's a list": lst = [1, 2] self.assertEqual(list(as_list(lst)), lst) it "yields just the thing if not a list": for val in (0, 1, None, True, False, "", "adf", lambda: 1, mock.Mock(name="blah")): self.assertEqual(list(as_list(val)), [val])