I'm trying to test my function but for me tests act unexpected way
def time_converter(time_zone=None, date_time=None):
if not time_zone and not date_time:
return None
else:
from_dt = datetime.strptime(date_time, '%Y-%m-%dT%H:%M:%S.%f')
time_zone = pytz.timezone(time_zone)
from_dt = from_dt.astimezone(time_zone)
from_dt = from_dt.strftime('%Y-%m-%dT%H:%M:%S.%f%z')
date_time = from_dt[:23]
time_zone = from_dt[-5:]
return date_time + time_zone
Here is my tests
class TestTimeConverter(unittest.TestCase):
def test_none_datetime_timezone_converter(self):
result = time_converter()
self.assertIsNone(result)
def test_ok_datetime_timezone_converter(self):
time_zone = 'Asia/Bishkek'
test = '2018-07-26T06:00:00.001+0600'
input = '2018-07-26T06:00:00.001'
result = time_converter(time_zone, input)
self.assertEqual(result, test)
if i run tests on my local machine everthing is ok but when i push my code on the gitlab thiss issue apeare
def test_ok_datetime_timezone_converter(self):
time_zone = 'Asia/Bishkek'
test = '2018-07-26T06:00:00.001+0600'
input = '2018-07-26T06:00:00.001'
result = time_converter(time_zone, input)
self.assertEqual(result, test)
E AssertionError: '2018-07-26T12:00:00.001+0600' != '2018-07-26T06:00:00.001+0600' E - 2018-07-26T12:00:00.001+0600 E ? ^^ E + 2018-07-26T06:00:00.001+0600 E ? ^^
tests/test_time_converter.py:16: AssertionError
====================== 1 failed, 1 passed in 0.07 seconds ======================
ERROR: Job failed: exit code 1
I tried to mock this class to return needed value but E TypeError: can't set attributes of built-in/extension type 'datetime.datetime'
Aucun commentaire:
Enregistrer un commentaire