Skip to content

Commit

Permalink
black & isort tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MKuranowski committed Apr 28, 2024
1 parent a51fe12 commit 1e4c41c
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 36 deletions.
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from setuptools import setup, Extension

from setuptools import Extension, setup

setup(ext_modules=[Extension(name="aiocsv._parser", sources=["aiocsv/_parser.c"])])
3 changes: 2 additions & 1 deletion tests/test_dialects.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os
from tempfile import NamedTemporaryFile

import aiofiles
import pytest
import os

from aiocsv import AsyncReader, AsyncWriter

Expand Down
24 changes: 14 additions & 10 deletions tests/test_dict.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
import csv
import os
from tempfile import NamedTemporaryFile

import aiofiles
import pytest
import csv
import os

from aiocsv import AsyncDictReader, AsyncDictWriter

FILENAME = "tests/metro_systems.tsv"
PARAMS = {"delimiter": "\t", "quotechar": "'", "quoting": csv.QUOTE_ALL}
HEADER = ["City", "Stations", "System Length"]
VALUES = [dict(zip(HEADER, i)) for i in [
["New York", "424", "380"],
["Shanghai", "345", "676"],
["Seoul", "331", "353"],
["Beijing", "326", "690"],
["Paris", "302", "214"],
["London", "270", "402"],
]]
VALUES = [
dict(zip(HEADER, i))
for i in [
["New York", "424", "380"],
["Shanghai", "345", "676"],
["Seoul", "331", "353"],
["Beijing", "326", "690"],
["Paris", "302", "214"],
["London", "270", "402"],
]
]


@pytest.mark.asyncio
Expand Down
2 changes: 1 addition & 1 deletion tests/test_newlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
READ_VALUES = [
["hello", 'is it "me"', "you're\nlooking for"],
["this is going to be", "another\nbroken row", "this time with escapechar"],
["and now it's both quoted\nand", "with", "escape char"]
["and now it's both quoted\nand", "with", "escape char"],
]


Expand Down
25 changes: 10 additions & 15 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from typing import AsyncIterator, Callable, List, Protocol, Type
import pytest
import csv
import io
from typing import AsyncIterator, Callable, List, Protocol, Type

import pytest

from aiocsv.parser import Parser as PyParser
from aiocsv._parser import Parser as CParser
from aiocsv.protocols import WithAsyncRead, DialectLike
from aiocsv.parser import Parser as PyParser
from aiocsv.protocols import DialectLike, WithAsyncRead


class Parser(Protocol):
Expand Down Expand Up @@ -37,9 +38,7 @@ async def test_parsing_simple(parser: Type[Parser]):
data = 'abc,"def",ghi\r\n' '"j""k""l",mno,pqr\r\n' 'stu,vwx,"yz"\r\n'

csv_result = list(csv.reader(io.StringIO(data, newline="")))
custom_result = [
r async for r in parser(AsyncStringIO(data), csv.get_dialect("excel"))
]
custom_result = [r async for r in parser(AsyncStringIO(data), csv.get_dialect("excel"))]

assert csv_result == custom_result
assert custom_result == [
Expand All @@ -66,9 +65,7 @@ async def test_parsing_escapes(parser: Type[Parser]):
async def test_parsing_empty(parser: Type[Parser]):
data = "\r\n a,,\r\n,\r\n "

csv_parser = csv.reader(
io.StringIO(data, newline=""), skipinitialspace=True, strict=True
)
csv_parser = csv.reader(io.StringIO(data, newline=""), skipinitialspace=True, strict=True)
csv_result = list(csv_parser)
custom_result = [r async for r in parser(AsyncStringIO(data), csv_parser.dialect)]

Expand Down Expand Up @@ -112,9 +109,7 @@ async def test_parsing_nonnumeric_invalid(parser: Type[Parser]):
async def test_parsing_none_quoting(parser: Type[Parser]):
data = '1" hello,"2\na","3.14"'

csv_parser = csv.reader(
io.StringIO(data, newline=""), quoting=csv.QUOTE_NONE, strict=True
)
csv_parser = csv.reader(io.StringIO(data, newline=""), quoting=csv.QUOTE_NONE, strict=True)
csv_result = list(csv_parser)
custom_result = [r async for r in parser(AsyncStringIO(data), csv_parser.dialect)]

Expand Down Expand Up @@ -293,7 +288,7 @@ async def test_parsing_unterminated_quote_non_strict(parser: Type[Parser]):
@pytest.mark.asyncio
@pytest.mark.parametrize("parser", PARSERS, ids=PARSER_NAMES)
async def test_parsing_eof_in_escape(parser: Type[Parser]):
data = 'a$'
data = "a$"

csv_parser = csv.reader(io.StringIO(data, newline=""), escapechar="$", strict=True)

Expand All @@ -307,7 +302,7 @@ async def test_parsing_eof_in_escape(parser: Type[Parser]):
@pytest.mark.asyncio
@pytest.mark.parametrize("parser", PARSERS, ids=PARSER_NAMES)
async def test_parsing_eof_in_escape_non_strict(parser: Type[Parser]):
data = 'a$'
data = "a$"

csv_parser = csv.reader(io.StringIO(data, newline=""), escapechar="$", strict=False)
csv_result = list(csv_parser)
Expand Down
10 changes: 3 additions & 7 deletions tests/test_simple.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import os
from tempfile import NamedTemporaryFile

import aiofiles
import pytest
import os

from aiocsv import AsyncReader, AsyncWriter

FILENAME = "tests/math_constants.csv"
HEADER = ["name", "value"]
VALUES = [
["pi", "3.1416"],
["sqrt2", "1.4142"],
["phi", "1.618"],
["e", "2.7183"]
]
VALUES = [["pi", "3.1416"], ["sqrt2", "1.4142"], ["phi", "1.618"], ["e", "2.7183"]]


@pytest.mark.asyncio
Expand Down

0 comments on commit 1e4c41c

Please sign in to comment.