def test_invalid_input(self): source = ['x', 1, 'y', 2] with self.assertRaises(TypeError): normalized = _get_iteritems(source) source = [{'x': 1}, {'y': 2}] with self.assertRaises(TypeError): normalized = _get_iteritems(source)
def test_list_of_items(self): items = _get_iteritems([('a', 1), ('b', 2)]) self.assertEqual(list(items), [('a', 1), ('b', 2)])
def test_get_iteritems(self): items_iter = _get_iteritems([('a', 1), ('b', 2)]) self.assertTrue(_is_collection_of_items(items_iter))
def test_Query(self): source = Select([('A', 'B'), ('x', 1), ('y', 2)]) query = source({'A': 'B'}).apply(lambda x: next(x)) normalized = _get_iteritems(query) self.assertEqual(list(normalized), [('x', 1), ('y', 2)])
def test_Result(self): result = Result(_get_iteritems([('a', 1), ('b', 2)]), evaltype=dict) normalized = _get_iteritems(result) self.assertEqual(list(normalized), [('a', 1), ('b', 2)])
def test_empty_iterable(self): items = _get_iteritems(iter([])) self.assertEqual(list(items), [])
def test_dict(self): items = _get_iteritems({'a': 1, 'b': 2}) self.assertEqual(set(items), set([('a', 1), ('b', 2)]))