import unittest
import Root
class TestRoot(unittest.TestCase):
def test_timeOperation(self):
timesAA = ['07:15','07:45','06:12','06:32','12:01','13:16']
result = Root.timeOperation(timesAA)
self.assertEqual(result, [1800,1200,4500])
if __name__ == '__main__':
unittest.main()
Результат модульного теста
def timeOperation(drivenTime2):
for x in range(0, len(drivenTime2)-1, 2):
#converts string objects in the array into time objects
time2 = datetime.datetime.strptime(drivenTime2[x], '%H:%M')
time3 = datetime.datetime.strptime(drivenTime2[x+1], '%H:%M')
#calculates time dureation and converts to seconds
durationInSeconds = (time3 - time2).total_seconds()
durationArray.append(durationInSeconds)
return durationArray
timesA = ['07:15','07:45','06:12','06:32','12:01','13:16']
print(timeOperation(timesA))
Результат оператора печати в консоли