# Path: solvebio/utils/tabulate.py
# def tabulate(tabular_data, headers=[], tablefmt="orgmode",
#              floatfmt="g", aligns=[], missingval="", sort=True, is_tsv=False):
#     list_of_lists, headers = _normalize_tabular_data(tabular_data, headers,
#                                                      sort=sort)
# 
#     # optimization: look for ANSI control codes once,
#     # enable smart width functions only if a control code is found
#     plain_text = '\n'.join(
#         ['\t'.join(map(_text_type, headers))] +
#         ['\t'.join(map(_text_type, row)) for row in list_of_lists])
# 
#     has_invisible = re.search(_invisible_codes, plain_text)
#     if has_invisible:
#         width_fn = _visible_width
#     else:
#         width_fn = len
# 
#     # format rows and columns, convert numeric values to strings
#     cols = list(zip(*list_of_lists))
# 
#     coltypes = list(map(_column_type, cols))
#     cols = [[_format(v, ct, floatfmt, missingval) for v in c]
#             for c, ct in zip(cols, coltypes)]
# 
#     # align columns
#     if not aligns:
#         # dynamic alignment by col type
#         aligns = ["decimal" if ct in [int, float] else "left"
#                   for ct in coltypes]
# 
#     minwidths = [width_fn(h) + 2 for h in headers] if headers \
#         else [0] * len(cols)
#     cols = [_align_column(c, a, minw, has_invisible)
#             for c, a, minw in zip(cols, aligns, minwidths)]
# 
#     if headers:
#         # align headers and add headers
#         minwidths = [max(minw, width_fn(c[0]))
#                      for minw, c in zip(minwidths, cols)]
#         headers = [_align_header(h, a, minw)
#                    for h, a, minw in zip(headers, aligns, minwidths)]
#     else:
#         minwidths = [width_fn(c[0]) for c in cols]
#     rows = list(zip(*cols))
# 
#     if not isinstance(tablefmt, TableFormat):
#         tablefmt = _table_formats.get(tablefmt, _table_formats["orgmode"])
# 
#     # make sure values don't have newlines or tabs in them, except for tsv output_format where
#     # we have to add spaces in order to simulate tab separators
#     rows = [[str(c).replace('\n', '').replace('\t', ' ' if is_tsv else '').replace('\r', '')
#             for c in r] for r in rows]
# 
#     return _format_table(tablefmt, headers, rows, minwidths, aligns)
# 
# Path: solvebio/utils/printing.py
# def set_from_env(name, default_value):
# def pretty_int(num):
# def green(text):
# def red(text):
# def yellow(text):
# def blue(text):
# def pager(fn, **kwargs):
#         def getchar():
#         def getchar():
# TTY_ROWS = set_from_env('LINES', 24)
# TTY_COLS = set_from_env('COLUMNS', 80)
# TTY_COLORS = True
#             TTY_ROWS = int(rows)
#             TTY_COLS = int(cols)
#     TTY_COLORS = False


import unittest
from solvebio.utils import tabulate as t
from solvebio.utils import printing as p
        self.assertEqual(t._type('\x1b[31m42\x1b[0m'), t._int_type)

    def test_align(self):
        self.assertEqual(t._afterpoint('123.45'), 2)
        self.assertEqual(t._afterpoint('1001'), -1)

        self.assertEqual(t._afterpoint('eggs'), -1)
        self.assertEqual(t._afterpoint('123e45'), 2)

        self.assertEqual(t._padleft(6, 'abcd'), '  abcd')
        self.assertEqual(t._padright(6, "abcd"), "abcd  ")

        self.assertEqual(t._padboth(6, "abcd"), " abcd ")

        self.assertEqual(t._padboth(7, "abcd"), " abcd  ")

        self.assertEqual(t._padright(2, 'abc'), 'abc')
        self.assertEqual(t._padleft(2, 'abc'), 'abc')
        self.assertEqual(t._padboth(2, 'abc'), 'abc')

        self.assertEqual(
            t._align_column(
                ["12.345", "-1234.5", "1.23", "1234.5",
                 "1e+234", "1.0e234"], "decimal"),
                ['   12.345  ', '-1234.5    ', '    1.23   ',
                 ' 1234.5    ', '    1e+234 ', '    1.0e234'])

    def test_column_type(self):
        self.assertEqual(t._column_type(["1", "2"]), t._int_type)
        self.assertEqual(t._column_type(["1", "2.3"]), t._float_type)

# Path: solvebio/utils/tabulate.py
# def tabulate(tabular_data, headers=[], tablefmt="orgmode",
#              floatfmt="g", aligns=[], missingval="", sort=True, is_tsv=False):
#     list_of_lists, headers = _normalize_tabular_data(tabular_data, headers,
#                                                      sort=sort)
# 
#     # optimization: look for ANSI control codes once,
#     # enable smart width functions only if a control code is found
#     plain_text = '\n'.join(
#         ['\t'.join(map(_text_type, headers))] +
#         ['\t'.join(map(_text_type, row)) for row in list_of_lists])
# 
#     has_invisible = re.search(_invisible_codes, plain_text)
#     if has_invisible:
#         width_fn = _visible_width
#     else:
#         width_fn = len
# 
#     # format rows and columns, convert numeric values to strings
#     cols = list(zip(*list_of_lists))
# 
#     coltypes = list(map(_column_type, cols))
#     cols = [[_format(v, ct, floatfmt, missingval) for v in c]
#             for c, ct in zip(cols, coltypes)]
# 
#     # align columns
#     if not aligns:
#         # dynamic alignment by col type
#         aligns = ["decimal" if ct in [int, float] else "left"
#                   for ct in coltypes]
# 
#     minwidths = [width_fn(h) + 2 for h in headers] if headers \
#         else [0] * len(cols)
#     cols = [_align_column(c, a, minw, has_invisible)
#             for c, a, minw in zip(cols, aligns, minwidths)]
# 
#     if headers:
#         # align headers and add headers
#         minwidths = [max(minw, width_fn(c[0]))
#                      for minw, c in zip(minwidths, cols)]
#         headers = [_align_header(h, a, minw)
#                    for h, a, minw in zip(headers, aligns, minwidths)]
#     else:
#         minwidths = [width_fn(c[0]) for c in cols]
#     rows = list(zip(*cols))
# 
#     if not isinstance(tablefmt, TableFormat):
#         tablefmt = _table_formats.get(tablefmt, _table_formats["orgmode"])
# 
#     # make sure values don't have newlines or tabs in them, except for tsv output_format where
#     # we have to add spaces in order to simulate tab separators
#     rows = [[str(c).replace('\n', '').replace('\t', ' ' if is_tsv else '').replace('\r', '')
#             for c in r] for r in rows]
# 
#     return _format_table(tablefmt, headers, rows, minwidths, aligns)
# 
# Path: solvebio/utils/printing.py
# def set_from_env(name, default_value):
# def pretty_int(num):
# def green(text):
# def red(text):
# def yellow(text):
# def blue(text):
# def pager(fn, **kwargs):
#         def getchar():
#         def getchar():
# TTY_ROWS = set_from_env('LINES', 24)
# TTY_COLS = set_from_env('COLUMNS', 80)
# TTY_COLORS = True
#             TTY_ROWS = int(rows)
#             TTY_COLS = int(cols)
#     TTY_COLORS = False


# Path: solvebio/test/test_tabulate.py
import unittest
from solvebio.utils import tabulate as t
from solvebio.utils import printing as p

        self.assertEqual(t._type('\x1b[31m42\x1b[0m'), t._int_type)

    def test_align(self):
        self.assertEqual(t._afterpoint('123.45'), 2)
        self.assertEqual(t._afterpoint('1001'), -1)

        self.assertEqual(t._afterpoint('eggs'), -1)
        self.assertEqual(t._afterpoint('123e45'), 2)

        self.assertEqual(t._padleft(6, 'abcd'), '  abcd')
        self.assertEqual(t._padright(6, "abcd"), "abcd  ")

        self.assertEqual(t._padboth(6, "abcd"), " abcd ")

        self.assertEqual(t._padboth(7, "abcd"), " abcd  ")

        self.assertEqual(t._padright(2, 'abc'), 'abc')
        self.assertEqual(t._padleft(2, 'abc'), 'abc')
        self.assertEqual(t._padboth(2, 'abc'), 'abc')

        self.assertEqual(
            t._align_column(
                ["12.345", "-1234.5", "1.23", "1234.5",
                 "1e+234", "1.0e234"], "decimal"),
                ['   12.345  ', '-1234.5    ', '    1.23   ',
                 ' 1234.5    ', '    1e+234 ', '    1.0e234'])

    def test_column_type(self):
        self.assertEqual(t._column_type(["1", "2"]), t._int_type)
        self.assertEqual(t._column_type(["1", "2.3"]), t._float_type)

        self.assertEqual(t._column_type(["1", "2.3", "four"]), t._text_type)