Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Widen tables with long titles #216

Merged
merged 2 commits into from Nov 9, 2022

Conversation

etjones
Copy link

@etjones etjones commented Nov 8, 2022

Recalculated this to scale the table correctly.

  • Added test_prettytable.test_all_lengths_equal_with_long_title() to capture this this error as well.

Original behavior:


Without title:
+---------+---------+
| field a | field b |
+---------+---------+
|    a1   |    b1   |
|    a2   |    b2   |
+---------+---------+

With title:
+-----------------------------------------------------------------+
| === 80 char str ================================================================ |
+--------------------------------+--------------------------------+
|            field a             |            field b             |
+--------------------------------+--------------------------------+
|               a1               |               b1               |
|               a2               |               b2               |
+--------------------------------+--------------------------------+

New behavior:

With title:
+-----------------------------------------------------------------------------------+
|  === 80 char str ================================================================ |
+-----------------------------------------+-----------------------------------------+
|                 field a                 |                 field b                 |
+-----------------------------------------+-----------------------------------------+
|                    a1                   |                    b1                   |
|                    a2                   |                    b2                   |
+-----------------------------------------+-----------------------------------------+

Athiriyya and others added 2 commits November 8, 2022 15:51
… table. Recalculated this to scale the table correctly.

- Added test_prettytable.test_all_lengths_equal_with_long_title() to capture this this error as well.

Former behavior:
```

Without title:
+---------+---------+
| field a | field b |
+---------+---------+
|    a1   |    b1   |
|    a2   |    b2   |
+---------+---------+

With title:
+-----------------------------------------------------------------+
| === 80 char str ================================================================ |
+--------------------------------+--------------------------------+
|            field a             |            field b             |
+--------------------------------+--------------------------------+
|               a1               |               b1               |
|               a2               |               b2               |
+--------------------------------+--------------------------------+
```

``` New behavior:

With title:
+-----------------------------------------------------------------------------------+
|  === 80 char str ================================================================ |
+-----------------------------------------+-----------------------------------------+
|                 field a                 |                 field b                 |
+-----------------------------------------+-----------------------------------------+
|                    a1                   |                    b1                   |
|                    a2                   |                    b2                   |
+-----------------------------------------+-----------------------------------------+
```
@codecov
Copy link

codecov bot commented Nov 8, 2022

Codecov Report

Merging #216 (bd7183d) into master (c73b7e3) will increase coverage by 0.14%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #216      +/-   ##
==========================================
+ Coverage   94.05%   94.19%   +0.14%     
==========================================
  Files           5        5              
  Lines        2254     2258       +4     
==========================================
+ Hits         2120     2127       +7     
+ Misses        134      131       -3     
Flag Coverage Δ
macos-latest 94.19% <100.00%> (+0.14%) ⬆️
ubuntu-latest 94.19% <100.00%> (+0.14%) ⬆️
windows-latest 94.06% <100.00%> (+0.14%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/prettytable/prettytable.py 90.43% <100.00%> (+0.22%) ⬆️
tests/test_prettytable.py 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@hugovk hugovk added the changelog: Fixed For any bug fixes label Nov 9, 2022
@hugovk hugovk changed the title - Tables with long titles could let the title line be wider than the table. Widen tables with long titles Nov 9, 2022
@hugovk
Copy link
Member

hugovk commented Nov 9, 2022

Thank you!

@hugovk hugovk merged commit aa4e316 into jazzband:master Nov 9, 2022
@kzwolenik95
Copy link
Contributor

This change broke parameter min_table_width:
I have suggested fix in #219

Traceback (most recent call last):
  File "=prettytable\hehe.py", line 22, in <module>
    print(x)
  File "prettytable\src\prettytable\prettytable.py", line 330, in __str__
    return self.get_string()
  File "prettytable\src\prettytable\prettytable.py", line 1715, in get_string
    self._compute_widths(formatted_rows, options)
  File "prettytable\src\prettytable\prettytable.py", line 1592, in _compute_widths
    scale = 1.0 * (len(options["title"]) - border_char_count) / sum(widths)
TypeError: object of type 'NoneType' has no len()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: Fixed For any bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants