From d58f1998cf53e89128d6448006b300135e8a7e8c Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Sun, 1 Feb 2026 21:45:54 +0000 Subject: [PATCH] Initial upload: Devtoolbelt v1.0.0 - unified CLI toolkit for developers --- tests/test_utils.py | 101 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 tests/test_utils.py diff --git a/tests/test_utils.py b/tests/test_utils.py new file mode 100644 index 0000000..218b9c6 --- /dev/null +++ b/tests/test_utils.py @@ -0,0 +1,101 @@ +"""Tests for utility functions.""" + +from devtoolbelt.utils import ( + format_bytes, + format_duration, + parse_key_value, + pluralize, + truncate, +) + + +class TestFormatBytes: + """Tests for format_bytes function.""" + + def test_bytes(self): + assert format_bytes(500) == "500.00 B" + + def test_kilobytes(self): + assert format_bytes(2048) == "2.00 KB" + + def test_megabytes(self): + assert format_bytes(1048576) == "1.00 MB" + + def test_gigabytes(self): + assert format_bytes(1073741824) == "1.00 GB" + + +class TestFormatDuration: + """Tests for format_duration function.""" + + def test_milliseconds(self): + assert format_duration(0.5) == "500ms" + + def test_seconds(self): + assert format_duration(30) == "30.0s" + + def test_minutes(self): + assert format_duration(120) == "2.0m" + + def test_hours(self): + assert format_duration(7200) == "2.0h" + + def test_days(self): + assert format_duration(172800) == "2.0d" + + +class TestParseKeyValue: + """Tests for parse_key_value function.""" + + def test_empty_string(self): + assert parse_key_value("") == {} + + def test_single_pair(self): + result = parse_key_value("key=value") + assert result == {"key": "value"} + + def test_multiple_pairs(self): + result = parse_key_value("key1=value1,key2=value2,key3=value3") + assert result == { + "key1": "value1", + "key2": "value2", + "key3": "value3" + } + + def test_values_with_spaces(self): + result = parse_key_value("name=John Doe,role=Admin") + assert result == {"name": "John Doe", "role": "Admin"} + + def test_missing_value(self): + result = parse_key_value("key") + assert result == {} + + +class TestPluralize: + """Tests for pluralize function.""" + + def test_singular(self): + assert pluralize(1, "item") == "item" + + def test_plural(self): + assert pluralize(5, "item") == "items" + + def test_custom_plural(self): + assert pluralize(1, "child", "children") == "child" + assert pluralize(3, "child", "children") == "children" + + +class TestTruncate: + """Tests for truncate function.""" + + def test_no_truncation_needed(self): + assert truncate("hello", 10) == "hello" + + def test_truncation(self): + assert truncate("hello world", 8) == "hello..." + + def test_custom_suffix(self): + assert truncate("hello world", 8, suffix="***") == "hello***" + + def test_exact_length(self): + assert truncate("hello", 5) == "hello"