mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-10-23 17:57:03 +02:00
fix: ValueTracker.evaluate() should not skip falsy values like 0
This commit is contained in:
parent
85b1be10c8
commit
84a2fa76b3
2 changed files with 25 additions and 1 deletions
|
|
@ -490,7 +490,7 @@ class ValueTracker:
|
|||
return "text"
|
||||
|
||||
def evaluate(self, value: object) -> None:
|
||||
if not value or not self.couldbe:
|
||||
if value is None or not self.couldbe:
|
||||
return
|
||||
not_these: list[str] = []
|
||||
for name, test in self.couldbe.items():
|
||||
|
|
|
|||
|
|
@ -102,3 +102,27 @@ def test_flatten(input, expected):
|
|||
)
|
||||
def test_dedupe_keys(input, expected):
|
||||
assert utils.dedupe_keys(input) == expected
|
||||
|
||||
|
||||
def test_value_tracker_evaluates_falsy_zero():
|
||||
"""ValueTracker should evaluate 0 and narrow to integer"""
|
||||
vt = utils.ValueTracker()
|
||||
vt.evaluate(0)
|
||||
vt.evaluate(0)
|
||||
assert vt.guessed_type == "integer"
|
||||
|
||||
|
||||
def test_value_tracker_evaluates_falsy_empty_string():
|
||||
"""ValueTracker should evaluate empty strings and narrow to text"""
|
||||
vt = utils.ValueTracker()
|
||||
vt.evaluate("")
|
||||
vt.evaluate("")
|
||||
assert vt.guessed_type == "text"
|
||||
|
||||
|
||||
def test_value_tracker_evaluates_falsy_false():
|
||||
"""ValueTracker should evaluate False and narrow to integer (bool is subclass of int)"""
|
||||
vt = utils.ValueTracker()
|
||||
vt.evaluate(False)
|
||||
vt.evaluate(False)
|
||||
assert vt.guessed_type == "integer"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue