def test_get_date_string(): assert ds.get_date_string() == dt.date.today().strftime(format='%m/%d/%Y') assert ds.get_date_string(date=dt.date(2017, 9, 9)) == dt.date( 2017, 9, 9).strftime(format='%m/%d/%Y') assert ds.get_date_string(format='MM/DD/YYYY') == dt.date.today().strftime( format='%m/%d/%Y') assert ds.get_date_string(format='DD-Mon-YY') == dt.date.today().strftime( format='%d-%b-%y') with pytest.raises(ValueError): ds.get_date_object('D/M/Y') with pytest.raises(TypeError): ds.get_date_string(3)
def test_get_date_object(): assert ds.get_date_object() == dt.date.today() assert ds.get_date_object('2017-09-09') == dt.date(2017, 9, 9) with pytest.raises(ValueError): ds.get_date_object('09/09/2017') with pytest.raises(TypeError): ds.get_date_object(3)
def test_get_date_object(): assert ds.get_date_object() == datetime.datetime.today().date() assert ds.get_date_object(date='2018-02-26') == datetime.datetime.strptime( '2018-02-26', '%Y-%m-%d').date() with pytest.raises(ValueError): ds.get_date_object(date='208-29-26') with pytest.raises(TypeError): ds.get_date_object(date=5)
def test_get_date_object_arg_badformat(date='bad date'): with pytest.raises(ValueError): ds.get_date_object('bad date')
def test_get_date_object(): dateobj2 = ds.get_date_object(date='2018-02-26') assert dateobj2 == DATEOBJ_DAY
def test_get_date(): assert ds.get_date_object() == datetime.date.today()
def test_get_date_object_format(): with pytest.raises(ValueError): ds.get_date_object('43-13-16')
def test_get_date_object_error(): with pytest.raises(ValueError): ds.get_date_object(WRONG_DATE)
def test_get_date_object(): date_obj = ds.get_date_object(DATE_STRING) assert date_obj.strftime(ds.DATE_FORMAT) == DATE_STRING
def test_get_date_object_args(): assert ds.get_date_object() == dt.date.today()
def test_get_date_object_type(x): with pytest.raises(TypeError): ds.get_date_object(date=x)
def test_get_date_object_value(x): with pytest.raises(ValueError): ds.get_date_object(date=x)
def test_get_date_object_string(x): assert ds.get_date_object(x) == dt.datetime.strptime(x, '%Y-%m-%d').date()
def test_get_date_object(): no_arg = datetime.date.today() dateobj1 = ds.get_date_object() assert no_arg == dateobj1
def test_get_date_object_arg_notstring(date=123): with pytest.raises(TypeError): ds.get_date_object(123)
def test_get_date_object_type_error(): """Assert that if date_simple.get_date_object() is called with an object that is not type str, it will raise a TypeError exception. """ with pytest.raises(TypeError): ds.get_date_object(2018)
def test_get_date_object_no_args(): """Assert that if date_simple.get_date_object() is called with no arguments, it will return a date object for today. """ assert ds.get_date_object() == dt.date.today()
def test_get_date_object_arg(): date = ds.get_date_object('2016-02-26') assert date == datetime.date(2016, 2, 26)
def test_get_date_object_none(): date_obj_res = ds.get_date_object() date_obj = dt.datetime.today().date() assert date_obj_res == date_obj
def test_get_date_object_value_error(): with pytest.raises(ValueError): ds.get_date_object('02/37/1998')
import date_simple as ds dateobj1 = ds.get_date_object() # datetime.date object for today dateobj2 = ds.get_date_object( date='2018-12-26') # datetime.date object for Feb 26, 2018 print(dateobj1, type(dateobj1)) print(dateobj2, type(dateobj2)) datestr1 = ds.get_date_string() datestr2 = ds.get_date_string(date_object=dateobj2) #datestr3 = ds.get_date_string(date_object='2018-12-26') print(datestr1, type(datestr1)) print(datestr2, type(datestr2)) # datestr = ds.get_date_string(date_object=dateobj2, format='MM/DD/YYYY') # print(datestr) # datestr = ds.get_date_string(date_object=dateobj2, format='DD-Mon-YY') # print(datestr)
def test_get_date_object_type_error(): with pytest.raises(TypeError): ds.get_date_object(datetime.date(2016, 2, 26))
def test_date_simple_format(): assert ds.get_date_object('2017-01-02') == datetime.date(2017, 1, 2)
def test_get_date_object_no_arg(): today = ds.get_date_object() assert isinstance(today, datetime.date) assert today == datetime.date.today()
def test_get_date_object_passed(): with pytest.raises(TypeError): ds.get_date_object(4)
def test_get_date_object(): """Assert that if date_simple.get_date_object() is called with a properly formatted date string, it will return a date object for that date. """ assert ds.get_date_object('2018-01-01') == dt.date(2018,1,1)
def test_get_date_object(): dateobj1 = ds.get_date_object() assert dateobj1 == DATEOBJ_TODAY
def test_get_date_object_value_error(): """Assert that if date_simple.get_date_object() is called with an improperly formatted string date, it will raise a ValueError exception. """ with pytest.raises(ValueError): ds.get_date_object('01-2018-01')
def test_get_date_object(): with pytest.raises(ValueError): dateobj2 = ds.get_date_object(date='bad date')
def test_get_date_object_arg(date='2018-02-26'): date_obj = datetime.datetime.strptime(date, '%Y-%m-%d').date() date_obj2 = ds.get_date_object(date='2018-02-26') assert date_obj == date_obj2