Skip to content

Commit

Permalink
Add write example test
Browse files Browse the repository at this point in the history
  • Loading branch information
Donaim committed Aug 7, 2024
1 parent 1b541cf commit eca1d17
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions example.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[section1]
header1,header2,header3
value1,value2,value3
[section2]
header4,header5,header6
value4,value5,value6
15 changes: 15 additions & 0 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

from pathlib import Path
import pytest
import io
import csv

import multicsv

Expand Down Expand Up @@ -39,3 +41,16 @@ def test_read_csv(example_file: Path) -> None:

assert section1 == [['d', 'e', 'f'],
['4', '5', '6']]


def test_write_csv():
with multicsv.open('example.csv', mode='w+') as csv_file:
# Write the CSV content to the file
csv_file['section1'] = io.StringIO("header1,header2,header3\nvalue1,value2,value3\n")
csv_file['section2'] = io.StringIO("header4,header5,header6\nvalue4,value5,value6\n")

# Read a section using the csv module
section1 = csv_file['section1']
csv_reader = csv.reader(section1)
assert list(csv_reader) == [['header1', 'header2', 'header3'],
['value1', 'value2', 'value3']]

0 comments on commit eca1d17

Please sign in to comment.