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

SwissDataScienceCenter / renku-python / 9058668052

13 May 2024 07:05AM UTC coverage: 77.713% (-8.4%) from 86.115%
9058668052

Pull #3727

github

web-flow
Merge 128d38387 into 050ed61bf
Pull Request #3727: fix: don't fail session launch when gitlab couldn't be reached

15 of 29 new or added lines in 3 files covered. (51.72%)

2594 existing lines in 125 files now uncovered.

23893 of 30745 relevant lines covered (77.71%)

3.2 hits per line

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

96.3
/renku/core/util/tabulate.py
1
# Copyright Swiss Data Science Center (SDSC). A partnership between
2
# École Polytechnique Fédérale de Lausanne (EPFL) and
3
# Eidgenössische Technische Hochschule Zürich (ETHZ).
4
#
5
# Licensed under the Apache License, Version 2.0 (the "License");
6
# you may not use this file except in compliance with the License.
7
# You may obtain a copy of the License at
8
#
9
#     http://www.apache.org/licenses/LICENSE-2.0
10
#
11
# Unless required by applicable law or agreed to in writing, software
12
# distributed under the License is distributed on an "AS IS" BASIS,
13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
# See the License for the specific language governing permissions and
15
# limitations under the License.
16
"""Print a collection as a table."""
7✔
17

18
from datetime import datetime
7✔
19
from operator import attrgetter
7✔
20

21

22
def format_cell(cell, datetime_fmt=None):
7✔
23
    """Format a cell."""
24
    if datetime_fmt and isinstance(cell, datetime):
2✔
25
        if cell.tzinfo:
2✔
26
            cell = cell.astimezone()
2✔
27
        return cell.strftime(datetime_fmt)
2✔
28
    elif isinstance(cell, bool):
2✔
29
        return "*" if cell else ""
2✔
30
    elif isinstance(cell, int):
2✔
31
        return f"{cell:,}"
1✔
32
    return cell
2✔
33

34

35
def tabulate(collection, headers, datetime_fmt="%Y-%m-%d %H:%M:%S", **kwargs):
7✔
36
    """Pretty-print a collection."""
37
    from tabulate import tabulate as to_table
3✔
38

39
    if isinstance(headers, dict):
3✔
40
        attrs = headers.keys()
3✔
41
        # if mapping is not specified keep original
42
        names = [key if value is None else value for key, value in headers.items()]
3✔
43
    else:
44
        attrs = names = headers
1✔
45

46
    if collection and isinstance(collection[0], dict):
3✔
47
        return to_table(collection, headers="keys", **kwargs)
1✔
48

49
    # NOTE: Convert instance attributes to a collection of formatted cells.
50
    table = [
3✔
51
        (format_cell(cell, datetime_fmt=datetime_fmt) for cell in _to_list(attrgetter(*attrs)(c))) for c in collection
52
    ]
53
    return to_table(table, headers=[h.upper() for h in names], **kwargs)
3✔
54

55

56
def _to_list(value):
7✔
57
    """Wrap value to a collection type."""
58
    if isinstance(value, (list, tuple)):
2✔
59
        return value
2✔
60

UNCOV
61
    return [value]
×
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