Skip to content

Commit a5f181e

Browse files
committedOct 21, 2023
Fix lint.
1 parent 5d2e4ee commit a5f181e

File tree

4 files changed

+36
-242
lines changed

4 files changed

+36
-242
lines changed
 

‎.pylintrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ disable=too-few-public-methods, duplicate-code
2525
# Argument names that match this expression will be ignored.
2626
# This includes some pytest fixtures that are "setup" methods for functions:
2727
# app_context, empty_db, etc
28-
ignored-argument-names=app_context|empty_db|dummy|^ignored_|^unused_
28+
ignored-argument-names=app_context|empty_db|dummy|^ignored_|^unused_,|^_
2929

3030

3131
### placeholder - available settings

‎lute/term/model.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
"""
77

88
from lute.db import db
9-
from lute.models.term import Term as DBTerm, TermTag, TermFlashMessage, TermImage
9+
from lute.models.term import Term as DBTerm, TermTag
1010
from lute.models.language import Language
1111

1212

13-
class Term:
13+
class Term: # pylint: disable=too-many-instance-attributes
1414
"""
1515
Term business object. All class members are primitives.
1616
"""
@@ -34,8 +34,8 @@ class Repository:
3434
Maps Term BO to and from lute.model.Term.
3535
"""
3636

37-
def __init__(self, db):
38-
self.db = db
37+
def __init__(self, _db):
38+
self.db = _db
3939

4040

4141
def find_by_id(self, term_id):
@@ -93,9 +93,9 @@ def _build_db_term(self, term):
9393
"Convert a term business object to a DBTerm."
9494
lang = Language.find(term.language_id)
9595
if lang is None:
96-
raise Exception(f'Unknown language {term.language_id} for term')
96+
raise ValueError(f'Unknown language {term.language_id} for term')
9797
if term.text is None:
98-
raise Exception('Text not set for term')
98+
raise ValueError('Text not set for term')
9999

100100
t = self._find_db_term_by_langid_and_text(lang.id, term.text)
101101
if t is None:
@@ -168,10 +168,9 @@ def _build_business_term(self, dbterm):
168168
term.status = dbterm.status
169169
term.translation = dbterm.translation
170170
term.romanization = dbterm.romanization
171-
term.token_count = dbterm.token_count
172171
term.current_image = dbterm.get_current_image()
173172
term.flash_message = dbterm.get_flash_message()
174-
term.term_parents = [p.text for p in dbterm.parents]
173+
term.parents = [p.text for p in dbterm.parents]
175174
term.romanization = dbterm.romanization
176175
term.term_tags = [tt.text for tt in dbterm.term_tags]
177176

‎tests/unit/models/test_TermTag.py

+14-7
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,45 @@
99
from tests.dbasserts import assert_sql_result
1010

1111

12-
@pytest.fixture(name="hola_tag")
13-
def fixture_hola_tag(spanish, app_context):
12+
@pytest.fixture(name="_hola_tag")
13+
def fixture_hola_tag(app_context):
14+
"A dummy tag for tests."
1415
t = TermTag("Hola", "Hola comment")
1516
db.session.add(t)
1617
db.session.commit()
1718

1819

19-
def test_save(hola_tag, app_context):
20+
def test_save(_hola_tag, app_context):
21+
"Save saves!"
2022
sql = "select TgID, TgText, TgComment from tags"
2123
expected = ["1; Hola; Hola comment"]
2224
assert_sql_result(sql, expected)
2325

2426

25-
def test_new_dup_tag_text_fails(hola_tag, spanish, app_context):
27+
def test_new_dup_tag_text_fails(_hola_tag, app_context):
28+
"Smoke test of db integrity."
2629
t2 = TermTag("Hola", "dup")
2730
db.session.add(t2)
2831
with pytest.raises(Exception):
2932
db.session.commit()
3033

3134

32-
def test_find_by_text(hola_tag, app_context):
35+
def test_find_by_text(_hola_tag, app_context):
36+
"Find by text returns match."
3337
retrieved = TermTag.find_by_text("Hola")
3438
assert retrieved is not None
3539
assert retrieved.text == "Hola"
3640

3741

38-
def test_find_by_text_returns_null_if_not_exact_match(hola_tag, app_context):
42+
def test_find_by_text_returns_null_if_not_exact_match(_hola_tag, app_context):
43+
"Find returns null if no match."
44+
# TODO check if used: this method feels useless.
3945
assert TermTag.find_by_text("unknown") is None
4046
assert TermTag.find_by_text("hola") is None
4147

4248

43-
def test_find_or_create_by_text_returns_new_if_no_match(hola_tag, app_context):
49+
def test_find_or_create_by_text_returns_new_if_no_match(_hola_tag, app_context):
50+
"Return new."
4451
assert TermTag.find_by_text("unknown") is None
4552
t = TermTag.find_or_create_by_text("unknown")
4653
assert t.text == 'unknown', 'new tag created'

0 commit comments

Comments
 (0)