-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pywvcsv: rename the library to just 'wvcsv'.
And eliminate redundant 'csv' prefix on functions inside the wvcsv module, so that we can avoid doing 'import * from wvcsv'. Now just 'import wvcsv' and use wvcsv.Reader(), wvcsv.quote(), etc.
- Loading branch information
Showing
7 changed files
with
73 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from wvcsv import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from wvtest import * | ||
import wvcsv | ||
|
||
import sys | ||
|
||
@wvtest | ||
def test_quote(): | ||
WVPASSEQ(wvcsv.quote(None), "") | ||
WVPASSEQ(wvcsv.quote("test"), "test") | ||
WVPASSEQ(wvcsv.quote("t,est"), '"t,est"') | ||
WVPASSEQ(wvcsv.quote('t,e"st'), '"t,e""st"') | ||
|
||
@wvtest | ||
def test_dequote(): | ||
WVPASSEQ(wvcsv.dequote(""), None) | ||
WVPASSEQ(wvcsv.dequote('test'), 'test') | ||
WVPASSEQ(wvcsv.dequote('"te,st"'), 'te,st') | ||
WVPASSEQ(wvcsv.dequote('"te,""st"'), 'te,"st') | ||
|
||
WVPASSEQ(wvcsv.dequote(wvcsv.quote('"foo,"bar,')), '"foo,"bar,') | ||
|
||
@wvtest | ||
def test_splitline(): | ||
WVPASSEQ(wvcsv.splitline(","), (None, None)) | ||
WVPASSEQ(wvcsv.splitline(",def"), (None, 'def')) | ||
WVPASSEQ(wvcsv.splitline("abc,def"), ('abc', 'def')) | ||
WVPASSEQ(wvcsv.splitline('"abc,",def'), ('abc,', 'def')) | ||
WVPASSEQ(wvcsv.splitline('"a""bc,",def'), ('a"bc,', 'def')) | ||
WVPASSEQ(wvcsv.splitline('"a""bc,",",def"'), ('a"bc,', ',def')) | ||
WVPASSEQ(wvcsv.splitline('"a""bc,",",def"""'), ('a"bc,', ',def"')) | ||
WVPASSEQ(wvcsv.splitline('"a""bc,",,",def"""'), ('a"bc,', None, ',def"')) | ||
|
||
@wvtest | ||
def test_getline_from_memory(): | ||
r = wvcsv.Reader("ABCDEFG,efgh\n\"a\nbcd\",1234") | ||
i = iter(r) | ||
WVPASSEQ(i.next(), "ABCDEFG,efgh") | ||
WVPASSEQ(i.next(), '"a\nbcd",1234') | ||
try: | ||
i.next() | ||
WVFAIL("i.next() should have thrown StopIteration") | ||
except StopIteration: | ||
WVPASS("wvcsv.Reader iterator throws StopIteration correctly") | ||
|
||
@wvtest | ||
def test_getline_from_file(): | ||
r = wvcsv.Reader(open("data/test.csv")) | ||
i = iter(r) | ||
WVPASSEQ(i.next(), "abc,def") | ||
WVPASSEQ(i.next(), 'ghi,"j\nkl"') | ||
WVPASSEQ(i.next(), '1234,5678') | ||
WVPASSEQ(i.next(), '') | ||
WVPASSEQ(i.next(), "9,10") | ||
try: | ||
i.next() | ||
WVFAIL("i.next() should have thrown StopIteration") | ||
except StopIteration: | ||
WVPASS("wvcsv.Reader iterator throws StopIteration correctly") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
from _wvcsv import * | ||
|
||
class CsvReader: | ||
class Reader: | ||
def __init__(self, data): | ||
self.id = csvsetup(data); | ||
self.id = setup(data); | ||
|
||
def __iter__(self): | ||
while True: | ||
r = csvreadline(self.id) | ||
r = readline(self.id) | ||
if r is None: | ||
break | ||
yield r | ||
|
||
def __del__(self): | ||
csvtakedown(self.id) | ||
takedown(self.id) |