forked from mergeos-bounties/Loru
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_export_csv.py
More file actions
44 lines (35 loc) · 1.45 KB
/
Copy pathtest_export_csv.py
File metadata and controls
44 lines (35 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""Tests for #224: export vocab CSV for teachers."""
from __future__ import annotations
import csv
import tempfile
from pathlib import Path
from loru.cli import data_export_csv
def test_export_csv_writes_file() -> None:
"""data export-csv writes a CSV file."""
with tempfile.TemporaryDirectory() as td:
out = Path(td) / "test_vocab.csv"
data_export_csv(out=out)
assert out.exists()
text = out.read_text(encoding="utf-8")
assert "index,gloss,has_sample" in text
def test_export_csv_has_correct_header() -> None:
"""CSV has expected columns."""
with tempfile.TemporaryDirectory() as td:
out = Path(td) / "test_vocab.csv"
data_export_csv(out=out)
with open(out, newline="", encoding="utf-8") as f:
reader = csv.DictReader(f)
assert set(reader.fieldnames) == {"index", "gloss", "has_sample"}
def test_export_csv_every_gloss_present() -> None:
"""Every gloss from DEFAULT_GLOSS is in the CSV."""
from loru.models.vocab import DEFAULT_GLOSS
with tempfile.TemporaryDirectory() as td:
out = Path(td) / "test_vocab.csv"
data_export_csv(out=out)
with open(out, newline="", encoding="utf-8") as f:
reader = csv.DictReader(f)
rows = list(reader)
assert len(rows) == len(DEFAULT_GLOSS)
for i, g in enumerate(DEFAULT_GLOSS):
assert rows[i]["gloss"] == g
assert rows[i]["index"] == str(i)