import pytest
from pathlib import Path
import io
@pytest.fixture(scope="session")
def fixture_dir():
return Path(__file__).parent.parent / "data" / "fixtures"
@pytest.fixture(scope="session")
def fixture_1k(fixture_dir):
path = fixture_dir / "1k_records.mrc"
if not path.exists():
pytest.skip(f"Fixture not found: {path}")
with open(path, 'rb') as f:
return f.read()
@pytest.fixture(scope="session")
def fixture_10k(fixture_dir):
path = fixture_dir / "10k_records.mrc"
if not path.exists():
pytest.skip(f"Fixture not found: {path}")
with open(path, 'rb') as f:
return f.read()
@pytest.fixture(scope="session")
def fixture_small(fixture_1k):
from mrrc import MARCReader
reader = MARCReader(io.BytesIO(fixture_1k))
small_records = []
for i, record in enumerate(reader):
small_records.append(record)
if i >= 9: break
from mrrc import MARCWriter
output = io.BytesIO()
writer = MARCWriter(output)
for record in small_records:
writer.write_record(record)
writer.close()
return output.getvalue()
@pytest.fixture(scope="session")
def fixture_217(fixture_1k):
from mrrc import MARCReader, MARCWriter
reader = MARCReader(io.BytesIO(fixture_1k))
records = []
for i, record in enumerate(reader):
records.append(record)
if i >= 216: break
output = io.BytesIO()
writer = MARCWriter(output)
for record in records:
writer.write_record(record)
writer.close()
return output.getvalue()
@pytest.fixture(scope="session")
def fixture_500(fixture_1k):
from mrrc import MARCReader, MARCWriter
reader = MARCReader(io.BytesIO(fixture_1k))
records = []
for i, record in enumerate(reader):
records.append(record)
if i >= 499: break
output = io.BytesIO()
writer = MARCWriter(output)
for record in records:
writer.write_record(record)
writer.close()
return output.getvalue()
@pytest.fixture(scope="session")
def fixture_5k(fixture_1k, fixture_10k):
from mrrc import MARCReader, MARCWriter
reader = MARCReader(io.BytesIO(fixture_10k))
records = []
for i, record in enumerate(reader):
records.append(record)
if i >= 4999: break
output = io.BytesIO()
writer = MARCWriter(output)
for record in records:
writer.write_record(record)
writer.close()
return output.getvalue()
@pytest.fixture(scope="session")
def fixture_with_error(fixture_small):
return fixture_small + b"00"
@pytest.fixture
def fixture_1k_io(fixture_1k):
return io.BytesIO(fixture_1k)
@pytest.fixture
def fixture_10k_io(fixture_10k):
return io.BytesIO(fixture_10k)
def pytest_configure(config):
config.addinivalue_line(
"markers",
"benchmark: mark test as a benchmark (deselect with '-m \"not benchmark\"')"
)
config.addinivalue_line(
"markers",
"slow: mark test as slow (deselect with '-m \"not slow\"')"
)