author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 25 Mar 2015 07:57:38 +0100 | |
changeset 10285 | d14db30b90d6 |
parent 9909 | e2d42ad10f98 |
child 10286 | 0f8c3ac88f1e |
permissions | -rw-r--r-- |
9903
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
1 |
# -*- coding: utf-8 -*- |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
2 |
import datetime as DT |
9181
2eac0aa1d3f6
[dataimport] ucsvreader should skip empty lines unless specified otherwise. Closes #3035944
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
3 |
from StringIO import StringIO |
2eac0aa1d3f6
[dataimport] ucsvreader should skip empty lines unless specified otherwise. Closes #3035944
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
4 |
from logilab.common.testlib import TestCase, unittest_main |
2eac0aa1d3f6
[dataimport] ucsvreader should skip empty lines unless specified otherwise. Closes #3035944
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
5 |
from cubicweb import dataimport |
9909
e2d42ad10f98
[test] Add test for dataimport's RQLObjectStore
Julien Cristau <julien.cristau@logilab.fr>
parents:
9903
diff
changeset
|
6 |
from cubicweb.devtools.testlib import CubicWebTC |
e2d42ad10f98
[test] Add test for dataimport's RQLObjectStore
Julien Cristau <julien.cristau@logilab.fr>
parents:
9903
diff
changeset
|
7 |
|
e2d42ad10f98
[test] Add test for dataimport's RQLObjectStore
Julien Cristau <julien.cristau@logilab.fr>
parents:
9903
diff
changeset
|
8 |
|
e2d42ad10f98
[test] Add test for dataimport's RQLObjectStore
Julien Cristau <julien.cristau@logilab.fr>
parents:
9903
diff
changeset
|
9 |
class RQLObjectStoreTC(CubicWebTC): |
e2d42ad10f98
[test] Add test for dataimport's RQLObjectStore
Julien Cristau <julien.cristau@logilab.fr>
parents:
9903
diff
changeset
|
10 |
|
e2d42ad10f98
[test] Add test for dataimport's RQLObjectStore
Julien Cristau <julien.cristau@logilab.fr>
parents:
9903
diff
changeset
|
11 |
def test_all(self): |
e2d42ad10f98
[test] Add test for dataimport's RQLObjectStore
Julien Cristau <julien.cristau@logilab.fr>
parents:
9903
diff
changeset
|
12 |
with self.admin_access.repo_cnx() as cnx: |
e2d42ad10f98
[test] Add test for dataimport's RQLObjectStore
Julien Cristau <julien.cristau@logilab.fr>
parents:
9903
diff
changeset
|
13 |
store = dataimport.RQLObjectStore(cnx) |
e2d42ad10f98
[test] Add test for dataimport's RQLObjectStore
Julien Cristau <julien.cristau@logilab.fr>
parents:
9903
diff
changeset
|
14 |
group_eid = store.create_entity('CWGroup', name=u'grp').eid |
e2d42ad10f98
[test] Add test for dataimport's RQLObjectStore
Julien Cristau <julien.cristau@logilab.fr>
parents:
9903
diff
changeset
|
15 |
user_eid = store.create_entity('CWUser', login=u'lgn', upassword=u'pwd').eid |
e2d42ad10f98
[test] Add test for dataimport's RQLObjectStore
Julien Cristau <julien.cristau@logilab.fr>
parents:
9903
diff
changeset
|
16 |
store.relate(user_eid, 'in_group', group_eid) |
e2d42ad10f98
[test] Add test for dataimport's RQLObjectStore
Julien Cristau <julien.cristau@logilab.fr>
parents:
9903
diff
changeset
|
17 |
cnx.commit() |
e2d42ad10f98
[test] Add test for dataimport's RQLObjectStore
Julien Cristau <julien.cristau@logilab.fr>
parents:
9903
diff
changeset
|
18 |
|
e2d42ad10f98
[test] Add test for dataimport's RQLObjectStore
Julien Cristau <julien.cristau@logilab.fr>
parents:
9903
diff
changeset
|
19 |
with self.admin_access.repo_cnx() as cnx: |
e2d42ad10f98
[test] Add test for dataimport's RQLObjectStore
Julien Cristau <julien.cristau@logilab.fr>
parents:
9903
diff
changeset
|
20 |
users = cnx.execute('CWUser X WHERE X login "lgn"') |
e2d42ad10f98
[test] Add test for dataimport's RQLObjectStore
Julien Cristau <julien.cristau@logilab.fr>
parents:
9903
diff
changeset
|
21 |
self.assertEqual(1, len(users)) |
e2d42ad10f98
[test] Add test for dataimport's RQLObjectStore
Julien Cristau <julien.cristau@logilab.fr>
parents:
9903
diff
changeset
|
22 |
self.assertEqual(user_eid, users.one().eid) |
e2d42ad10f98
[test] Add test for dataimport's RQLObjectStore
Julien Cristau <julien.cristau@logilab.fr>
parents:
9903
diff
changeset
|
23 |
groups = cnx.execute('CWGroup X WHERE U in_group X, U login "lgn"') |
e2d42ad10f98
[test] Add test for dataimport's RQLObjectStore
Julien Cristau <julien.cristau@logilab.fr>
parents:
9903
diff
changeset
|
24 |
self.assertEqual(1, len(users)) |
e2d42ad10f98
[test] Add test for dataimport's RQLObjectStore
Julien Cristau <julien.cristau@logilab.fr>
parents:
9903
diff
changeset
|
25 |
self.assertEqual(group_eid, groups.one().eid) |
9695
aa982b7c3f2a
[dataimport] Prevent ucsvreader from skipping the first line when ignore_errors is True (closes #3705791)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9181
diff
changeset
|
26 |
|
9903
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
27 |
class CreateCopyFromBufferTC(TestCase): |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
28 |
|
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
29 |
# test converters |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
30 |
|
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
31 |
def test_convert_none(self): |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
32 |
cnvt = dataimport._copyfrom_buffer_convert_None |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
33 |
self.assertEqual('NULL', cnvt(None)) |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
34 |
|
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
35 |
def test_convert_number(self): |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
36 |
cnvt = dataimport._copyfrom_buffer_convert_number |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
37 |
self.assertEqual('42', cnvt(42)) |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
38 |
self.assertEqual('42', cnvt(42L)) |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
39 |
self.assertEqual('42.42', cnvt(42.42)) |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
40 |
|
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
41 |
def test_convert_string(self): |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
42 |
cnvt = dataimport._copyfrom_buffer_convert_string |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
43 |
# simple |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
44 |
self.assertEqual('babar', cnvt('babar')) |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
45 |
# unicode |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
46 |
self.assertEqual('\xc3\xa9l\xc3\xa9phant', cnvt(u'éléphant')) |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
47 |
self.assertEqual('\xe9l\xe9phant', cnvt(u'éléphant', encoding='latin1')) |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
48 |
self.assertEqual('babar#', cnvt('babar\t', replace_sep='#')) |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
49 |
self.assertRaises(ValueError, cnvt, 'babar\t') |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
50 |
|
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
51 |
def test_convert_date(self): |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
52 |
cnvt = dataimport._copyfrom_buffer_convert_date |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
53 |
self.assertEqual('0666-01-13', cnvt(DT.date(666, 1, 13))) |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
54 |
|
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
55 |
def test_convert_time(self): |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
56 |
cnvt = dataimport._copyfrom_buffer_convert_time |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
57 |
self.assertEqual('06:06:06.000100', cnvt(DT.time(6, 6, 6, 100))) |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
58 |
|
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
59 |
def test_convert_datetime(self): |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
60 |
cnvt = dataimport._copyfrom_buffer_convert_datetime |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
61 |
self.assertEqual('0666-06-13 06:06:06.000000', cnvt(DT.datetime(666, 6, 13, 6, 6, 6))) |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
62 |
|
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
63 |
# test buffer |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
64 |
def test_create_copyfrom_buffer_tuple(self): |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
65 |
cnvt = dataimport._create_copyfrom_buffer |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
66 |
data = ((42, 42L, 42.42, u'éléphant', DT.date(666, 1, 13), DT.time(6, 6, 6), DT.datetime(666, 6, 13, 6, 6, 6)), |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
67 |
(6, 6L, 6.6, u'babar', DT.date(2014, 1, 14), DT.time(4, 2, 1), DT.datetime(2014, 1, 1, 0, 0, 0))) |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
68 |
results = dataimport._create_copyfrom_buffer(data) |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
69 |
# all columns |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
70 |
expected = '''42\t42\t42.42\téléphant\t0666-01-13\t06:06:06.000000\t0666-06-13 06:06:06.000000 |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
71 |
6\t6\t6.6\tbabar\t2014-01-14\t04:02:01.000000\t2014-01-01 00:00:00.000000''' |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
72 |
self.assertMultiLineEqual(expected, results.getvalue()) |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
73 |
# selected columns |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
74 |
results = dataimport._create_copyfrom_buffer(data, columns=(1, 3, 6)) |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
75 |
expected = '''42\téléphant\t0666-06-13 06:06:06.000000 |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
76 |
6\tbabar\t2014-01-01 00:00:00.000000''' |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
77 |
self.assertMultiLineEqual(expected, results.getvalue()) |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
78 |
|
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
79 |
def test_create_copyfrom_buffer_dict(self): |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
80 |
cnvt = dataimport._create_copyfrom_buffer |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
81 |
data = (dict(integer=42, double=42.42, text=u'éléphant', date=DT.datetime(666, 6, 13, 6, 6, 6)), |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
82 |
dict(integer=6, double=6.6, text=u'babar', date=DT.datetime(2014, 1, 1, 0, 0, 0))) |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
83 |
results = dataimport._create_copyfrom_buffer(data, ('integer', 'text')) |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
84 |
expected = '''42\téléphant\n6\tbabar''' |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
85 |
self.assertMultiLineEqual(expected, results.getvalue()) |
d1fdbdbab194
[dataimport] _create_copyfrom_buffer: add the tests
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
9695
diff
changeset
|
86 |
|
9695
aa982b7c3f2a
[dataimport] Prevent ucsvreader from skipping the first line when ignore_errors is True (closes #3705791)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9181
diff
changeset
|
87 |
|
9181
2eac0aa1d3f6
[dataimport] ucsvreader should skip empty lines unless specified otherwise. Closes #3035944
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
88 |
class UcsvreaderTC(TestCase): |
2eac0aa1d3f6
[dataimport] ucsvreader should skip empty lines unless specified otherwise. Closes #3035944
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
89 |
|
2eac0aa1d3f6
[dataimport] ucsvreader should skip empty lines unless specified otherwise. Closes #3035944
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
90 |
def test_empty_lines_skipped(self): |
2eac0aa1d3f6
[dataimport] ucsvreader should skip empty lines unless specified otherwise. Closes #3035944
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
91 |
stream = StringIO('''a,b,c,d, |
2eac0aa1d3f6
[dataimport] ucsvreader should skip empty lines unless specified otherwise. Closes #3035944
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
92 |
1,2,3,4, |
2eac0aa1d3f6
[dataimport] ucsvreader should skip empty lines unless specified otherwise. Closes #3035944
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
93 |
,,,, |
2eac0aa1d3f6
[dataimport] ucsvreader should skip empty lines unless specified otherwise. Closes #3035944
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
94 |
,,,, |
2eac0aa1d3f6
[dataimport] ucsvreader should skip empty lines unless specified otherwise. Closes #3035944
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
95 |
''') |
2eac0aa1d3f6
[dataimport] ucsvreader should skip empty lines unless specified otherwise. Closes #3035944
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
96 |
self.assertEqual([[u'a', u'b', u'c', u'd', u''], |
2eac0aa1d3f6
[dataimport] ucsvreader should skip empty lines unless specified otherwise. Closes #3035944
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
97 |
[u'1', u'2', u'3', u'4', u''], |
2eac0aa1d3f6
[dataimport] ucsvreader should skip empty lines unless specified otherwise. Closes #3035944
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
98 |
], |
2eac0aa1d3f6
[dataimport] ucsvreader should skip empty lines unless specified otherwise. Closes #3035944
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
99 |
list(dataimport.ucsvreader(stream))) |
2eac0aa1d3f6
[dataimport] ucsvreader should skip empty lines unless specified otherwise. Closes #3035944
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
100 |
stream.seek(0) |
2eac0aa1d3f6
[dataimport] ucsvreader should skip empty lines unless specified otherwise. Closes #3035944
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
101 |
self.assertEqual([[u'a', u'b', u'c', u'd', u''], |
2eac0aa1d3f6
[dataimport] ucsvreader should skip empty lines unless specified otherwise. Closes #3035944
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
102 |
[u'1', u'2', u'3', u'4', u''], |
2eac0aa1d3f6
[dataimport] ucsvreader should skip empty lines unless specified otherwise. Closes #3035944
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
103 |
[u'', u'', u'', u'', u''], |
2eac0aa1d3f6
[dataimport] ucsvreader should skip empty lines unless specified otherwise. Closes #3035944
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
104 |
[u'', u'', u'', u'', u''] |
2eac0aa1d3f6
[dataimport] ucsvreader should skip empty lines unless specified otherwise. Closes #3035944
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
105 |
], |
2eac0aa1d3f6
[dataimport] ucsvreader should skip empty lines unless specified otherwise. Closes #3035944
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
106 |
list(dataimport.ucsvreader(stream, skip_empty=False))) |
2eac0aa1d3f6
[dataimport] ucsvreader should skip empty lines unless specified otherwise. Closes #3035944
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
107 |
|
9695
aa982b7c3f2a
[dataimport] Prevent ucsvreader from skipping the first line when ignore_errors is True (closes #3705791)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9181
diff
changeset
|
108 |
def test_skip_first(self): |
aa982b7c3f2a
[dataimport] Prevent ucsvreader from skipping the first line when ignore_errors is True (closes #3705791)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9181
diff
changeset
|
109 |
stream = StringIO('a,b,c,d,\n' |
aa982b7c3f2a
[dataimport] Prevent ucsvreader from skipping the first line when ignore_errors is True (closes #3705791)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9181
diff
changeset
|
110 |
'1,2,3,4,\n') |
aa982b7c3f2a
[dataimport] Prevent ucsvreader from skipping the first line when ignore_errors is True (closes #3705791)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9181
diff
changeset
|
111 |
reader = dataimport.ucsvreader(stream, skipfirst=True, |
aa982b7c3f2a
[dataimport] Prevent ucsvreader from skipping the first line when ignore_errors is True (closes #3705791)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9181
diff
changeset
|
112 |
ignore_errors=True) |
aa982b7c3f2a
[dataimport] Prevent ucsvreader from skipping the first line when ignore_errors is True (closes #3705791)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9181
diff
changeset
|
113 |
self.assertEqual(list(reader), |
aa982b7c3f2a
[dataimport] Prevent ucsvreader from skipping the first line when ignore_errors is True (closes #3705791)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9181
diff
changeset
|
114 |
[[u'1', u'2', u'3', u'4', u'']]) |
aa982b7c3f2a
[dataimport] Prevent ucsvreader from skipping the first line when ignore_errors is True (closes #3705791)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9181
diff
changeset
|
115 |
|
aa982b7c3f2a
[dataimport] Prevent ucsvreader from skipping the first line when ignore_errors is True (closes #3705791)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9181
diff
changeset
|
116 |
stream.seek(0) |
aa982b7c3f2a
[dataimport] Prevent ucsvreader from skipping the first line when ignore_errors is True (closes #3705791)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9181
diff
changeset
|
117 |
reader = dataimport.ucsvreader(stream, skipfirst=True, |
aa982b7c3f2a
[dataimport] Prevent ucsvreader from skipping the first line when ignore_errors is True (closes #3705791)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9181
diff
changeset
|
118 |
ignore_errors=False) |
aa982b7c3f2a
[dataimport] Prevent ucsvreader from skipping the first line when ignore_errors is True (closes #3705791)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9181
diff
changeset
|
119 |
self.assertEqual(list(reader), |
aa982b7c3f2a
[dataimport] Prevent ucsvreader from skipping the first line when ignore_errors is True (closes #3705791)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9181
diff
changeset
|
120 |
[[u'1', u'2', u'3', u'4', u'']]) |
aa982b7c3f2a
[dataimport] Prevent ucsvreader from skipping the first line when ignore_errors is True (closes #3705791)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9181
diff
changeset
|
121 |
|
aa982b7c3f2a
[dataimport] Prevent ucsvreader from skipping the first line when ignore_errors is True (closes #3705791)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9181
diff
changeset
|
122 |
stream.seek(0) |
aa982b7c3f2a
[dataimport] Prevent ucsvreader from skipping the first line when ignore_errors is True (closes #3705791)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9181
diff
changeset
|
123 |
reader = dataimport.ucsvreader(stream, skipfirst=False, |
aa982b7c3f2a
[dataimport] Prevent ucsvreader from skipping the first line when ignore_errors is True (closes #3705791)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9181
diff
changeset
|
124 |
ignore_errors=True) |
aa982b7c3f2a
[dataimport] Prevent ucsvreader from skipping the first line when ignore_errors is True (closes #3705791)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9181
diff
changeset
|
125 |
self.assertEqual(list(reader), |
aa982b7c3f2a
[dataimport] Prevent ucsvreader from skipping the first line when ignore_errors is True (closes #3705791)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9181
diff
changeset
|
126 |
[[u'a', u'b', u'c', u'd', u''], |
aa982b7c3f2a
[dataimport] Prevent ucsvreader from skipping the first line when ignore_errors is True (closes #3705791)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9181
diff
changeset
|
127 |
[u'1', u'2', u'3', u'4', u'']]) |
aa982b7c3f2a
[dataimport] Prevent ucsvreader from skipping the first line when ignore_errors is True (closes #3705791)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9181
diff
changeset
|
128 |
|
aa982b7c3f2a
[dataimport] Prevent ucsvreader from skipping the first line when ignore_errors is True (closes #3705791)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9181
diff
changeset
|
129 |
stream.seek(0) |
aa982b7c3f2a
[dataimport] Prevent ucsvreader from skipping the first line when ignore_errors is True (closes #3705791)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9181
diff
changeset
|
130 |
reader = dataimport.ucsvreader(stream, skipfirst=False, |
aa982b7c3f2a
[dataimport] Prevent ucsvreader from skipping the first line when ignore_errors is True (closes #3705791)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9181
diff
changeset
|
131 |
ignore_errors=False) |
aa982b7c3f2a
[dataimport] Prevent ucsvreader from skipping the first line when ignore_errors is True (closes #3705791)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9181
diff
changeset
|
132 |
self.assertEqual(list(reader), |
aa982b7c3f2a
[dataimport] Prevent ucsvreader from skipping the first line when ignore_errors is True (closes #3705791)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9181
diff
changeset
|
133 |
[[u'a', u'b', u'c', u'd', u''], |
aa982b7c3f2a
[dataimport] Prevent ucsvreader from skipping the first line when ignore_errors is True (closes #3705791)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9181
diff
changeset
|
134 |
[u'1', u'2', u'3', u'4', u'']]) |
aa982b7c3f2a
[dataimport] Prevent ucsvreader from skipping the first line when ignore_errors is True (closes #3705791)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9181
diff
changeset
|
135 |
|
9181
2eac0aa1d3f6
[dataimport] ucsvreader should skip empty lines unless specified otherwise. Closes #3035944
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
136 |
|
2eac0aa1d3f6
[dataimport] ucsvreader should skip empty lines unless specified otherwise. Closes #3035944
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
137 |
if __name__ == '__main__': |
2eac0aa1d3f6
[dataimport] ucsvreader should skip empty lines unless specified otherwise. Closes #3035944
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
138 |
unittest_main() |