Esempio n. 1
0
 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)
Esempio n. 2
0
 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)])
Esempio n. 3
0
 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])
Esempio n. 4
0
 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)
Esempio n. 5
0
 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])
Esempio n. 6
0
 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)
Esempio n. 7
0
 def _check_output(self):
     exported = json.loads(to_unicode(self.output.getvalue().strip()))
     self.assertEqual(exported, [dict(self.i)])
Esempio n. 8
0
 def _check_output(self):
     self.assertCsvEqual(to_unicode(self.output.getvalue()),
                         'age,name\r\n22,John£\r\n')