def test_convert_to_type(self): # Test null res = convert_to_type(None, 'datetime') ok_(res is None) # Test integer res = convert_to_type(12, 'int') ok_(isinstance(res, int)) eq_(res, 12) # Test integer res = convert_to_type('12', 'int') ok_(isinstance(res, int)) eq_(res, 12) # Test string res = convert_to_type(datetime.datetime(2012, 1, 1), 'str') ok_(isinstance(res, str)) eq_(res, '2012-01-01 00:00:00') # Test boolean res = convert_to_type(1, 'bool') ok_(isinstance(res, bool)) ok_(res) # Test boolean res = convert_to_type('T', 'bool') ok_(isinstance(res, bool)) ok_(res) # Test boolean res = convert_to_type(14, 'bool') ok_(isinstance(res, bool)) ok_(not res) # Test datetime res = convert_to_type('2012-01-01T12:23:34', 'datetime') ok_(isinstance(res, datetime.datetime)) eq_(res.year, 2012) eq_(res.month, 1) eq_(res.hour, 12) # Test date res = convert_to_type('2012-01-01T00:00:00', 'date') ok_(isinstance(res, datetime.date)) eq_(res.year, 2012) eq_(res.month, 1) # Test error assert_raises(ValueError, convert_to_type, 'abds', 'int') assert_raises(ValueError, convert_to_type, '2013-02-32', 'date')
def test_convert_to_type(self): # Test null res = convert_to_type(None, 'datetime') ok_(res is None) # Test integer res = convert_to_type(12, 'int') ok_(isinstance(res, int)) eq_(res, 12) # Test integer res = convert_to_type('12', 'int') ok_(isinstance(res, int)) eq_(res, 12) # Test string res = convert_to_type(datetime.datetime(2012, 1, 1), 'str') ok_(isinstance(res, str)) eq_(res, '2012-01-01 00:00:00') # Test boolean res = convert_to_type(1, 'bool') ok_(isinstance(res, bool)) ok_(res) # Test boolean res = convert_to_type('T', 'bool') ok_(isinstance(res, bool)) ok_(res) # Test boolean res = convert_to_type(14, 'bool') ok_(isinstance(res, bool)) ok_(not res) # Test datetime res = convert_to_type('2012-01-01T12:23:34', 'datetime') ok_(isinstance(res, datetime.datetime)) eq_(res.year, 2012) eq_(res.month, 1) eq_(res.hour, 12) # Test date res = convert_to_type('2012-01-01T00:00:00', 'date') ok_(isinstance(res, datetime.date)) eq_(res.year, 2012) eq_(res.month, 1) # Test error assert_raises(ValueError, convert_to_type, 'abds', 'int') assert_raises(ValueError, convert_to_type, '2013-02-32', 'date')
def test_convert_to_type(self): # Test null res = convert_to_type(None, "datetime") ok_(res is None) # Test integer res = convert_to_type(12, "int") ok_(isinstance(res, int)) eq_(res, 12) # Test integer res = convert_to_type("12", "int") ok_(isinstance(res, int)) eq_(res, 12) # Test string res = convert_to_type(datetime.datetime(2012, 1, 1), "str") ok_(isinstance(res, str)) eq_(res, "2012-01-01 00:00:00") # Test boolean res = convert_to_type(1, "bool") ok_(isinstance(res, bool)) ok_(res) # Test boolean res = convert_to_type("T", "bool") ok_(isinstance(res, bool)) ok_(res) # Test boolean res = convert_to_type(14, "bool") ok_(isinstance(res, bool)) ok_(not res) # Test datetime res = convert_to_type("2012-01-01T12:23:34", "datetime") ok_(isinstance(res, datetime.datetime)) eq_(res.year, 2012) eq_(res.month, 1) eq_(res.hour, 12) # Test date res = convert_to_type("2012-01-01T00:00:00", "date") ok_(isinstance(res, datetime.date)) eq_(res.year, 2012) eq_(res.month, 1) # Test error assert_raises(ValueError, convert_to_type, "abds", "int") assert_raises(ValueError, convert_to_type, "2013-02-32", "date")
def test_convert_to_type(self): # Test null res = convert_to_type(None, "datetime") assert res is None # Test integer res = convert_to_type(12, "int") assert res == 12 # Test integer res = convert_to_type("12", "int") assert res == 12 # Test string res = convert_to_type(datetime.datetime(2012, 1, 1), "str") assert res == "2012-01-01 00:00:00" # Test boolean res = convert_to_type(1, "bool") assert res is True # Test boolean res = convert_to_type("T", "bool") assert res is True # Test boolean res = convert_to_type(14, "bool") assert res is False # Test datetime res = convert_to_type("2012-01-01T12:23:34", "datetime") assert isinstance(res, datetime.datetime) assert res.year == 2012 assert res.month == 1 assert res.hour == 12 # Test date res = convert_to_type("2012-01-01T00:00:00", "date") assert isinstance(res, datetime.date) assert res.year == 2012 assert res.month == 1 # Test error with pytest.raises(ValueError): convert_to_type("abds", "int") with pytest.raises(ValueError): convert_to_type("2013-02-32", "date")
def test_convert_to_type(self): # Test null res = convert_to_type(None, 'datetime') assert res is None # Test integer res = convert_to_type(12, 'int') assert res == 12 # Test integer res = convert_to_type('12', 'int') assert res == 12 # Test string res = convert_to_type(datetime.datetime(2012, 1, 1), 'str') assert res == '2012-01-01 00:00:00' # Test boolean res = convert_to_type(1, 'bool') assert res is True # Test boolean res = convert_to_type('T', 'bool') assert res is True # Test boolean res = convert_to_type(14, 'bool') assert res is False # Test datetime res = convert_to_type('2012-01-01T12:23:34', 'datetime') assert isinstance(res, datetime.datetime) assert res.year == 2012 assert res.month == 1 assert res.hour == 12 # Test date res = convert_to_type('2012-01-01T00:00:00', 'date') assert isinstance(res, datetime.date) assert res.year == 2012 assert res.month == 1 # Test error with pytest.raises(ValueError): convert_to_type('abds', 'int') with pytest.raises(ValueError): convert_to_type('2013-02-32', 'date')
def test_convert_to_type(self): # Test null res = convert_to_type(None, 'datetime') assert res is None # Test integer res = convert_to_type(12, 'int') assert res == 12 # Test integer res = convert_to_type('12', 'int') assert res == 12 # Test string res = convert_to_type(datetime.datetime(2012, 1, 1), 'str') assert res == '2012-01-01 00:00:00' # Test boolean res = convert_to_type(1, 'bool') assert res is True # Test boolean res = convert_to_type('T', 'bool') assert res is True # Test boolean res = convert_to_type(14, 'bool') assert res is False # Test datetime res = convert_to_type('2012-01-01T12:23:34', 'datetime') assert isinstance(res, datetime.datetime) assert res.year == 2012 assert res.month == 1 assert res.hour == 12 # Test date res = convert_to_type('2012-01-01T00:00:00', 'date') assert isinstance(res, datetime.date) assert res.year == 2012 assert res.month == 1 # Test error with pytest.raises(ValueError): convert_to_type('abds', 'int') with pytest.raises(ValueError): convert_to_type('2013-02-32', 'date')