Skip to content

Commit

Permalink
Exclude tox from coverage, command tableprinter.
Browse files Browse the repository at this point in the history
  • Loading branch information
frinkelpi authored and dbrgn committed Nov 13, 2016
1 parent 84205cb commit 1081b05
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 64 deletions.
6 changes: 5 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
[run]
source = fahrplan
omit = */tests/*
omit =
*/tests/*
*/.tox/*
*/texttable/*
setup.py
branch = True

[report]
Expand Down
124 changes: 62 additions & 62 deletions fahrplan/tableprinter.py
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
# -*- coding: utf-8 -*-

from __future__ import print_function, division, absolute_import, unicode_literals

import sys
import logging

import six


class Tableprinter(object):
"""Simple class to print an ascii table. Expects unicode data."""

def __init__(self, widths, separator=' '):
"""Constructor for table printer.
Args:
widths: Tuple containing the width for each column.
separator: The column separator (default ' ').
"""
self.widths = widths
self.separator = separator
try:
self.encoding = sys.stdout.encoding or 'utf-8'
except AttributeError:
self.encoding = 'utf-8'
logging.debug('Using output encoding %s' % self.encoding)

def print_line(self, items):
"""Print data line.
Args:
items: Tuple containing row data.
"""
pairs = zip(items, self.widths)
for item, width in pairs:
out = item.ljust(width) + self.separator
if not six.PY3:
out = out.encode(self.encoding, 'replace')
print(out, end='')
print() # newline

def print_separator(self, char='-', cols=[]):
"""Print separator line.
Args:
char: Character to use for printing the separator.
cols: The 0 based column indexes, where the separator should be
printed (by default the line is printed across all columns)
"""
if not cols:
width = sum(self.widths) + len(self.separator) * len(self.widths)
print(char * width)
else:
for i in range(len(self.widths)):
symbol = char if i in cols else ' '
print(symbol * self.widths[i], end='')
print(self.separator, end='')
print() # newline
# # -*- coding: utf-8 -*-

# from __future__ import print_function, division, absolute_import, unicode_literals

# import sys
# import logging

# import six


# class Tableprinter(object):
# """Simple class to print an ascii table. Expects unicode data."""

# def __init__(self, widths, separator=' '):
# """Constructor for table printer.

# Args:
# widths: Tuple containing the width for each column.
# separator: The column separator (default ' ').

# """
# self.widths = widths
# self.separator = separator
# try:
# self.encoding = sys.stdout.encoding or 'utf-8'
# except AttributeError:
# self.encoding = 'utf-8'
# logging.debug('Using output encoding %s' % self.encoding)

# def print_line(self, items):
# """Print data line.

# Args:
# items: Tuple containing row data.

# """
# pairs = zip(items, self.widths)
# for item, width in pairs:
# out = item.ljust(width) + self.separator
# if not six.PY3:
# out = out.encode(self.encoding, 'replace')
# print(out, end='')
# print() # newline

# def print_separator(self, char='-', cols=[]):
# """Print separator line.

# Args:
# char: Character to use for printing the separator.
# cols: The 0 based column indexes, where the separator should be
# printed (by default the line is printed across all columns)

# """
# if not cols:
# width = sum(self.widths) + len(self.separator) * len(self.widths)
# print(char * width)
# else:
# for i in range(len(self.widths)):
# symbol = char if i in cols else ' '
# print(symbol * self.widths[i], end='')
# print(self.separator, end='')
# print() # newline
2 changes: 1 addition & 1 deletion fahrplan/tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from .. import meta
from .. import parser
from ..tableprinter import Tableprinter
#from ..tableprinter import Tableprinter


BASE_COMMAND = 'python -m fahrplan.main'
Expand Down

0 comments on commit 1081b05

Please sign in to comment.