Scientific Computing with Python Projects - Time Calculator

Tests are not fully executed (Possible problem in test_module.py)
Hi friends, I have my add_time() function ready. It is working fine but for some reason the tests are not being carried out through the test_module.py. It does not throw any error but the tests are not carried out either, only the one that is in the main.py module. Any ideas? I don’t know whether to deliver it like this or continue investigating. Any suggestions would be welcome. Thank you.
Regarding the code, I accept all kinds of criticisms or suggestions.

def add_time(start, duration, day=None):
	days = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday']
	add_hh, add_mm = map(int, (duration.split(':')))
	tota_mm_add = add_hh*60 + add_mm

	hh,mm = map(int, start.split()[0].split(':') )
	if 'PM' in start: hh += 12

	total_mm = hh*60 + mm
	new_time_mm = total_mm + tota_mm_add
	total_days = new_time_mm//1440
	new_hh = (new_time_mm//60)%24
	meridian = ' PM' if new_hh >= 12 else ' AM'

	new_hh = str(new_hh%12)
	if new_hh == '0': 
		new_hh = '12'

	new_mm = str(new_time_mm % 60)
	if len(new_mm) == 1: 
		new_mm = '0'+new_mm

	new_time = ':'.join([new_hh, new_mm]) + meridian
	if day: new_time += ', '+ days[(days.index(day.capitalize())+total_days)%7]
	if total_days == 1: new_time += ' (next day)'
	elif total_days > 1: new_time += f' ({total_days} days later)'

	return new_time

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36

Challenge: Scientific Computing with Python Projects - Time Calculator

Link to the challenge:

The tests need to pass before you submit the project as complete.

Did you change the main.py file?

Hello Jeremy! Thanks for answering. This is the original main.py

# This entry point file to be used in development. Start by reading README.md
from time_calculator import add_time
from unit test import main
# This entrypoint file to be used in development. Start by reading README.md
from time_calculator import add_time
from unittest import main


print(add_time("11:06 PM", "2:02"))


# Run unit tests automatically
main(module='test_module', exit=False)

Apparently everything is fine there, at least it’s like in the following exercise (budget.py). The console output when main.py is run is this

1:08 AM (next day)
............
----------------------------------------------------------------------
Ran 12 tests in 0.027s

OK
>
KeyboardInterrupt
>

I should investigate what is happening inside the test_module.py. As soon as I can, I’ll see how the test_module.py are implemented in the exercises that do work correctly. Thanks!

You should not touch this file. It must be untouched.

This says all 12 tests passed

1 Like

Ohh… “I suspected it from the beginning.” I think I have been fooled by the red color of the console font. I got used to seeing that when the tests are passed they were showing in green. Sorry and thank you very much