prettytable 3.10.0__tar.gz → 3.10.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. {prettytable-3.10.0 → prettytable-3.10.2}/.pre-commit-config.yaml +6 -7
  2. {prettytable-3.10.0 → prettytable-3.10.2}/PKG-INFO +28 -28
  3. {prettytable-3.10.0 → prettytable-3.10.2}/README.md +26 -26
  4. {prettytable-3.10.0 → prettytable-3.10.2}/pyproject.toml +32 -26
  5. {prettytable-3.10.0 → prettytable-3.10.2}/src/prettytable/prettytable.py +43 -19
  6. {prettytable-3.10.0 → prettytable-3.10.2}/tests/test_colortable.py +62 -1
  7. {prettytable-3.10.0 → prettytable-3.10.2}/tests/test_prettytable.py +284 -129
  8. {prettytable-3.10.0 → prettytable-3.10.2}/.coveragerc +0 -0
  9. {prettytable-3.10.0 → prettytable-3.10.2}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
  10. {prettytable-3.10.0 → prettytable-3.10.2}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
  11. {prettytable-3.10.0 → prettytable-3.10.2}/.github/dependabot.yml +0 -0
  12. {prettytable-3.10.0 → prettytable-3.10.2}/.github/labels.yml +0 -0
  13. {prettytable-3.10.0 → prettytable-3.10.2}/.github/release-drafter.yml +0 -0
  14. {prettytable-3.10.0 → prettytable-3.10.2}/.github/workflows/labels.yml +0 -0
  15. {prettytable-3.10.0 → prettytable-3.10.2}/.github/workflows/lint.yml +0 -0
  16. {prettytable-3.10.0 → prettytable-3.10.2}/.github/workflows/release-drafter.yml +0 -0
  17. {prettytable-3.10.0 → prettytable-3.10.2}/.github/workflows/release.yml +0 -0
  18. {prettytable-3.10.0 → prettytable-3.10.2}/.github/workflows/require-pr-label.yml +0 -0
  19. {prettytable-3.10.0 → prettytable-3.10.2}/.github/workflows/test.yml +0 -0
  20. {prettytable-3.10.0 → prettytable-3.10.2}/.gitignore +0 -0
  21. {prettytable-3.10.0 → prettytable-3.10.2}/CHANGELOG.md +0 -0
  22. {prettytable-3.10.0 → prettytable-3.10.2}/CODE_OF_CONDUCT.md +0 -0
  23. {prettytable-3.10.0 → prettytable-3.10.2}/CONTRIBUTING.md +0 -0
  24. {prettytable-3.10.0 → prettytable-3.10.2}/LICENSE +0 -0
  25. {prettytable-3.10.0 → prettytable-3.10.2}/RELEASING.md +0 -0
  26. {prettytable-3.10.0 → prettytable-3.10.2}/src/prettytable/__init__.py +0 -0
  27. {prettytable-3.10.0 → prettytable-3.10.2}/src/prettytable/colortable.py +0 -0
  28. {prettytable-3.10.0 → prettytable-3.10.2}/src/prettytable/py.typed +0 -0
  29. {prettytable-3.10.0 → prettytable-3.10.2}/tox.ini +0 -0
@@ -1,17 +1,17 @@
1
1
  repos:
2
2
  - repo: https://github.com/astral-sh/ruff-pre-commit
3
- rev: v0.2.2
3
+ rev: v0.5.0
4
4
  hooks:
5
5
  - id: ruff
6
6
  args: [--exit-non-zero-on-fix]
7
7
 
8
8
  - repo: https://github.com/psf/black-pre-commit-mirror
9
- rev: 24.2.0
9
+ rev: 24.4.2
10
10
  hooks:
11
11
  - id: black
12
12
 
13
13
  - repo: https://github.com/pre-commit/pre-commit-hooks
14
- rev: v4.5.0
14
+ rev: v4.6.0
15
15
  hooks:
16
16
  - id: check-case-conflict
17
17
  - id: check-merge-conflict
@@ -23,7 +23,7 @@ repos:
23
23
  exclude: .github/ISSUE_TEMPLATE/bug_report.md|tests/test_prettytable.py
24
24
 
25
25
  - repo: https://github.com/pre-commit/mirrors-mypy
26
- rev: v1.8.0
26
+ rev: v1.10.1
27
27
  hooks:
28
28
  - id: mypy
29
29
  additional_dependencies: [types-colorama, types-setuptools]
@@ -31,13 +31,12 @@ repos:
31
31
  exclude: ^tests/
32
32
 
33
33
  - repo: https://github.com/tox-dev/pyproject-fmt
34
- rev: 1.7.0
34
+ rev: 2.1.3
35
35
  hooks:
36
36
  - id: pyproject-fmt
37
- additional_dependencies: [tox]
38
37
 
39
38
  - repo: https://github.com/abravalheri/validate-pyproject
40
- rev: v0.16
39
+ rev: v0.18
41
40
  hooks:
42
41
  - id: validate-pyproject
43
42
 
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: prettytable
3
- Version: 3.10.0
3
+ Version: 3.10.2
4
4
  Summary: A simple Python library for easily displaying tabular data in a visually appealing ASCII table format
5
5
  Project-URL: Changelog, https://github.com/jazzband/prettytable/releases
6
6
  Project-URL: Homepage, https://github.com/jazzband/prettytable
@@ -497,32 +497,32 @@ whatever you prefer. The `set_style` method just does this automatically for you
497
497
 
498
498
  The options are:
499
499
 
500
- | Option | Details |
501
- | ---------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
502
- | `border` | A Boolean option (must be `True` or `False`). Controls whether a border is drawn inside and around the table. |
503
- | `preserve_internal_border` | A Boolean option (must be `True` or `False`). Controls whether borders are still drawn within the table even when `border=False`. |
504
- | `header` | A Boolean option (must be `True` or `False`). Controls whether the first row of the table is a header showing the names of all the fields. |
505
- | `hrules` | Controls printing of horizontal rules after rows. Allowed values: `FRAME`, `HEADER`, `ALL`, `NONE`. |
506
- | `HEADER`, `ALL`, `NONE` | These are variables defined inside the `prettytable` module so make sure you import them or use `prettytable.FRAME` etc. |
507
- | `vrules` | Controls printing of vertical rules between columns. Allowed values: `FRAME`, `ALL`, `NONE`. |
508
- | `int_format` | A string which controls the way integer data is printed. This works like: `print("%<int_format>d" % data)`. |
509
- | `float_format` | A string which controls the way floating point data is printed. This works like: `print("%<float_format>f" % data)`. |
510
- | `custom_format` | A dictionary of field and callable. This allows you to set any format you want `pf.custom_format["my_col_int"] = ()lambda f, v: f"{v:,}"`. The type of the callable if `callable[[str, Any], str]` |
511
- | `padding_width` | Number of spaces on either side of column data (only used if left and right paddings are `None`). |
512
- | `left_padding_width` | Number of spaces on left-hand side of column data. |
513
- | `right_padding_width` | Number of spaces on right-hand side of column data. |
514
- | `vertical_char` | Single character string used to draw vertical lines. Default: `\|`. |
515
- | `horizontal_char` | Single character string used to draw horizontal lines. Default: `-`. |
516
- | `_horizontal_align_char` | Single character string used to indicate column alignment in horizontal lines. Default: `:` for Markdown, otherwise `None`. |
517
- | `junction_char` | Single character string used to draw line junctions. Default: `+`. |
518
- | `top_junction_char` | Single character string used to draw top line junctions. Default: `junction_char`. |
519
- | `bottom_junction_char` | single character string used to draw bottom line junctions. Default: `junction_char`. |
520
- | `right_junction_char` | Single character string used to draw right line junctions. Default: `junction_char`. |
521
- | `left_junction_char` | Single character string used to draw left line junctions. Default: `junction_char`. |
522
- | `top_right_junction_char` | Single character string used to draw top-right line junctions. Default: `junction_char`. |
523
- | `top_left_junction_char` | Single character string used to draw top-left line junctions. Default: `junction_char`. |
524
- | `bottom_right_junction_char` | Single character string used to draw bottom-right line junctions. Default: `junction_char`. |
525
- | `bottom_left_junction_char` | Single character string used to draw bottom-left line junctions. Default: `junction_char`. |
500
+ | Option | Details |
501
+ | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
502
+ | `border` | A Boolean option (must be `True` or `False`). Controls whether a border is drawn inside and around the table. |
503
+ | `preserve_internal_border` | A Boolean option (must be `True` or `False`). Controls whether borders are still drawn within the table even when `border=False`. |
504
+ | `header` | A Boolean option (must be `True` or `False`). Controls whether the first row of the table is a header showing the names of all the fields. |
505
+ | `hrules` | Controls printing of horizontal rules after rows. Allowed values: `FRAME`, `HEADER`, `ALL`, `NONE`. |
506
+ | `HEADER`, `ALL`, `NONE` | These are variables defined inside the `prettytable` module so make sure you import them or use `prettytable.FRAME` etc. |
507
+ | `vrules` | Controls printing of vertical rules between columns. Allowed values: `FRAME`, `ALL`, `NONE`. |
508
+ | `int_format` | A string which controls the way integer data is printed. This works like: `print("%<int_format>d" % data)`. |
509
+ | `float_format` | A string which controls the way floating point data is printed. This works like: `print("%<float_format>f" % data)`. |
510
+ | `custom_format` | A dictionary of field and callable. This allows you to set any format you want `pf.custom_format["my_col_int"] = lambda f, v: f"{v:,}"`. The type of the callable is `Callable[[str, Any], str]` |
511
+ | `padding_width` | Number of spaces on either side of column data (only used if left and right paddings are `None`). |
512
+ | `left_padding_width` | Number of spaces on left-hand side of column data. |
513
+ | `right_padding_width` | Number of spaces on right-hand side of column data. |
514
+ | `vertical_char` | Single character string used to draw vertical lines. Default: `\|`. |
515
+ | `horizontal_char` | Single character string used to draw horizontal lines. Default: `-`. |
516
+ | `_horizontal_align_char` | Single character string used to indicate column alignment in horizontal lines. Default: `:` for Markdown, otherwise `None`. |
517
+ | `junction_char` | Single character string used to draw line junctions. Default: `+`. |
518
+ | `top_junction_char` | Single character string used to draw top line junctions. Default: `junction_char`. |
519
+ | `bottom_junction_char` | single character string used to draw bottom line junctions. Default: `junction_char`. |
520
+ | `right_junction_char` | Single character string used to draw right line junctions. Default: `junction_char`. |
521
+ | `left_junction_char` | Single character string used to draw left line junctions. Default: `junction_char`. |
522
+ | `top_right_junction_char` | Single character string used to draw top-right line junctions. Default: `junction_char`. |
523
+ | `top_left_junction_char` | Single character string used to draw top-left line junctions. Default: `junction_char`. |
524
+ | `bottom_right_junction_char` | Single character string used to draw bottom-right line junctions. Default: `junction_char`. |
525
+ | `bottom_left_junction_char` | Single character string used to draw bottom-left line junctions. Default: `junction_char`. |
526
526
 
527
527
  You can set the style options to your own settings in two ways:
528
528
 
@@ -465,32 +465,32 @@ whatever you prefer. The `set_style` method just does this automatically for you
465
465
 
466
466
  The options are:
467
467
 
468
- | Option | Details |
469
- | ---------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
470
- | `border` | A Boolean option (must be `True` or `False`). Controls whether a border is drawn inside and around the table. |
471
- | `preserve_internal_border` | A Boolean option (must be `True` or `False`). Controls whether borders are still drawn within the table even when `border=False`. |
472
- | `header` | A Boolean option (must be `True` or `False`). Controls whether the first row of the table is a header showing the names of all the fields. |
473
- | `hrules` | Controls printing of horizontal rules after rows. Allowed values: `FRAME`, `HEADER`, `ALL`, `NONE`. |
474
- | `HEADER`, `ALL`, `NONE` | These are variables defined inside the `prettytable` module so make sure you import them or use `prettytable.FRAME` etc. |
475
- | `vrules` | Controls printing of vertical rules between columns. Allowed values: `FRAME`, `ALL`, `NONE`. |
476
- | `int_format` | A string which controls the way integer data is printed. This works like: `print("%<int_format>d" % data)`. |
477
- | `float_format` | A string which controls the way floating point data is printed. This works like: `print("%<float_format>f" % data)`. |
478
- | `custom_format` | A dictionary of field and callable. This allows you to set any format you want `pf.custom_format["my_col_int"] = ()lambda f, v: f"{v:,}"`. The type of the callable if `callable[[str, Any], str]` |
479
- | `padding_width` | Number of spaces on either side of column data (only used if left and right paddings are `None`). |
480
- | `left_padding_width` | Number of spaces on left-hand side of column data. |
481
- | `right_padding_width` | Number of spaces on right-hand side of column data. |
482
- | `vertical_char` | Single character string used to draw vertical lines. Default: `\|`. |
483
- | `horizontal_char` | Single character string used to draw horizontal lines. Default: `-`. |
484
- | `_horizontal_align_char` | Single character string used to indicate column alignment in horizontal lines. Default: `:` for Markdown, otherwise `None`. |
485
- | `junction_char` | Single character string used to draw line junctions. Default: `+`. |
486
- | `top_junction_char` | Single character string used to draw top line junctions. Default: `junction_char`. |
487
- | `bottom_junction_char` | single character string used to draw bottom line junctions. Default: `junction_char`. |
488
- | `right_junction_char` | Single character string used to draw right line junctions. Default: `junction_char`. |
489
- | `left_junction_char` | Single character string used to draw left line junctions. Default: `junction_char`. |
490
- | `top_right_junction_char` | Single character string used to draw top-right line junctions. Default: `junction_char`. |
491
- | `top_left_junction_char` | Single character string used to draw top-left line junctions. Default: `junction_char`. |
492
- | `bottom_right_junction_char` | Single character string used to draw bottom-right line junctions. Default: `junction_char`. |
493
- | `bottom_left_junction_char` | Single character string used to draw bottom-left line junctions. Default: `junction_char`. |
468
+ | Option | Details |
469
+ | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
470
+ | `border` | A Boolean option (must be `True` or `False`). Controls whether a border is drawn inside and around the table. |
471
+ | `preserve_internal_border` | A Boolean option (must be `True` or `False`). Controls whether borders are still drawn within the table even when `border=False`. |
472
+ | `header` | A Boolean option (must be `True` or `False`). Controls whether the first row of the table is a header showing the names of all the fields. |
473
+ | `hrules` | Controls printing of horizontal rules after rows. Allowed values: `FRAME`, `HEADER`, `ALL`, `NONE`. |
474
+ | `HEADER`, `ALL`, `NONE` | These are variables defined inside the `prettytable` module so make sure you import them or use `prettytable.FRAME` etc. |
475
+ | `vrules` | Controls printing of vertical rules between columns. Allowed values: `FRAME`, `ALL`, `NONE`. |
476
+ | `int_format` | A string which controls the way integer data is printed. This works like: `print("%<int_format>d" % data)`. |
477
+ | `float_format` | A string which controls the way floating point data is printed. This works like: `print("%<float_format>f" % data)`. |
478
+ | `custom_format` | A dictionary of field and callable. This allows you to set any format you want `pf.custom_format["my_col_int"] = lambda f, v: f"{v:,}"`. The type of the callable is `Callable[[str, Any], str]` |
479
+ | `padding_width` | Number of spaces on either side of column data (only used if left and right paddings are `None`). |
480
+ | `left_padding_width` | Number of spaces on left-hand side of column data. |
481
+ | `right_padding_width` | Number of spaces on right-hand side of column data. |
482
+ | `vertical_char` | Single character string used to draw vertical lines. Default: `\|`. |
483
+ | `horizontal_char` | Single character string used to draw horizontal lines. Default: `-`. |
484
+ | `_horizontal_align_char` | Single character string used to indicate column alignment in horizontal lines. Default: `:` for Markdown, otherwise `None`. |
485
+ | `junction_char` | Single character string used to draw line junctions. Default: `+`. |
486
+ | `top_junction_char` | Single character string used to draw top line junctions. Default: `junction_char`. |
487
+ | `bottom_junction_char` | single character string used to draw bottom line junctions. Default: `junction_char`. |
488
+ | `right_junction_char` | Single character string used to draw right line junctions. Default: `junction_char`. |
489
+ | `left_junction_char` | Single character string used to draw left line junctions. Default: `junction_char`. |
490
+ | `top_right_junction_char` | Single character string used to draw top-right line junctions. Default: `junction_char`. |
491
+ | `top_left_junction_char` | Single character string used to draw top-left line junctions. Default: `junction_char`. |
492
+ | `bottom_right_junction_char` | Single character string used to draw bottom-right line junctions. Default: `junction_char`. |
493
+ | `bottom_left_junction_char` | Single character string used to draw bottom-left line junctions. Default: `junction_char`. |
494
494
 
495
495
  You can set the style options to your own settings in two ways:
496
496
 
@@ -9,9 +9,13 @@ requires = [
9
9
  name = "prettytable"
10
10
  description = "A simple Python library for easily displaying tabular data in a visually appealing ASCII table format"
11
11
  readme = "README.md"
12
- license = {text = "BSD (3 clause)"}
13
- maintainers = [{name ="Jazzband"}]
14
- authors = [{name = "Luke Maurits", email = "luke@maurits.id.au"}]
12
+ license = { text = "BSD (3 clause)" }
13
+ maintainers = [
14
+ { name = "Jazzband" },
15
+ ]
16
+ authors = [
17
+ { name = "Luke Maurits", email = "luke@maurits.id.au" },
18
+ ]
15
19
  requires-python = ">=3.8"
16
20
  classifiers = [
17
21
  "License :: OSI Approved :: BSD License",
@@ -34,16 +38,14 @@ dynamic = [
34
38
  dependencies = [
35
39
  "wcwidth",
36
40
  ]
37
- [project.optional-dependencies]
38
- tests = [
41
+ optional-dependencies.tests = [
39
42
  "pytest",
40
43
  "pytest-cov",
41
44
  "pytest-lazy-fixtures",
42
45
  ]
43
- [project.urls]
44
- Changelog = "https://github.com/jazzband/prettytable/releases"
45
- Homepage = "https://github.com/jazzband/prettytable"
46
- Source = "https://github.com/jazzband/prettytable"
46
+ urls.Changelog = "https://github.com/jazzband/prettytable/releases"
47
+ urls.Homepage = "https://github.com/jazzband/prettytable"
48
+ urls.Source = "https://github.com/jazzband/prettytable"
47
49
 
48
50
  [tool.hatch]
49
51
  version.source = "vcs"
@@ -54,28 +56,32 @@ local_scheme = "no-local-version"
54
56
  [tool.ruff]
55
57
  fix = true
56
58
 
57
- [tool.ruff.lint]
58
- select = [
59
- "C4", # flake8-comprehensions
60
- "E", # pycodestyle errors
61
- "EM", # flake8-errmsg
62
- "F", # pyflakes errors
63
- "I", # isort
64
- "ISC", # flake8-implicit-str-concat
65
- "LOG", # flake8-logging
66
- "PGH", # pygrep-hooks
59
+ lint.select = [
60
+ "C4", # flake8-comprehensions
61
+ "E", # pycodestyle errors
62
+ "EM", # flake8-errmsg
63
+ "F", # pyflakes errors
64
+ "I", # isort
65
+ "ISC", # flake8-implicit-str-concat
66
+ "LOG", # flake8-logging
67
+ "PGH", # pygrep-hooks
67
68
  "RUF100", # unused noqa (yesqa)
68
- "UP", # pyupgrade
69
- "W", # pycodestyle warnings
70
- "YTT", # flake8-2020
69
+ "UP", # pyupgrade
70
+ "W", # pycodestyle warnings
71
+ "YTT", # flake8-2020
71
72
  ]
72
- extend-ignore = [
73
+ lint.extend-ignore = [
73
74
  "E203", # Whitespace before ':'
74
75
  "E221", # Multiple spaces before operator
75
76
  "E226", # Missing whitespace around arithmetic operator
76
77
  "E241", # Multiple spaces after ','
77
78
  ]
79
+ lint.isort.known-first-party = [
80
+ "prettytable",
81
+ ]
82
+ lint.isort.required-imports = [
83
+ "from __future__ import annotations",
84
+ ]
78
85
 
79
- [tool.ruff.lint.isort]
80
- known-first-party = ["prettytable"]
81
- required-imports = ["from __future__ import annotations"]
86
+ [tool.pyproject-fmt]
87
+ max_supported_python = "3.13"
@@ -135,6 +135,7 @@ class PrettyTable:
135
135
  self.int_format = {}
136
136
  self.float_format = {}
137
137
  self.custom_format = {}
138
+ self._style = None
138
139
 
139
140
  if field_names:
140
141
  self.field_names = field_names
@@ -1270,6 +1271,7 @@ class PrettyTable:
1270
1271
  ##############################
1271
1272
 
1272
1273
  def set_style(self, style) -> None:
1274
+ self._style = style
1273
1275
  if style == DEFAULT:
1274
1276
  self._set_default_style()
1275
1277
  elif style == MSWORD_FRIENDLY:
@@ -1550,21 +1552,26 @@ class PrettyTable:
1550
1552
 
1551
1553
  def _format_value(self, field, value):
1552
1554
  if isinstance(value, int) and field in self._int_format:
1553
- return ("%%%sd" % self._int_format[field]) % value
1555
+ return (f"%{self._int_format[field]}d") % value
1554
1556
  elif isinstance(value, float) and field in self._float_format:
1555
- return ("%%%sf" % self._float_format[field]) % value
1557
+ return (f"%{self._float_format[field]}f") % value
1556
1558
 
1557
1559
  formatter = self._custom_format.get(field, (lambda f, v: str(v)))
1558
1560
  return formatter(field, value)
1559
1561
 
1560
1562
  def _compute_table_width(self, options):
1561
- table_width = 2 if options["vrules"] in (FRAME, ALL) else 0
1563
+ if options["vrules"] == FRAME:
1564
+ table_width = 2
1565
+ if options["vrules"] == ALL:
1566
+ table_width = 1
1567
+ else:
1568
+ table_width = 0
1562
1569
  per_col_padding = sum(self._get_padding_widths(options))
1563
1570
  for index, fieldname in enumerate(self.field_names):
1564
1571
  if not options["fields"] or (
1565
1572
  options["fields"] and fieldname in options["fields"]
1566
1573
  ):
1567
- table_width += self._widths[index] + per_col_padding
1574
+ table_width += self._widths[index] + per_col_padding + 1
1568
1575
  return table_width
1569
1576
 
1570
1577
  def _compute_widths(self, rows, options) -> None:
@@ -1588,23 +1595,33 @@ class PrettyTable:
1588
1595
  widths[index] = max(widths[index], _get_size(value)[0])
1589
1596
  if fieldname in self.min_width:
1590
1597
  widths[index] = max(widths[index], self.min_width[fieldname])
1598
+
1599
+ if self._style == MARKDOWN:
1600
+ # Markdown needs at least one hyphen in the divider
1601
+ if self._align[fieldname] in ("l", "r"):
1602
+ min_width = 1
1603
+ else: # "c"
1604
+ min_width = 3
1605
+ widths[index] = max(min_width, widths[index])
1606
+
1591
1607
  self._widths = widths
1592
1608
 
1609
+ per_col_padding = sum(self._get_padding_widths(options))
1593
1610
  # Are we exceeding max_table_width?
1594
1611
  if self._max_table_width:
1595
1612
  table_width = self._compute_table_width(options)
1596
1613
  if table_width > self._max_table_width:
1597
1614
  # Shrink widths in proportion
1598
- scale = 1.0 * self._max_table_width / table_width
1599
- widths = [int(w * scale) for w in widths]
1600
- self._widths = widths
1615
+ markup_chars = per_col_padding * len(widths) + len(widths) - 1
1616
+ scale = (self._max_table_width - markup_chars) / (
1617
+ table_width - markup_chars
1618
+ )
1619
+ self._widths = [max(1, int(w * scale)) for w in widths]
1601
1620
 
1602
1621
  # Are we under min_table_width or title width?
1603
1622
  if self._min_table_width or options["title"]:
1604
1623
  if options["title"]:
1605
- title_width = len(options["title"]) + sum(
1606
- self._get_padding_widths(options)
1607
- )
1624
+ title_width = len(options["title"]) + per_col_padding
1608
1625
  if options["vrules"] in (FRAME, ALL):
1609
1626
  title_width += 2
1610
1627
  else:
@@ -1619,9 +1636,7 @@ class PrettyTable:
1619
1636
  borders = 0
1620
1637
 
1621
1638
  # Subtract padding for each column and borders
1622
- min_width -= (
1623
- sum([sum(self._get_padding_widths(options)) for _ in widths]) + borders
1624
- )
1639
+ min_width -= sum([per_col_padding for _ in widths]) + borders
1625
1640
  # What is being scaled is content so we sum column widths
1626
1641
  content_width = sum(widths) or 1
1627
1642
 
@@ -1872,7 +1887,10 @@ class PrettyTable:
1872
1887
  )
1873
1888
  bits.append(endpoint)
1874
1889
  title = " " * lpad + title + " " * rpad
1875
- bits.append(self._justify(title, len(self._hrule) - 2, "c"))
1890
+ lpad, rpad = self._get_padding_widths(options)
1891
+ sum_widths = sum([n + lpad + rpad + 1 for n in self._widths])
1892
+
1893
+ bits.append(self._justify(title, sum_widths - 1, "c"))
1876
1894
  bits.append(endpoint)
1877
1895
  lines.append("".join(bits))
1878
1896
  return "\n".join(lines)
@@ -1884,9 +1902,11 @@ class PrettyTable:
1884
1902
  if options["hrules"] in (ALL, FRAME):
1885
1903
  bits.append(self._stringify_hrule(options, "top_"))
1886
1904
  if options["title"] and options["vrules"] in (ALL, FRAME):
1905
+ left_j_len = len(self.left_junction_char)
1906
+ right_j_len = len(self.right_junction_char)
1887
1907
  bits[-1] = (
1888
1908
  self.left_junction_char
1889
- + bits[-1][1:-1]
1909
+ + bits[-1][left_j_len:-right_j_len]
1890
1910
  + self.right_junction_char
1891
1911
  )
1892
1912
  bits.append("\n")
@@ -2178,7 +2198,9 @@ class PrettyTable:
2178
2198
  if options["fields"] and field not in options["fields"]:
2179
2199
  continue
2180
2200
  lines.append(
2181
- " <th>%s</th>" % escape(field).replace("\n", linebreak)
2201
+ " <th>{}</th>".format(
2202
+ escape(field).replace("\n", linebreak)
2203
+ )
2182
2204
  )
2183
2205
  lines.append(" </tr>")
2184
2206
  lines.append(" </thead>")
@@ -2193,7 +2215,9 @@ class PrettyTable:
2193
2215
  if options["fields"] and field not in options["fields"]:
2194
2216
  continue
2195
2217
  lines.append(
2196
- " <td>%s</td>" % escape(datum).replace("\n", linebreak)
2218
+ " <td>{}</td>".format(
2219
+ escape(datum).replace("\n", linebreak)
2220
+ )
2197
2221
  )
2198
2222
  lines.append(" </tr>")
2199
2223
  lines.append(" </tbody>")
@@ -2341,7 +2365,7 @@ class PrettyTable:
2341
2365
 
2342
2366
  alignments = "".join([self._align[field] for field in wanted_fields])
2343
2367
 
2344
- begin_cmd = "\\begin{tabular}{%s}" % alignments
2368
+ begin_cmd = f"\\begin{{tabular}}{{{alignments}}}"
2345
2369
  lines.append(begin_cmd)
2346
2370
 
2347
2371
  # Headers
@@ -2383,7 +2407,7 @@ class PrettyTable:
2383
2407
  if options["border"] and options["vrules"] in [ALL, FRAME]:
2384
2408
  alignment_str = "|" + alignment_str + "|"
2385
2409
 
2386
- begin_cmd = "\\begin{tabular}{%s}" % alignment_str
2410
+ begin_cmd = f"\\begin{{tabular}}{{{alignment_str}}}"
2387
2411
  lines.append(begin_cmd)
2388
2412
  if options["border"] and options["hrules"] in [ALL, FRAME]:
2389
2413
  lines.append("\\hline")
@@ -3,7 +3,7 @@ from __future__ import annotations
3
3
  import pytest
4
4
 
5
5
  from prettytable import PrettyTable
6
- from prettytable.colortable import RESET_CODE, ColorTable, Theme
6
+ from prettytable.colortable import RESET_CODE, ColorTable, Theme, Themes
7
7
 
8
8
 
9
9
  @pytest.fixture
@@ -94,3 +94,64 @@ class TestFormatCode:
94
94
  def test_multiple(self) -> None:
95
95
  assert Theme.format_code("30;42") == "\x1b[30;42m"
96
96
  assert Theme.format_code("\x1b[30;42m") == "\x1b[30;42m"
97
+
98
+
99
+ class TestColorTableRendering:
100
+ """Tests for the rendering of the color table
101
+
102
+ Methods
103
+ -------
104
+ test_color_table_rendering
105
+ Tests the color table rendering using the default alignment (`'c'`)
106
+ """
107
+
108
+ def test_color_table_rendering(self) -> None:
109
+ """Tests the color table rendering using the default alignment (`'c'`)"""
110
+ chars = {
111
+ "+": "\x1b[36m+\x1b[0m\x1b[96m",
112
+ "-": "\x1b[34m-\x1b[0m\x1b[96m",
113
+ "|": "\x1b[34m|\x1b[0m\x1b[96m",
114
+ " ": " ",
115
+ }
116
+
117
+ plus = chars.get("+")
118
+ minus = chars.get("-")
119
+ pipe = chars.get("|")
120
+ space = chars.get(" ")
121
+
122
+ # +-----------------------+
123
+ # | Efforts |
124
+ # +---+---+---+---+---+---+
125
+ # | A | B | C | D | E | f |
126
+ # +---+---+---+---+---+---+
127
+ # | 1 | 2 | 3 | 4 | 5 | 6 |
128
+ # +---+---+---+---+---+---+
129
+
130
+ header = (
131
+ plus + minus * 23 + plus,
132
+ pipe + space * 8 + "Efforts" + space * 8 + pipe,
133
+ (plus + minus * 3) * 6 + plus,
134
+ )
135
+
136
+ body = (
137
+ "".join(pipe + space + char + space for char in "ABCDEF") + pipe,
138
+ (plus + minus * 3) * 6 + plus,
139
+ "".join(pipe + space + char + space for char in "123456") + pipe,
140
+ (plus + minus * 3) * 6 + plus,
141
+ )
142
+
143
+ header_str = str("\n".join(header))
144
+ body_str = str("\n".join(body))
145
+
146
+ table = ColorTable(
147
+ ("A", "B", "C", "D", "E", "F"),
148
+ theme=Themes.OCEAN,
149
+ )
150
+
151
+ table.title = "Efforts"
152
+ table.add_row([1, 2, 3, 4, 5, 6])
153
+
154
+ expected = header_str + "\n" + body_str + "\x1b[0m"
155
+ result = str(table)
156
+
157
+ assert expected == result