# Path: snakemakelib/report/utils.py
# class Template(string.Formatter):
#     _suffix = {'-3':('n', 10**(-9)), '-2':('u', 10**(-6)), '-1':('m', 10**(-3)), '0':('', 1), '1':('k', 10**3), '2':('M', 10**6), '3':('G', 10**9), '4':('T', 10**12), '5':('P', 10**15)}
#     def format_field(self, value, spec):
#         sfx = ""
#         if spec.endswith('h'):
#             if not value == 0:
#                 spec = spec[:-1] + 'f'
#                 n = (math.floor(math.log(value,10) / 3))
#                 value = value / self._suffix[str(n)][1]
#                 sfx = self._suffix[str(n)][0]
#             else:
#                 spec = 'd'
#         return super(Template, self).format_field(value, spec) + sfx
# 
# def recast(x, strpfmt="%b %d %H:%M:%S"):
#     x = x.rstrip().lstrip()
#     if re.match('^[0-9]+$', x):
#         return int(x)
#     elif re.match('^[0-9]+[,\.][0-9]+$', x):
#         return float(x.replace(",", "."))
#     elif re.search("%", x):
#         return float(x.replace(",", ".").replace("%", ""))
#     else:
#         try:
#             dateobj = datetime.strptime(x, strpfmt)
#             return dateobj
#         except:
#             return x


import unittest
import datetime
from snakemakelib.report.utils import Template, recast
        T = 12121414141232
        G = 12121414141.235
        M = 12121414
        k = 12123.23
        z = 12.25
        m = 0.01212
        u = 0.00001212
        n = 0.00000001212
        Ts = tp.format_field(T, '3.2h')
        Gs = tp.format_field(G, '3.2h')
        Ms = tp.format_field(M, '3.2h')
        ks = tp.format_field(k, '3.2h')
        zs = tp.format_field(z, '3.2h')
        ms = tp.format_field(m, '3.2h')
        us = tp.format_field(u, '3.2h')
        ns = tp.format_field(n, '3.2h')
        self.assertEqual(Ts, '12.12T')
        self.assertEqual(Gs, '12.12G')
        self.assertEqual(Ms, '12.12M')
        self.assertEqual(ks, '12.12k')
        self.assertEqual(zs, '12.25')
        self.assertEqual(ms, '12.12m')
        self.assertEqual(us, '12.12u')
        self.assertEqual(ns, '12.12n')

    def test_recast(self):
        """Test recasting string to float, int, date, or other"""
        self.assertEqual(type(recast("1234")), int)
        self.assertEqual(type(recast("123.45")), float)
        self.assertEqual(type(recast("123,45")), float)

# Path: snakemakelib/report/utils.py
# class Template(string.Formatter):
#     _suffix = {'-3':('n', 10**(-9)), '-2':('u', 10**(-6)), '-1':('m', 10**(-3)), '0':('', 1), '1':('k', 10**3), '2':('M', 10**6), '3':('G', 10**9), '4':('T', 10**12), '5':('P', 10**15)}
#     def format_field(self, value, spec):
#         sfx = ""
#         if spec.endswith('h'):
#             if not value == 0:
#                 spec = spec[:-1] + 'f'
#                 n = (math.floor(math.log(value,10) / 3))
#                 value = value / self._suffix[str(n)][1]
#                 sfx = self._suffix[str(n)][0]
#             else:
#                 spec = 'd'
#         return super(Template, self).format_field(value, spec) + sfx
# 
# def recast(x, strpfmt="%b %d %H:%M:%S"):
#     x = x.rstrip().lstrip()
#     if re.match('^[0-9]+$', x):
#         return int(x)
#     elif re.match('^[0-9]+[,\.][0-9]+$', x):
#         return float(x.replace(",", "."))
#     elif re.search("%", x):
#         return float(x.replace(",", ".").replace("%", ""))
#     else:
#         try:
#             dateobj = datetime.strptime(x, strpfmt)
#             return dateobj
#         except:
#             return x


# Path: snakemakelib/report/tests/test_report_utils.py
import unittest
import datetime
from snakemakelib.report.utils import Template, recast

        T = 12121414141232
        G = 12121414141.235
        M = 12121414
        k = 12123.23
        z = 12.25
        m = 0.01212
        u = 0.00001212
        n = 0.00000001212
        Ts = tp.format_field(T, '3.2h')
        Gs = tp.format_field(G, '3.2h')
        Ms = tp.format_field(M, '3.2h')
        ks = tp.format_field(k, '3.2h')
        zs = tp.format_field(z, '3.2h')
        ms = tp.format_field(m, '3.2h')
        us = tp.format_field(u, '3.2h')
        ns = tp.format_field(n, '3.2h')
        self.assertEqual(Ts, '12.12T')
        self.assertEqual(Gs, '12.12G')
        self.assertEqual(Ms, '12.12M')
        self.assertEqual(ks, '12.12k')
        self.assertEqual(zs, '12.25')
        self.assertEqual(ms, '12.12m')
        self.assertEqual(us, '12.12u')
        self.assertEqual(ns, '12.12n')

    def test_recast(self):
        """Test recasting string to float, int, date, or other"""
        self.assertEqual(type(recast("1234")), int)
        self.assertEqual(type(recast("123.45")), float)
        self.assertEqual(type(recast("123,45")), float)

        self.assertEqual(type(recast("23.45%")), float)