• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

thombashi / pytablewriter / 7161421392

11 Dec 2023 12:45AM CUT coverage: 89.714%. Remained the same
7161421392

Pull #61

github

web-flow
Bump actions/setup-python from 4 to 5

Bumps [actions/setup-python](https://github.com/actions/setup-python) from 4 to 5.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](https://github.com/actions/setup-python/compare/v4...v5)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #61: Bump actions/setup-python from 4 to 5

953 of 1135 branches covered (0.0%)

3288 of 3665 relevant lines covered (89.71%)

0.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.55
/pytablewriter/writer/text/sourcecode/_python.py
1
from typing import Any, List
1✔
2

3
import typepy
1✔
4

5
from ...._function import dateutil_datetime_formatter, quote_datetime_formatter
1✔
6
from ....sanitizer import sanitize_python_var_name
1✔
7
from ._sourcecode import SourceCodeTableWriter
1✔
8

9

10
class PythonCodeTableWriter(SourceCodeTableWriter):
1✔
11
    """
12
    A table writer class for Python source code format.
13

14
        :Example:
15
            :ref:`example-python-code-table-writer`
16

17
    .. py:method:: write_table
18

19
        |write_table| with Python format.
20
        The tabular data are written as a nested list variable definition
21
        for Python format.
22

23
        :raises pytablewriter.EmptyTableNameError:
24
            If the |table_name| is empty.
25
        :Example:
26
            :ref:`example-python-code-table-writer`
27

28
        .. note::
29
            Specific values in the tabular data are converted when writing:
30

31
            - |None|: written as ``None``
32
            - |inf|: written as ``float("inf")``
33
            - |nan|: written as ``float("nan")``
34
            - |datetime| instances determined by |is_datetime_instance_formatting| attribute:
35
                - |True|: written as `dateutil.parser <https://dateutil.readthedocs.io/en/stable/parser.html>`__
36
                - |False|: written as |str|
37

38
            .. seealso::
39
                :ref:`example-type-hint-python`
40
    """
41

42
    FORMAT_NAME = "python"
1✔
43

44
    @property
1✔
45
    def format_name(self) -> str:
1✔
46
        return self.FORMAT_NAME
1✔
47

48
    @property
1✔
49
    def support_split_write(self) -> bool:
1✔
50
        return True
1✔
51

52
    def __init__(self, **kwargs: Any) -> None:
1✔
53
        super().__init__(**kwargs)
1✔
54

55
        self._dp_extractor.type_value_map = {
1✔
56
            typepy.Typecode.NONE: None,
57
            typepy.Typecode.INFINITY: 'float("inf")',
58
            typepy.Typecode.NAN: 'float("nan")',
59
        }
60

61
    def get_variable_name(self, value: str) -> str:
1✔
62
        return sanitize_python_var_name(self.table_name, "_").lower()
1✔
63

64
    def _write_table(self, **kwargs: Any) -> None:
1✔
65
        if self.is_datetime_instance_formatting:
1!
66
            self._dp_extractor.datetime_formatter = dateutil_datetime_formatter
1✔
67
        else:
68
            self._dp_extractor.datetime_formatter = quote_datetime_formatter
×
69

70
        self.inc_indent_level()
1✔
71
        super()._write_table(**kwargs)
1✔
72
        self.dec_indent_level()
1✔
73

74
    def _get_opening_row_items(self) -> List[str]:
1✔
75
        if typepy.is_not_null_string(self.table_name):
1!
76
            return [self.variable_name + " = ["]
1✔
77

78
        return ["["]
×
79

80
    def _get_closing_row_items(self) -> List[str]:
1✔
81
        return ["]"]
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc