def test_extend_structured(self): with filetext('1,1.0\n2,2.0\n') as fn: csv = CSV(fn, 'r+', schema='{x: int32, y: float32}', delimiter=',') csv.extend([(3, 3)]) assert (list(csv) == [[1, 1.0], [2, 2.0], [3, 3.0]] or list(csv) == [{'x': 1, 'y': 1.0}, {'x': 2, 'y': 2.0}, {'x': 3, 'y': 3.0}])
def test_a_mode(self): text = ("id, name, balance\n1, Alice, 100\n2, Bob, 200\n" "3, Charlie, 300\n4, Denis, 400\n5, Edith, 500") with filetext(text) as fn: csv = CSV(fn, 'a') csv.extend([(6, 'Frank', 600), (7, 'Georgina', 700)]) assert 'Georgina' in set(csv.py[:, 'name'])
def reconstructCsv(fuzzed: dict) -> bytes: csv = [] count = 0 for i in fuzzed['values']: if not isinstance(i, bytes): i = str(i).encode() # bad? if count == fuzzed['cpl']: count = 0 csv.extend([i, b"\n"]) else: csv.extend([i, b","]) count += 1 return b''.join(csv)
def test_extend_structured(self): with filetext('1,1.0\n2,2.0\n') as fn: csv = CSV(fn, 'r+', schema='{x: int32, y: float32}', delimiter=',') csv.extend([(3, 3)]) assert (list(csv) == [[1, 1.0], [2, 2.0], [3, 3.0]] or list(csv) == [{ 'x': 1, 'y': 1.0 }, { 'x': 2, 'y': 2.0 }, { 'x': 3, 'y': 3.0 }])
def test_extend_structured(self): with filetext('1,1.0\n2,2.0\n') as fn: csv = CSV(fn, 'r+', schema='{x: int32, y: float32}', delimiter=',') csv.extend([(3, 3)]) assert tuplify(tuple(csv)) == ((1, 1.0), (2, 2.0), (3, 3.0))