diff --git a/lute/book/stats.py b/lute/book/stats.py index dd13f971..ec6d4ff7 100644 --- a/lute/book/stats.py +++ b/lute/book/stats.py @@ -106,7 +106,6 @@ def _get_stats(book): percent = round(100.0 * unknowns / allunique) sd = json.dumps(status_distribution) - sd = sd.replace('"', "") # Any change in the below fields requires a change to # update_stats as well, query insert doesn't check field order. diff --git a/tests/unit/book/test_stats.py b/tests/unit/book/test_stats.py index 6ed4d59d..738ca6b7 100644 --- a/tests/unit/book/test_stats.py +++ b/tests/unit/book/test_stats.py @@ -109,7 +109,7 @@ def add_terms(lang, terms): def assert_stats(expected, msg=""): "helper." sql = """select wordcount, distinctterms, distinctunknowns, - unknownpercent, status_distribution from bookstats""" + unknownpercent, replace(status_distribution, '"', "'") from bookstats""" assert_sql_result(sql, expected, msg) @@ -124,31 +124,48 @@ def test_stats_smoke_test(_test_book, spanish): "Terms are rendered to count stats." add_terms(spanish, ["gato", "TENGO"]) refresh_stats() - assert_stats(["4; 4; 2; 50; {0: 2, 1: 2, 2: 0, 3: 0, 4: 0, 5: 0, 98: 0, 99: 0}"]) + assert_stats( + [ + "4; 4; 2; 50; {'0': 2, '1': 2, '2': 0, '3': 0, '4': 0, '5': 0, '98': 0, '99': 0}" + ] + ) def test_stats_calculates_rendered_text(_test_book, spanish): "Multiword term counted as one term." add_terms(spanish, ["tengo un"]) refresh_stats() - assert_stats(["4; 3; 2; 67; {0: 2, 1: 1, 2: 0, 3: 0, 4: 0, 5: 0, 98: 0, 99: 0}"]) + assert_stats( + [ + "4; 3; 2; 67; {'0': 2, '1': 1, '2': 0, '3': 0, '4': 0, '5': 0, '98': 0, '99': 0}" + ] + ) def test_stats_only_update_books_marked_stale(_test_book, spanish): "Have to mark book as stale, too expensive otherwise." add_terms(spanish, ["gato", "TENGO"]) refresh_stats() - assert_stats(["4; 4; 2; 50; {0: 2, 1: 2, 2: 0, 3: 0, 4: 0, 5: 0, 98: 0, 99: 0}"]) + assert_stats( + [ + "4; 4; 2; 50; {'0': 2, '1': 2, '2': 0, '3': 0, '4': 0, '5': 0, '98': 0, '99': 0}" + ] + ) add_terms(spanish, ["hola"]) refresh_stats() assert_stats( - ["4; 4; 2; 50; {0: 2, 1: 2, 2: 0, 3: 0, 4: 0, 5: 0, 98: 0, 99: 0}"], + [ + "4; 4; 2; 50; {'0': 2, '1': 2, '2': 0, '3': 0, '4': 0, '5': 0, '98': 0, '99': 0}" + ], "not updated", ) mark_stale(_test_book) refresh_stats() assert_stats( - ["4; 4; 1; 25; {0: 1, 1: 3, 2: 0, 3: 0, 4: 0, 5: 0, 98: 0, 99: 0}"], "updated" + [ + "4; 4; 1; 25; {'0': 1, '1': 3, '2': 0, '3': 0, '4': 0, '5': 0, '98': 0, '99': 0}" + ], + "updated", )