Skip to content

Commit 6a425db

Browse files
committed
Fix some type failures for test cases
1 parent 2195667 commit 6a425db

File tree

4 files changed

+59
-42
lines changed

4 files changed

+59
-42
lines changed

tests/testapp/test_aggregates.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ def test_no_rows(self):
6666

6767

6868
class GroupConcatTests(TestCase):
69+
shakes: Author
70+
jk: Author
71+
grisham: Author
72+
str_tutee_ids: list[str]
73+
6974
@classmethod
7075
def setUpTestData(cls):
7176
super().setUpTestData()

tests/testapp/test_dynamicfield.py

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -117,28 +117,31 @@ def as_sql(self, compiler, connection):
117117

118118

119119
class QueryTests(DynColTestCase):
120+
objs: list[DynamicModel]
121+
120122
@classmethod
121123
def setUpTestData(cls):
122124
super().setUpTestData()
123-
cls.objs = [
124-
DynamicModel(attrs={"a": "b"}),
125-
DynamicModel(attrs={"a": "b", "c": "d"}),
126-
DynamicModel(attrs={"c": "d"}),
127-
DynamicModel(attrs={}),
128-
DynamicModel(
129-
attrs={
130-
"datetimey": dt.datetime(2001, 1, 4, 14, 15, 16),
131-
"datey": dt.date(2001, 1, 4),
132-
"floaty": 128.5,
133-
"inty": 9001,
134-
"stry": "strvalue",
135-
"str_underscorey": "strvalue2",
136-
"timey": dt.time(14, 15, 16),
137-
"nesty": {"level2": "chirp"},
138-
}
139-
),
140-
]
141-
DynamicModel.objects.bulk_create(cls.objs)
125+
DynamicModel.objects.bulk_create(
126+
[
127+
DynamicModel(attrs={"a": "b"}),
128+
DynamicModel(attrs={"a": "b", "c": "d"}),
129+
DynamicModel(attrs={"c": "d"}),
130+
DynamicModel(attrs={}),
131+
DynamicModel(
132+
attrs={
133+
"datetimey": dt.datetime(2001, 1, 4, 14, 15, 16),
134+
"datey": dt.date(2001, 1, 4),
135+
"floaty": 128.5,
136+
"inty": 9001,
137+
"stry": "strvalue",
138+
"str_underscorey": "strvalue2",
139+
"timey": dt.time(14, 15, 16),
140+
"nesty": {"level2": "chirp"},
141+
}
142+
),
143+
]
144+
)
142145
cls.objs = list(DynamicModel.objects.order_by("id"))
143146

144147
def test_equal(self):
@@ -264,14 +267,17 @@ def test_key_transform_nesty__level2__startswith(self):
264267

265268

266269
class SpeclessQueryTests(DynColTestCase):
270+
objs: list[SpeclessDynamicModel]
271+
267272
@classmethod
268273
def setUpTestData(cls):
269274
super().setUpTestData()
270-
objs = [
271-
SpeclessDynamicModel(attrs={"a": "b"}),
272-
SpeclessDynamicModel(attrs={"a": "c"}),
273-
]
274-
SpeclessDynamicModel.objects.bulk_create(objs)
275+
SpeclessDynamicModel.objects.bulk_create(
276+
[
277+
SpeclessDynamicModel(attrs={"a": "b"}),
278+
SpeclessDynamicModel(attrs={"a": "c"}),
279+
]
280+
)
275281
cls.objs = list(SpeclessDynamicModel.objects.order_by("id"))
276282

277283
def test_simple(self):

tests/testapp/test_functions.py

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ def test_if_false_default_None(self):
128128
class NumericFunctionTests(TestCase):
129129
def test_crc32(self):
130130
Alphabet.objects.create(d="AAAAAA")
131-
ab = Alphabet.objects.annotate(crc=CRC32("d")).first()
131+
ab = Alphabet.objects.annotate(crc=CRC32("d")).get()
132+
132133
# Precalculated this in MySQL prompt. Python's binascii.crc32 doesn't
133134
# match - maybe sign issues?
134135
assert ab.crc == 2854018686
@@ -145,7 +146,7 @@ def test_sign(self):
145146
"csign": Sign("c"),
146147
}
147148

148-
ab = Alphabet.objects.annotate(**kwargs).first()
149+
ab = Alphabet.objects.annotate(**kwargs).get()
149150

150151
assert ab.asign == 1
151152
assert ab.bsign == 0
@@ -155,34 +156,34 @@ def test_sign(self):
155156
class StringFunctionTests(TestCase):
156157
def test_concat_ws(self):
157158
Alphabet.objects.create(d="AAA", e="BBB")
158-
ab = Alphabet.objects.annotate(de=ConcatWS("d", "e")).first()
159+
ab = Alphabet.objects.annotate(de=ConcatWS("d", "e")).get()
159160
assert ab.de == "AAA,BBB"
160161

161162
def test_concat_ws_integers(self):
162163
Alphabet.objects.create(a=1, b=2)
163-
ab = Alphabet.objects.annotate(ab=ConcatWS("a", "b")).first()
164+
ab = Alphabet.objects.annotate(ab=ConcatWS("a", "b")).get()
164165
assert ab.ab == "1,2"
165166

166167
def test_concat_ws_skips_nulls(self):
167168
Alphabet.objects.create(d="AAA", e=None, f=2)
168-
ab = Alphabet.objects.annotate(de=ConcatWS("d", "e", "f")).first()
169+
ab = Alphabet.objects.annotate(de=ConcatWS("d", "e", "f")).get()
169170
assert ab.de == "AAA,2"
170171

171172
def test_concat_ws_separator(self):
172173
Alphabet.objects.create(d="AAA", e="BBB")
173-
ab = Alphabet.objects.annotate(de=ConcatWS("d", "e", separator=":")).first()
174+
ab = Alphabet.objects.annotate(de=ConcatWS("d", "e", separator=":")).get()
174175
assert ab.de == "AAA:BBB"
175176

176177
def test_concat_ws_separator_null_returns_none(self):
177178
Alphabet.objects.create(a=1, b=2)
178179
concat = ConcatWS("a", "b", separator=None)
179-
ab = Alphabet.objects.annotate(ab=concat).first()
180+
ab = Alphabet.objects.annotate(ab=concat).get()
180181
assert ab.ab is None
181182

182183
def test_concat_ws_separator_field(self):
183184
Alphabet.objects.create(a=1, d="AAA", e="BBB")
184185
concat = ConcatWS("d", "e", separator=F("a"))
185-
ab = Alphabet.objects.annotate(de=concat).first()
186+
ab = Alphabet.objects.annotate(de=concat).get()
186187
assert ab.de == "AAA1BBB"
187188

188189
def test_concat_ws_too_few_fields(self):
@@ -196,7 +197,7 @@ def test_concat_ws_then_lookups_from_textfield(self):
196197
ab = (
197198
Alphabet.objects.annotate(de=ConcatWS("d", "e", separator=":"))
198199
.filter(de__endswith=":BBB")
199-
.first()
200+
.get()
200201
)
201202
assert ab.de == "AAA:BBB"
202203

@@ -216,16 +217,16 @@ def test_elt_expression(self):
216217

217218
def test_field_simple(self):
218219
Alphabet.objects.create(d="a")
219-
ab = Alphabet.objects.annotate(dp=Field("d", ["a", "b"])).first()
220+
ab = Alphabet.objects.annotate(dp=Field("d", ["a", "b"])).get()
220221
assert ab.dp == 1
221-
ab = Alphabet.objects.annotate(dp=Field("d", ["b", "a"])).first()
222+
ab = Alphabet.objects.annotate(dp=Field("d", ["b", "a"])).get()
222223
assert ab.dp == 2
223-
ab = Alphabet.objects.annotate(dp=Field("d", ["c", "d"])).first()
224+
ab = Alphabet.objects.annotate(dp=Field("d", ["c", "d"])).get()
224225
assert ab.dp == 0
225226

226227
def test_field_expression(self):
227228
Alphabet.objects.create(d="b")
228-
ab = Alphabet.objects.annotate(dp=Field("d", [Value("a"), Value("b")])).first()
229+
ab = Alphabet.objects.annotate(dp=Field("d", [Value("a"), Value("b")])).get()
229230
assert ab.dp == 2
230231

231232
def test_order_by(self):
@@ -287,7 +288,7 @@ def test_xmlextractvalue_expression(self):
287288

288289
def test_xmlextractvalue_invalid_xml(self):
289290
Alphabet.objects.create(d='{"this": "isNotXML"}')
290-
ab = Alphabet.objects.annotate(ev=XMLExtractValue("d", "/some")).first()
291+
ab = Alphabet.objects.annotate(ev=XMLExtractValue("d", "/some")).get()
291292
assert ab.ev == ""
292293

293294

@@ -301,7 +302,7 @@ def test_md5_string(self):
301302
DeprecationWarning, "This function is deprecated."
302303
):
303304
md5 = MD5("d")
304-
ab = Alphabet.objects.annotate(md5=md5).first()
305+
ab = Alphabet.objects.annotate(md5=md5).get()
305306

306307
assert ab.md5 == pymd5
307308

@@ -314,7 +315,7 @@ def test_sha1_string(self):
314315
DeprecationWarning, "This function is deprecated."
315316
):
316317
sha1 = SHA1("d")
317-
ab = Alphabet.objects.annotate(sha=sha1).first()
318+
ab = Alphabet.objects.annotate(sha=sha1).get()
318319

319320
assert ab.sha == pysha1
320321

@@ -330,7 +331,7 @@ def test_sha2_string(self):
330331
DeprecationWarning, "This function is deprecated."
331332
):
332333
sha2 = SHA2("d", hash_len)
333-
ab = Alphabet.objects.annotate(sha=sha2).first()
334+
ab = Alphabet.objects.annotate(sha=sha2).get()
334335

335336
assert ab.sha == pysha
336337

@@ -343,7 +344,7 @@ def test_sha2_string_hash_len_default(self):
343344
DeprecationWarning, "This function is deprecated."
344345
):
345346
sha2 = SHA2("d")
346-
ab = Alphabet.objects.annotate(sha=sha2).first()
347+
ab = Alphabet.objects.annotate(sha=sha2).get()
347348

348349
assert ab.sha == pysha512
349350

@@ -381,6 +382,8 @@ def test_last_insert_id_in_query(self):
381382

382383

383384
class JSONFunctionTests(TestCase):
385+
obj: JSONModel
386+
384387
@classmethod
385388
def setUpTestData(cls):
386389
super().setUpTestData()

tests/testapp/test_locks.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ class LockTests(TestCase):
2525

2626
databases = {"default", "other"}
2727

28+
supports_lock_info: bool
29+
lock_info_preinstalled: bool
30+
2831
@classmethod
2932
def setUpClass(cls):
3033
super().setUpClass()

0 commit comments

Comments
 (0)