mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-08-09 10:54:10 +02:00
Truncate values longer than 100 characters
This commit is contained in:
parent
c0d21956bc
commit
955daaaf05
2 changed files with 24 additions and 10 deletions
|
|
@ -12,11 +12,11 @@ def db_to_analyze(fresh_db):
|
|||
stuff = fresh_db["stuff"]
|
||||
stuff.insert_all(
|
||||
[
|
||||
{"id": 1, "owner": "Terry", "size": 5},
|
||||
{"id": 1, "owner": "Terryterryterry", "size": 5},
|
||||
{"id": 2, "owner": "Joan", "size": 4},
|
||||
{"id": 3, "owner": "Kumar", "size": 5},
|
||||
{"id": 4, "owner": "Anne", "size": 5},
|
||||
{"id": 5, "owner": "Terry", "size": 5},
|
||||
{"id": 5, "owner": "Terryterryterry", "size": 5},
|
||||
{"id": 6, "owner": "Joan", "size": 4},
|
||||
{"id": 7, "owner": "Kumar", "size": 5},
|
||||
{"id": 8, "owner": "Joan", "size": 4},
|
||||
|
|
@ -51,7 +51,7 @@ def db_to_analyze(fresh_db):
|
|||
num_null=0,
|
||||
num_blank=0,
|
||||
num_distinct=4,
|
||||
most_common=[("Joan", 3), ("Terry", 2)],
|
||||
most_common=[("Joan", 3), ("Terry...", 2)],
|
||||
least_common=[("Anne", 1), ("Kumar", 2)],
|
||||
),
|
||||
),
|
||||
|
|
@ -71,7 +71,10 @@ def db_to_analyze(fresh_db):
|
|||
],
|
||||
)
|
||||
def test_analyze_column(db_to_analyze, column, expected):
|
||||
assert db_to_analyze["stuff"].analyze_column(column, common_limit=2) == expected
|
||||
assert (
|
||||
db_to_analyze["stuff"].analyze_column(column, common_limit=2, value_truncate=5)
|
||||
== expected
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
|
@ -89,7 +92,7 @@ def test_analyze_table(db_to_analyze_path):
|
|||
== textwrap.dedent(
|
||||
"""
|
||||
1/3: ColumnDetails(table='stuff', column='id', total_rows=8, num_null=0, num_blank=0, num_distinct=8, most_common=None, least_common=None)
|
||||
2/3: ColumnDetails(table='stuff', column='owner', total_rows=8, num_null=0, num_blank=0, num_distinct=4, most_common=[('Joan', 3), ('Terry', 2), ('Kumar', 2), ('Anne', 1)], least_common=None)
|
||||
2/3: ColumnDetails(table='stuff', column='owner', total_rows=8, num_null=0, num_blank=0, num_distinct=4, most_common=[('Joan', 3), ('Terryterryterry', 2), ('Kumar', 2), ('Anne', 1)], least_common=None)
|
||||
3/3: ColumnDetails(table='stuff', column='size', total_rows=8, num_null=0, num_blank=0, num_distinct=2, most_common=[(5, 5), (4, 3)], least_common=None)
|
||||
"""
|
||||
).strip()
|
||||
|
|
@ -119,7 +122,7 @@ def test_analyze_table_save(db_to_analyze_path):
|
|||
"num_null": 0,
|
||||
"num_blank": 0,
|
||||
"num_distinct": 4,
|
||||
"most_common": '[["Joan", 3], ["Terry", 2], ["Kumar", 2], ["Anne", 1]]',
|
||||
"most_common": '[["Joan", 3], ["Terryterryterry", 2], ["Kumar", 2], ["Anne", 1]]',
|
||||
"least_common": None,
|
||||
},
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue