Example #1
0
def test_dictwriter_append_header_only():
    fileobj = StringIO()
    writer1 = DictWriter(fileobj, fieldnames=["f1", "f2", "f3"])
    writer1.writeheader()
    assert fileobj.getvalue() == "f1,f2,f3\r\n"

    writer2 = DictWriter.append(fileobj)
    writer2.writerow({"f1": 2, "f2": 5, "f3": "xyz"})
    assert fileobj.getvalue() == "f1,f2,f3\r\n2,5,xyz\r\n"
Example #2
0
def test_dictwriter_append_header_only():
    fileobj = StringIO()
    writer1 = DictWriter(fileobj, fieldnames=["f1", "f2", "f3"])
    writer1.writeheader()
    assert fileobj.getvalue() == "f1,f2,f3\r\n"

    writer2 = DictWriter.append(fileobj)
    writer2.writerow({"f1": 2, "f2": 5, "f3": "xyz"})
    assert fileobj.getvalue() == "f1,f2,f3\r\n2,5,xyz\r\n"
Example #3
0
def test_dictwriter_append_empty():
    fileobj = StringIO()
    with pytest.raises(ValueError):
        writer = DictWriter.append(fileobj)
Example #4
0
def test_dictwriter_append_empty():
    fileobj = StringIO()
    with pytest.raises(ValueError):
        writer = DictWriter.append(fileobj)