From 556ef5d34bcc420599cdec527886e9a907f1f5c5 Mon Sep 17 00:00:00 2001 From: Arthur Milchior Date: Mon, 25 Nov 2019 00:15:20 +0100 Subject: [PATCH] newField checks its input is a str Indeed, it takes as input a name (str). For some reason in some test it was given a model. This actually led to some strange failed test. --- anki/models.py | 1 + tests/test_models.py | 6 ++---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/anki/models.py b/anki/models.py index d37b7e24e..08d366f3d 100644 --- a/anki/models.py +++ b/anki/models.py @@ -231,6 +231,7 @@ and notes.mid = ? and cards.ord = ?""", m['id'], ord) ################################################## def newField(self, name): + assert(isinstance(name, str)) f = defaultField.copy() f['name'] = name return f diff --git a/tests/test_models.py b/tests/test_models.py index 39ea748b4..29d238830 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -39,8 +39,7 @@ def test_fields(): assert "{{NewFront}}" in m['tmpls'][0]['qfmt'] h = d.models.scmhash(m) # add a field - f = d.models.newField(m) - f['name'] = "foo" + f = d.models.newField("foo") d.models.addField(m, f) assert d.getNote(d.models.nids(m)[0]).fields == ["1", "2", ""] assert d.models.scmhash(m) != h @@ -57,8 +56,7 @@ def test_fields(): d.models.moveField(m, m['flds'][1], 0) assert d.getNote(d.models.nids(m)[0]).fields == ["1", ""] # add another and put in middle - f = d.models.newField(m) - f['name'] = "baz" + f = d.models.newField("baz") d.models.addField(m, f) f = d.getNote(d.models.nids(m)[0]) f['baz'] = "2"