def assertCsvEqual(self, first, second, msg=None): first = to_unicode(first) second = to_unicode(second) csvsplit = lambda csv: [ sorted(re.split(r'(,|\s+)', line)) for line in csv.splitlines(True) ] return self.assertEqual(csvsplit(first), csvsplit(second), msg)
def assertTwoItemsExported(self, item): self.ie.start_exporting() self.ie.export_item(item) self.ie.export_item(item) self.ie.finish_exporting() exported = json.loads(to_unicode(self.output.getvalue())) self.assertEqual(exported, [dict(item), dict(item)])
def test_nonstring_types_item(self): item = self._get_nonstring_types_item() self.ie.start_exporting() self.ie.export_item(item) self.ie.finish_exporting() exported = json.loads(to_unicode(self.output.getvalue())) item['time'] = str(item['time']) self.assertEqual(exported, [item])
def test_nested_item(self): i1 = ATestItem(name=u'Joseph', age='22') i2 = dict(name=u'Maria', age=i1) i3 = ATestItem(name=u'Jesus', age=i2) self.ie.start_exporting() self.ie.export_item(i3) self.ie.finish_exporting() exported = json.loads(to_unicode(self.output.getvalue())) self.assertEqual(exported, self._expected_nested)
def test_nested_dict_item(self): i1 = dict(name=u'Joseph\xa3', age='22') i2 = ATestItem(name=u'Maria', age=i1) i3 = dict(name=u'Jesus', age=i2) self.ie.start_exporting() self.ie.export_item(i3) self.ie.finish_exporting() exported = json.loads(to_unicode(self.output.getvalue())) expected = {'name': u'Jesus', 'age': {'name': 'Maria', 'age': i1}} self.assertEqual(exported, [expected])
def _assert_expected_item(self, exported_dict): for k, v in exported_dict.items(): exported_dict[k] = to_unicode(v) self.assertEqual(self.i, exported_dict)
def _check_output(self): exported = json.loads(to_unicode(self.output.getvalue().strip())) self.assertEqual(exported, [dict(self.i)])
def _check_output(self): self.assertCsvEqual(to_unicode(self.output.getvalue()), 'age,name\r\n22,John£\r\n')