Example #1
0
def test_fromtext_lineterminators():

    data = [b'foo,bar', b'a,1', b'b,2', b'c,2']

    expect = (('lines', ), ('foo,bar', ), ('a,1', ), ('b,2', ), ('c,2', ))

    for lt in b'\r', b'\n', b'\r\n':
        f = NamedTemporaryFile(mode='wb', delete=False)
        f.write(lt.join(data))
        f.close()
        actual = fromtext(f.name, encoding='ascii')
        ieq(expect, actual)
Example #2
0
def test_fromtext():

    # initial data
    f = NamedTemporaryFile(delete=False, mode='wb')
    f.write(b'foo\tbar\n')
    f.write(b'a\t1\n')
    f.write(b'b\t2\n')
    f.write(b'c\t3\n')
    f.close()

    actual = fromtext(f.name, encoding='ascii')
    expect = (('lines', ), ('foo\tbar', ), ('a\t1', ), ('b\t2', ), ('c\t3', ))
    ieq(expect, actual)
    ieq(expect, actual)  # verify can iterate twice
Example #3
0
def test_fromtext():

    # initial data
    f = NamedTemporaryFile(delete=False)
    f.write("foo\tbar\n")
    f.write("a\t1\n")
    f.write("b\t2\n")
    f.write("c\t3\n")
    f.close()

    actual = fromtext(f.name)
    expect = (("lines",), ("foo\tbar",), ("a\t1",), ("b\t2",), ("c\t3",))
    ieq(expect, actual)
    ieq(expect, actual)  # verify can iterate twice
Example #4
0
def test_fromtext():

    # initial data
    f = NamedTemporaryFile(delete=False, mode='wb')
    f.write(b'foo\tbar\n')
    f.write(b'a\t1\n')
    f.write(b'b\t2\n')
    f.write(b'c\t3\n')
    f.close()

    actual = fromtext(f.name, encoding='ascii')
    expect = (('lines',),
              ('foo\tbar',),
              ('a\t1',),
              ('b\t2',),
              ('c\t3',))
    ieq(expect, actual)
    ieq(expect, actual)  # verify can iterate twice
Example #5
0
def test_fromtext_lineterminators():

    data = [b'foo,bar',
            b'a,1',
            b'b,2',
            b'c,2']

    expect = (('lines',),
              ('foo,bar',),
              ('a,1',),
              ('b,2',),
              ('c,2',))

    for lt in b'\r', b'\n', b'\r\n':
        f = NamedTemporaryFile(mode='wb', delete=False)
        f.write(lt.join(data))
        f.close()
        actual = fromtext(f.name, encoding='ascii')
        ieq(expect, actual)
Example #6
0
def test_fromtext_gz():

    # initial data
    f = NamedTemporaryFile(delete=False)
    f.close()
    fn = f.name + '.gz'
    os.rename(f.name, fn)
    f = gzip.open(fn, 'wb')
    try:
        f.write(b'foo\tbar\n')
        f.write(b'a\t1\n')
        f.write(b'b\t2\n')
        f.write(b'c\t3\n')
    finally:
        f.close()

    actual = fromtext(fn, encoding='ascii')
    expect = (('lines', ), ('foo\tbar', ), ('a\t1', ), ('b\t2', ), ('c\t3', ))
    ieq(expect, actual)
    ieq(expect, actual)  # verify can iterate twice
Example #7
0
def test_fromtext_gz():

    # initial data
    f = NamedTemporaryFile(delete=False)
    f.close()
    fn = f.name + ".gz"
    os.rename(f.name, fn)
    f = gzip.open(fn, "wb")
    try:
        f.write("foo\tbar\n")
        f.write("a\t1\n")
        f.write("b\t2\n")
        f.write("c\t3\n")
    finally:
        f.close()

    actual = fromtext(fn)
    expect = (("lines",), ("foo\tbar",), ("a\t1",), ("b\t2",), ("c\t3",))
    ieq(expect, actual)
    ieq(expect, actual)  # verify can iterate twice
Example #8
0
def test_fromtext():
    data = (u"name,id\n"
            u"Արամ Խաչատրյան,1\n"
            u"Johann Strauß,2\n"
            u"Вагиф Сәмәдоғлу,3\n"
            u"章子怡,4\n")
    fn = NamedTemporaryFile().name
    f = io.open(fn, encoding='utf-8', mode='wt')
    f.write(data)
    f.close()

    actual = fromtext(fn, encoding='utf-8')
    expect = (
        (u'lines', ),
        (u'name,id', ),
        (u'Արամ Խաչատրյան,1', ),
        (u'Johann Strauß,2', ),
        (u'Вагиф Сәмәдоғлу,3', ),
        (u'章子怡,4', ),
    )
    ieq(expect, actual)
    ieq(expect, actual)  # verify can iterate twice
Example #9
0
def test_fromtext():
    data = (
        u"name,id\n"
        u"Արամ Խաչատրյան,1\n"
        u"Johann Strauß,2\n"
        u"Вагиф Сәмәдоғлу,3\n"
        u"章子怡,4\n"
    )
    fn = NamedTemporaryFile().name
    f = io.open(fn, encoding='utf-8', mode='wt')
    f.write(data)
    f.close()

    actual = fromtext(fn, encoding='utf-8')
    expect = ((u'lines',),
              (u'name,id',),
              (u'Արամ Խաչատրյան,1',),
              (u'Johann Strauß,2',),
              (u'Вагиф Сәмәдоғлу,3',),
              (u'章子怡,4',),
              )
    ieq(expect, actual)
    ieq(expect, actual)  # verify can iterate twice
Example #10
0
def test_fromtext_gz():

    # initial data
    f = NamedTemporaryFile(delete=False)
    f.close()
    fn = f.name + '.gz'
    os.rename(f.name, fn)
    f = gzip.open(fn, 'wb')
    try:
        f.write(b'foo\tbar\n')
        f.write(b'a\t1\n')
        f.write(b'b\t2\n')
        f.write(b'c\t3\n')
    finally:
        f.close()

    actual = fromtext(fn, encoding='ascii')
    expect = (('lines',),
              ('foo\tbar',),
              ('a\t1',),
              ('b\t2',),
              ('c\t3',))
    ieq(expect, actual)
    ieq(expect, actual)  # verify can iterate twice