third_party.pigweed.src/pw_console/py/text_formatting_test.py
Anthony DiGirolamo f53188afca pw_console: Log pane table view
- Table view option for log panes that renders each metadata field in
  it's own justified column.
- Move LogLine class out of log_container.py to it's own file
- Create table_test.py to check correct column size, header, and row
  formatting.
- Fix typos in text_formatting_test.py
- Clean up and split LogContainer.render_content() code (was named
  LogContainer.draw)

Bug: 412
Change-Id: I7354a659a2bb4486e8a84df5618ca3e8121f4413
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/51522
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
Pigweed-Auto-Submit: Anthony DiGirolamo <tonymd@google.com>
Reviewed-by: Keir Mierle <keir@google.com>
2021-07-02 01:52:17 +00:00

95 lines
3.9 KiB
Python

# Copyright 2021 The Pigweed Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
"""Tests for pw_console.text_formatting"""
import unittest
from parameterized import parameterized # type: ignore
from pw_console.text_formatting import get_line_height
class TestTextFormatting(unittest.TestCase):
"""Tests for text_formatting functions."""
@parameterized.expand([
(
'with short prefix height 2',
len('LINE that should be wrapped'), # text_width
len('| |'), # screen_width
len('--->'), # prefix_width
( 'LINE that should b\n'
'--->e wrapped \n').count('\n'), # expected_height
len( '_____'), # expected_trailing_characters
),
(
'with short prefix height 3',
len('LINE that should be wrapped three times.'), # text_width
len('| |'), # screen_width
len('--->'), # prefix_width
( 'LINE that should b\n'
'--->e wrapped thre\n'
'--->e times. \n').count('\n'), # expected_height
len( '______'), # expected_trailing_characters
),
(
'with short prefix height 4',
len('LINE that should be wrapped even more times, say four.'),
len('| |'), # screen_width
len('--->'), # prefix_width
( 'LINE that should b\n'
'--->e wrapped even\n'
'---> more times, s\n'
'--->ay four. \n').count('\n'), # expected_height
len( '______'), # expected_trailing_characters
),
(
'no wrapping needed',
len('LINE wrapped'), # text_width
len('| |'), # screen_width
len('--->'), # prefix_width
( 'LINE wrapped \n').count('\n'), # expected_height
len( '______'), # expected_trailing_characters
),
(
'prefix is > screen width',
len('LINE that should be wrapped'), # text_width
len('| |'), # screen_width
len('------------------>'), # prefix_width
( 'LINE that should b\n'
'e wrapped \n').count('\n'), # expected_height
len( '_________'), # expected_trailing_characters
),
(
'prefix is == screen width',
len('LINE that should be wrapped'), # text_width
len('| |'), # screen_width
len('----------------->'), # prefix_width
( 'LINE that should b\n'
'e wrapped \n').count('\n'), # expected_height
len( '_________'), # expected_trailing_characters
),
]) # yapf: disable
def test_get_line_height(self, _name, text_width, screen_width,
prefix_width, expected_height,
expected_trailing_characters) -> None:
"""Test line height calculations."""
height, remaining_width = get_line_height(text_width, screen_width,
prefix_width)
self.assertEqual(height, expected_height)
self.assertEqual(remaining_width, expected_trailing_characters)
if __name__ == '__main__':
unittest.main()