test: Fix MyPy errors

Fix multiple errors in test dug up by MyPy.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-07-03 14:40:47 +02:00 • committed by janware DevOps
commit 26f3893579
Signed by: DevOps
SSH key fingerprint: SHA256:cZiw7ExG5q3KAVm7Jse3rGITowu0VjgUgNMPbifmY8g
6 changed files with 19 additions and 27 deletions

View file

@ -1,9 +1,11 @@
from jwutils.cast import *
from jwutils.log import *
from jw.util.cast import cast_str, guess_type
from jw.util.log import ERR, INFO, set_flags, set_level, slog
set_level(DEBUG)
set_level('debug')
set_flags('console,color,position,prio')
# fmt: disable # don't conflate
# yapf: disable # don't conflate
test_data = [
(bool, 'true', True, True),
(bool, 'False', True, False),
@ -27,13 +29,15 @@ test_data = [
(str, None, Exception(), Exception()),
(str, 'This is a string', 'This is a string', 'This is a string')
]
# fmt: ensable # don't conflate
# yapf: ensable # don't conflate
status = 0
for tp, s, guessed_val, cast_val in test_data:
try:
slog(INFO, f'guessed type of "{s}" = "{guess_type(s)}", should be "{tp}"')
slog(INFO, f'cast_str("{s}") = "{cast_str(s)}"')
slog(INFO, f'cast_str("{s}, {tp}") = "{cast_str(s, target_type=tp)}"')
slog(INFO, f'guessed type of "{s}" = "{guess_type(s)}", should be "{tp}"') # type: ignore
slog(INFO, f'cast_str("{s}") = "{cast_str(s)}"') # type: ignore
slog(INFO, f'cast_str("{s}, {tp}") = "{cast_str(s, target_type=tp)}"') # type: ignore
except Exception as e:
if s is None:
slog(INFO, f'guessed type of "{s}" = Exception, should be "Exception"')

View file

@ -1,14 +0,0 @@
import jwutils
print "This is without muted output"
with jwutils.MuteStdIO():
print "This is with muted output"
with jwutils.MuteStdIO():
print "This will have an error"
print "Second suppressed line of output"
print "Third suppressed line of output"
raise Exception("Something went wrong")
print "Output is unmuted again"

View file

@ -1,8 +1,10 @@
from jwutils.log import *
from jwutils.Options import *
from jw.util.log import NOTICE, slog
from jw.util.Options import Options
i: str | int
delim = "======================= "
d = "----------------------- "
d = "----------------------- "
s = "this=that a=b doit"
slog(NOTICE, d + s)
@ -11,9 +13,9 @@ slog(NOTICE, d + "dump()")
a.dump(NOTICE)
slog(NOTICE, d + "by index")
for i in range(0, 4):
slog(NOTICE, "attr({}) = {}".format(i, a.get(i, by_index=True, default=False)))
slog(NOTICE, "attr({}) = {}".format(i, a.get(i, by_index = True, default = False)))
slog(NOTICE, d + "by key")
for i in [ "this", "that", "b", "a", "doit"]:
for i in ["this", "that", "b", "a", "doit"]:
slog(NOTICE, "attr({}) = {}".format(i, a[i]))
s = '"me": "too", "Pfalse": true, "myarr": ["a", "b", "c"], "me": "not"'
@ -23,10 +25,10 @@ slog(NOTICE, d + "dump()")
a.dump(NOTICE)
slog(NOTICE, d + "by index")
for i in range(0, 5):
slog(NOTICE, "attr({}) = {}".format(i, a.get(i, by_index=True, default=False)))
slog(NOTICE, "attr({}) = {}".format(i, a.get(i, by_index = True, default = False)))
slog(NOTICE, d + "by key in keys()")
for i in a.keys():
slog(NOTICE, "attr({}) = {}".format(i, a[i]))
slog(NOTICE, d + "by key")
for i in [ "me", "Pfalse", "myarr" ]:
for i in ["me", "Pfalse", "myarr"]:
slog(NOTICE, "attr({}) = {}".format(i, a[i]))