Skip to content

Commit

Permalink
test: Add test data
Browse files Browse the repository at this point in the history
  • Loading branch information
msto committed Dec 9, 2024
1 parent cbc2c2a commit e154fbd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
10 changes: 10 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from pathlib import Path

import pytest


@pytest.fixture(scope="session")
def datadir() -> Path:
"""Path to the test data directory."""

return Path(__file__).parent / "data"
3 changes: 3 additions & 0 deletions tests/data/reader_should_parse_quotes.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"id" "title"
"fake" "A fake object"
"also_fake" "Another fake object"
19 changes: 6 additions & 13 deletions tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,21 @@ class FakeDataclass:
assert rows[0].bar == 1


def test_read_csv_with_header_quotes(tmp_path: Path) -> None:
def test_reader_should_parse_quotes(datadir: Path) -> None:
"""
Test that having quotes around column names in header row doesn't break anything
https://github.com/msto/dataclass_io/issues/19
"""
fpath = tmp_path / "test.txt"
fpath = datadir / "reader_should_parse_quotes.tsv"

@dataclass
class FakeDataclass:
id: str
title: str

test_csv = [
'"id"\t"title"\n',
'"fake"\t"A fake object"\n',
'"also_fake"\t"Another fake object"\n',
]

with fpath.open("w") as f:
f.writelines(test_csv)

# Parse CSV using DataclassReader
with DataclassReader.open(fpath, FakeDataclass) as reader:
for fake_object in reader:
print(fake_object)
records = [record for record in reader]

assert records[0] == FakeDataclass(id="fake", title="A fake object")
assert records[1] == FakeDataclass(id="also_fake", title="Another fake object")

0 comments on commit e154fbd

Please sign in to comment.