Ejemplo n.º 1
0
 def test_fails(self):
     a = {1: 2, 3: 2}
     with self.assertRaises(ValueError):
         invert_dict(a)
Ejemplo n.º 2
0
 def test_ok(self):
     a = {1: 2, 3: 4, 5: 6}
     self.assertDictEqual(invert_dict(a), {2: 1, 4: 3, 6: 5})
Ejemplo n.º 3
0
#!/usr/bin/env python3

# std
import copy
from pathlib import Path

# 3rd
import pandas as pd

# todo: Docstrings, cleanup

# ours
from ankipandas.util.misc import invert_dict

tables_ours2anki = {"revs": "revlog", "cards": "cards", "notes": "notes"}
tables_anki2ours = invert_dict(tables_ours2anki)

fields_file = Path(__file__).parent / "data" / "anki_fields.csv"
fields_df = pd.read_csv(fields_file)

table2index = {"cards": "cid", "notes": "nid", "revs": "rid"}

our_tables = sorted(list(tables_ours2anki.keys()))
our_columns = {
    table: sorted(
        list(fields_df[(fields_df["Table"] == table)
                       & fields_df["Default"]]["Column"].unique()))
    for table in our_tables
}
# Remove indices
for table, columns in our_columns.items():