|
| 1 | +# tests/test_utils.py |
| 2 | +import pytest |
| 3 | +from ttk_text.utils import parse_padding |
| 4 | + |
| 5 | + |
| 6 | +class TestParsePadding: |
| 7 | + def test_parse_tuple_left(self): |
| 8 | + result = parse_padding(5) |
| 9 | + assert result is not None |
| 10 | + assert result.to_padx() == (5, 5) |
| 11 | + assert result.to_pady() == (5, 5) |
| 12 | + |
| 13 | + def test_parse_tuple_left_top(self): |
| 14 | + result = parse_padding((5, 10)) |
| 15 | + assert result is not None |
| 16 | + assert result.to_padx() == (5, 5) |
| 17 | + assert result.to_pady() == (10, 10) |
| 18 | + |
| 19 | + def test_parse_tuple_left_top_right_bottom(self): |
| 20 | + result = parse_padding((1, 2, 3, 4)) |
| 21 | + assert result is not None |
| 22 | + assert result.to_padx() == (1, 3) |
| 23 | + assert result.to_pady() == (2, 4) |
| 24 | + |
| 25 | + def test_parse_string_left(self): |
| 26 | + result5p = parse_padding("5p") |
| 27 | + assert result5p is not None |
| 28 | + assert result5p.to_padx() == ("5p", "5p") |
| 29 | + assert result5p.to_pady() == ("5p", "5p") |
| 30 | + |
| 31 | + |
| 32 | + def test_parse_string_left_top(self): |
| 33 | + result5p10p = parse_padding("5p 10p") |
| 34 | + assert result5p10p is not None |
| 35 | + assert result5p10p.to_padx() == ("5p", "5p") |
| 36 | + assert result5p10p.to_pady() == ("10p", "10p") |
| 37 | + |
| 38 | + def test_parse_string_left_top_right_bottom(self): |
| 39 | + result5p10p15p20p = parse_padding("5p 10p 15p 20p") |
| 40 | + assert result5p10p15p20p is not None |
| 41 | + assert result5p10p15p20p.to_padx() == ("5p", "15p") |
| 42 | + assert result5p10p15p20p.to_pady() == ("10p", "20p") |
| 43 | + |
| 44 | + |
| 45 | + def test_parse_none(self): |
| 46 | + result = parse_padding(None) |
| 47 | + assert result is None |
| 48 | + |
| 49 | + |
| 50 | + # def test_parse_invalid(self): |
| 51 | + # with pytest.raises(ValueError): |
| 52 | + # parse_padding("invalid") |
0 commit comments