Exemplo n.º 1
0
 def test_string_2_float(self):
     value = "11.11"
     n_value = formatters.to_format(float, value)
     assert n_value == 11.11
     value = "abc"
     n_value = formatters.to_format(float, value)
     assert n_value == value
Exemplo n.º 2
0
 def test_boolean_2_string(self):
     value = True
     n_value = formatters.to_format(str, value)
     assert n_value == "true"
     value = False
     n_value = formatters.to_format(str, value)
     assert n_value == "false"
Exemplo n.º 3
0
 def test_empty_to_supported_types(self):
     value = ""
     n_value = formatters.to_format(float, value)
     assert type(n_value) == float
     assert n_value == 0
     value = ""
     n_value = formatters.to_format(int, value)
     assert type(n_value) == int
     assert n_value == 0
     value = ""
     n_value = formatters.to_format(datetime.datetime, value)
     assert n_value == ""
Exemplo n.º 4
0
 def test_date_conversion(self):
     d = datetime.datetime.now()
     new_d = formatters.to_format(datetime.datetime, d)
     assert d == new_d
     new_d = formatters.to_format(str, d)
     assert d.strftime("%d/%m/%y") == new_d
     new_d = formatters.to_format(bool, d)
     assert d == new_d
     t = datetime.time(11, 11, 11)
     new_t = formatters.to_format(datetime.datetime, t)
     assert t == new_t
     new_t = formatters.to_format(str, t)
     assert t.strftime("%H:%M:%S") == new_t
     new_t = formatters.to_format(bool, t)
     assert t == new_t
     bad = "bad"
     new_d = formatters.to_format(str, bad)
     assert bad == new_d
Exemplo n.º 5
0
 def test_int_2_date(self):
     value = 11
     n_value = formatters.to_format(datetime.datetime, value)
     assert type(n_value) == int
     assert n_value == value
Exemplo n.º 6
0
 def test_int_2_float_format(self):
     value = 11
     n_value = formatters.to_format(float, value)
     assert type(n_value) == float
     assert n_value == value
Exemplo n.º 7
0
 def test_int_2_string_format(self):
     value = 11
     n_value = formatters.to_format(str, value)
     assert n_value == "11"
Exemplo n.º 8
0
 def test_float_2_date_format(self):
     value = 1.1111
     n_value = formatters.to_format(datetime.datetime, value)
     assert type(n_value) == float
     assert n_value == value
Exemplo n.º 9
0
 def test_float_2_int_format(self):
     value = 1.1111
     n_value = formatters.to_format(int, value)
     assert type(n_value) == int
     assert n_value == 1
Exemplo n.º 10
0
 def test_float_2_string_format(self):
     value = 1.0
     n_value = formatters.to_format(str, value)
     assert n_value == "1.0"
Exemplo n.º 11
0
def _cleanse_a_row(row):
    for item in row:
        if item == constants.DEFAULT_NA:
            yield " "
        else:
            yield to_format(str, item)
Exemplo n.º 12
0
 def test_none_2_str(self):
     value = None
     n_value = formatters.to_format(str, value)
     assert n_value == ""
Exemplo n.º 13
0
 def test_date_format(self):
     d = "11-Jan-14"
     n_d = formatters.to_format(datetime.datetime, d)
     assert d == n_d
Exemplo n.º 14
0
 def test_boolean_2_float(self):
     value = True
     n_value = formatters.to_format(float, value)
     assert n_value == 1
Exemplo n.º 15
0
 def test_string_to_string(self):
     value = "string"
     n_value = formatters.to_format(str, value)
     assert n_value == value
Exemplo n.º 16
0
 def test_boolean_2_date(self):
     value = True
     n_value = formatters.to_format(datetime.datetime, value)
     assert type(n_value) == bool
     assert n_value == value
Exemplo n.º 17
0
def _cleanse_a_row(row):
    for item in row:
        if item == constants.DEFAULT_NA:
            yield " "
        else:
            yield to_format(str, item)