def test_prepare_to_export_with_FlexibleTable(self): flexible = rows.FlexibleTable() for row in utils.table: flexible.append(row._asdict()) field_names = list(flexible.fields.keys()) prepared = plugins_utils.prepare_to_export(flexible) self.assertEqual(next(prepared), field_names) for row, expected_row in zip(prepared, flexible._rows): values = [expected_row[field_name] for field_name in field_names] self.assertEqual(values, row)
def test_prepare_to_export_with_FlexibleTable_and_export_fields(self): flexible = rows.FlexibleTable() for row in utils.table: flexible.append(row._asdict()) field_names = flexible.fields.keys() field_types = flexible.fields.values() export_fields = field_names[:len(field_names) // 2] prepared = plugins_utils.prepare_to_export(flexible, export_fields=export_fields) self.assertEqual(prepared.next(), export_fields) for row, expected_row in zip(prepared, flexible._rows): values = [expected_row[field_name] for field_name in export_fields] self.assertEqual(values, row)
def test_prepare_to_export_with_FlexibleTable_and_export_fields(self): flexible = rows.FlexibleTable() for row in utils.table: # convertion to text_type is needed on Python 2 since namedtuples' # keys are bytes, not unicode flexible.append( {six.text_type(key): value for key, value in row._asdict().items()} ) field_names = list(flexible.fields.keys()) export_fields = field_names[: len(field_names) // 2] print([(x, type(x)) for x in export_fields]) prepared = plugins_utils.prepare_to_export( flexible, export_fields=export_fields ) self.assertEqual(next(prepared), export_fields) for row, expected_row in zip(prepared, flexible._rows): values = [expected_row[field_name] for field_name in export_fields] self.assertEqual(values, row)