Skip to content
This repository has been archived by the owner on Jul 31, 2024. It is now read-only.

Commit

Permalink
tests: add test_index.py
Browse files Browse the repository at this point in the history
  • Loading branch information
rzmk committed Jun 3, 2024
1 parent f284b80 commit a993c62
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/test_index.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import qsv
import pytest
from pathlib import Path
from .test_data import test_data


class TestIndexFunc:
@pytest.mark.parametrize(
"file_name",
[("fruits.csv")],
)
def test_index(self, file_name, tmp_path: Path):
"""Generate an index for a given file path at `filename.ext.idx` where `.ext` is the file's extension."""

# Make a temporary data file in a temporary directory
tmp_file = tmp_path.joinpath(file_name).resolve()
tmp_file.write_text(test_data[file_name].read_text(), encoding="utf-8")

qsv.index(tmp_file, run=True)
idx_file = tmp_path.joinpath(f"{file_name}.idx").resolve()

assert idx_file.exists()

@pytest.mark.parametrize(
"file_name",
[("fruits.csv")],
)
def test_output(self, file_name, tmp_path: Path):
"""Generate an index for a given file path at a specified output path."""

# Make a temporary data file in a temporary directory
tmp_file = tmp_path.joinpath(file_name).resolve()
tmp_file.write_text(test_data[file_name].read_text(), encoding="utf-8")
output_file = tmp_path.joinpath(
f"arbitrary_path{''.join(test_data[file_name].suffixes)}.idx"
).resolve()

qsv.index(tmp_file, output=output_file.as_posix(), run=True)

assert output_file.exists()

0 comments on commit a993c62

Please sign in to comment.