def test_csv_export_extra_data(self):
        """Ensures exported CSV data matches source data"""
        qs_filter = { "pk__in": [x.pk for x in self.snapshots] }
        qs = BuildingSnapshot.objects.filter(**qs_filter)

        fields = list(_get_fields_from_queryset(qs))
        fields.append("canonical_building__id")
        fields.append('my new field')

        export_filename = export_csv(qs, fields)
        export_file = open(export_filename)

        reader = csv.reader(export_file)
        header = reader.next()

        self.assertEqual(header[len(fields)-1], 'my new field')

        for i in range(len(self.snapshots)):
            row = reader.next()
            for j in range(len(fields)):
                field = fields[j]
                components = field.split("__")
                qs_val = qs[i]
                for component in components:
                    try:
                        qs_val = getattr(qs_val, component)
                    except __HOLE__:
                        qs_val = qs_val.extra_data.get(component)
                    if qs_val == None:
                        break
                if isinstance(qs_val, Manager) or qs_val == None: qs_val = u''
                else: qs_val = unicode(qs_val)
                csv_val = row[j]
                self.assertEqual(qs_val, csv_val)

        export_file.close()
        os.remove(export_filename)
dataset/ETHPy150Open buildingenergy/buildingenergy-platform/seed/tests/test_exporters.py/TestExporters.test_csv_export_extra_data