Beispiel #1
0
 def test_reader_as_list(self):
     f = StringIO(u'key,value\nhello,world\nhello,camper\nfoo,bar\n')
     a = read_map_from_csv(key='key',
                           value='value',
                           f=f,
                           delimiter=',',
                           as_list=True)
     self.assertEqual(a['hello'], ['world', 'camper'])
Beispiel #2
0
 def test_reader_fail(self):
     o = [
         (0, 'bla', 'value', u'key,value\nhello,world\nhappy,camper\n', ',',
          None, False, False, False, DefinitionException),
         (1, 'key', 'bla', u'key,value\nhello,world\nhappy,camper\n', ',',
          None, False, False, False, DefinitionException),
         (2, 0, 'value', u'key,value\nhello,world\nhappy,camper\n', ',',
          None, False, False, False, DefinitionException),
         (3, 'key', 0, u'key,value\nhello,world\nhappy,camper\n', ',', None,
          False, False, False, DefinitionException),
         (4, 'key', 'value', u'key,value\nhello,world\nhello,camper\n', ',',
          1, False, False, False, None),
         (5, 'key', 'value', u'key,value\nhello,world\nhello,camper\n', ',',
          None, True, False, False, NonUniqueDataException),
         (6, 'key', 'value', u'key;value\nhello;world\nhello;camper\n', ';',
          1, False, False, False, None),
         (7, 'key', 'value', u'key;value\nhello;world\nhello;camper\n', ';',
          1, False, False, True, None),
         (8, 'key', 'value', u'key;value\nhallo;world\nhello;camper\n', ';',
          2, False, False, True, None),
     ]
     for row, key, value, data, delim, size, u, first, as_list, exc in o:
         f = StringIO(data)
         if exc:
             with self.assertRaises(exc) as err:
                 read_map_from_csv(key=key,
                                   value=value,
                                   f=f,
                                   delimiter=delim,
                                   unique=u,
                                   first=first)
                 self.assertEqual(exc, err, "%d failed" % row)
         else:
             self.assertEqual(
                 len(
                     read_map_from_csv(key=key,
                                       value=value,
                                       f=f,
                                       delimiter=delim,
                                       unique=u,
                                       first=first,
                                       as_list=as_list)), size,
                 "%d failed" % row)
Beispiel #3
0
 def test_reader_no_header_reverse(self):
     f = StringIO(u'hello,world\nhappy,camper\n')
     a = read_map_from_csv(key=1, value=0, header=False, f=f, delimiter=',')
     self.assertIn('world', a)
Beispiel #4
0
 def test_reader_no_header_default(self):
     f = StringIO(u'hello,world\nhappy,camper\n')
     a = read_map_from_csv(header=False, f=f, delimiter=',')
     self.assertIn('hello', a)
Beispiel #5
0
 def test_reader(self):
     f = StringIO(u'key,value\nhello,world\nhappy,camper\n')
     a = read_map_from_csv(key='key', value='value', f=f, delimiter=',')
     self.assertIn('hello', a)