# Path: rows/fields.py
# @property
# def fields(self):
#     possible, skip = self._possible_types, self._skip
# 
#     if possible:
#         # Create a header with placeholder values for each detected column
#         # and then join this placeholders with original header - the
#         # original header may have less columns then the detected ones, so
#         # we end with a full header having a name for every possible
#         # column.
#         placeholders = make_header(range(max(possible.keys()) + 1))
#         header = [a or b for a, b in zip_longest(self.field_names, placeholders)]
#     else:
#         header = self.field_names
# 
#     return OrderedDict(
#         [
#             (
#                 field_name,
#                 self.define_field_type(
#                     is_empty=self._is_empty[index],
#                     possible_types=possible[index] if index in possible else [],
#                 ),
#             )
#             for index, field_name in enumerate(header)
#             if index not in skip
#         ]
#     )


import itertools
import random
import types
import unittest
import mock
import six
import rows
import rows.plugins.utils as plugins_utils
import tests.utils as utils
from collections import OrderedDict
from rows import fields
        """`prepare_to_export` raises exception if obj isn't `*Table`"""

        expected_message = "Table type not recognized"

        with self.assertRaises(ValueError) as exception_context:
            next(plugins_utils.prepare_to_export(1))
        self.assertEqual(exception_context.exception.args[0], expected_message)

        with self.assertRaises(ValueError) as exception_context:
            next(plugins_utils.prepare_to_export(42.0))
        self.assertEqual(exception_context.exception.args[0], expected_message)

        with self.assertRaises(ValueError) as exception_context:
            next(plugins_utils.prepare_to_export([list("abc"), [1, 2, 3]]))
        self.assertEqual(exception_context.exception.args[0], expected_message)

    @mock.patch("rows.plugins.utils.prepare_to_export", return_value=iter([[], [], []]))
    def test_serialize_should_call_prepare_to_export(self, mocked_prepare_to_export):
        table = utils.table
        kwargs = {"export_fields": 123, "other_parameter": 3.14}
        result = plugins_utils.serialize(table, **kwargs)
        self.assertFalse(mocked_prepare_to_export.called)
        field_names, table_rows = next(result), list(result)
        self.assertTrue(mocked_prepare_to_export.called)
        self.assertEqual(mocked_prepare_to_export.call_count, 1)
        self.assertEqual(mock.call(table, **kwargs), mocked_prepare_to_export.call_args)

    def test_serialize(self):
        result = plugins_utils.serialize(utils.table)
        field_types = list(utils.table.fields.values())

# Path: rows/fields.py
# @property
# def fields(self):
#     possible, skip = self._possible_types, self._skip
# 
#     if possible:
#         # Create a header with placeholder values for each detected column
#         # and then join this placeholders with original header - the
#         # original header may have less columns then the detected ones, so
#         # we end with a full header having a name for every possible
#         # column.
#         placeholders = make_header(range(max(possible.keys()) + 1))
#         header = [a or b for a, b in zip_longest(self.field_names, placeholders)]
#     else:
#         header = self.field_names
# 
#     return OrderedDict(
#         [
#             (
#                 field_name,
#                 self.define_field_type(
#                     is_empty=self._is_empty[index],
#                     possible_types=possible[index] if index in possible else [],
#                 ),
#             )
#             for index, field_name in enumerate(header)
#             if index not in skip
#         ]
#     )


# Path: tests/tests_plugin_utils.py
import itertools
import random
import types
import unittest
import mock
import six
import rows
import rows.plugins.utils as plugins_utils
import tests.utils as utils
from collections import OrderedDict
from rows import fields

        """`prepare_to_export` raises exception if obj isn't `*Table`"""

        expected_message = "Table type not recognized"

        with self.assertRaises(ValueError) as exception_context:
            next(plugins_utils.prepare_to_export(1))
        self.assertEqual(exception_context.exception.args[0], expected_message)

        with self.assertRaises(ValueError) as exception_context:
            next(plugins_utils.prepare_to_export(42.0))
        self.assertEqual(exception_context.exception.args[0], expected_message)

        with self.assertRaises(ValueError) as exception_context:
            next(plugins_utils.prepare_to_export([list("abc"), [1, 2, 3]]))
        self.assertEqual(exception_context.exception.args[0], expected_message)

    @mock.patch("rows.plugins.utils.prepare_to_export", return_value=iter([[], [], []]))
    def test_serialize_should_call_prepare_to_export(self, mocked_prepare_to_export):
        table = utils.table
        kwargs = {"export_fields": 123, "other_parameter": 3.14}
        result = plugins_utils.serialize(table, **kwargs)
        self.assertFalse(mocked_prepare_to_export.called)
        field_names, table_rows = next(result), list(result)
        self.assertTrue(mocked_prepare_to_export.called)
        self.assertEqual(mocked_prepare_to_export.call_count, 1)
        self.assertEqual(mock.call(table, **kwargs), mocked_prepare_to_export.call_args)

    def test_serialize(self):
        result = plugins_utils.serialize(utils.table)
        field_types = list(utils.table.fields.values())

        self.assertEqual(next(result), list(utils.table.fields.keys()))