# Path: django_sonic_screwdriver/iterables.py
# def count(iterable):
#     """
#     Counts the numbers of elements of the iterable.
#     """
#     if hasattr(iterable, "__len__"):
#         return len(iterable)
# 
#     d = collections.deque(enumerate(iterable, 1), maxlen=1)
#     return d[0][0] if d else 0
# 
# def get_iterable(data):
#     """
#     Returns iterable data.
#     """
#     if isinstance(data, QueryDict):
#         return data.lists()
#     else:
#         return data.items()
# 
# def is_iterable(obj):
#     """
#     Check if obj is iterable.
#     """
#     try:
#         iter(obj)
#     except TypeError:
#         return False
#     else:
#         return True


from collections.abc import Iterable
from django.http import QueryDict
from django.test import TestCase
from django_sonic_screwdriver.iterables import count, get_iterable, is_iterable



class IterablesTest(TestCase):
    def test_count(self):
        data = {"key": "value"}
        self.assertEqual(count(data), 1)
        self.assertEqual(count(iter(data)), 1)
        with self.assertRaises(TypeError):
            self.assertEqual(count(1), 0)

    def test_get_iterable(self):
        data = {"key": "value"}
        self.assertEqual(get_iterable(data), data.items())

        data = QueryDict("AParam=1&AnotherParam=2&c=3")

# Path: django_sonic_screwdriver/iterables.py
# def count(iterable):
#     """
#     Counts the numbers of elements of the iterable.
#     """
#     if hasattr(iterable, "__len__"):
#         return len(iterable)
# 
#     d = collections.deque(enumerate(iterable, 1), maxlen=1)
#     return d[0][0] if d else 0
# 
# def get_iterable(data):
#     """
#     Returns iterable data.
#     """
#     if isinstance(data, QueryDict):
#         return data.lists()
#     else:
#         return data.items()
# 
# def is_iterable(obj):
#     """
#     Check if obj is iterable.
#     """
#     try:
#         iter(obj)
#     except TypeError:
#         return False
#     else:
#         return True


# Path: tests/test_iterables.py
from collections.abc import Iterable
from django.http import QueryDict
from django.test import TestCase
from django_sonic_screwdriver.iterables import count, get_iterable, is_iterable




class IterablesTest(TestCase):
    def test_count(self):
        data = {"key": "value"}
        self.assertEqual(count(data), 1)
        self.assertEqual(count(iter(data)), 1)
        with self.assertRaises(TypeError):
            self.assertEqual(count(1), 0)

    def test_get_iterable(self):
        data = {"key": "value"}
        self.assertEqual(get_iterable(data), data.items())

        data = QueryDict("AParam=1&AnotherParam=2&c=3")

        self.assertTrue(isinstance(get_iterable(data), Iterable))