def test_task_10_subclasshook(backup_reminders_csv): test_task_4_DeadlinedReminder() DeadlinedReminder = dr.DeadlinedReminder assert '__subclasshook__' in DeadlinedReminder.__dict__,\ 'Could not find `__subclasshook__` onto `DeadlinedReminder`' # NOTE: we should not getattr, as that one is bound *to the class* and the check fails hook = DeadlinedReminder.__dict__['__subclasshook__'] assert isinstance(hook, classmethod),\ '`__subclasshook__` should be a classmethod' assert issubclass(EveningReminder, DeadlinedReminder),\ '`__subclasshook__` gives wrong result for class that'\ ' respects the protocol of `DeadlinedReminder`' assert not issubclass(DummyReminder, DeadlinedReminder),\ '`__subclasshook__` gives wrong result for class that '\ ' does not respect the protocol of `DeadlinedReminder`' # --- task_10_add_reminder_evening --------------------------------- assert hasattr(app, 'EveningReminder'),\ 'You did not import/use `EveningReminder` in `app.py`' try: database.add_reminder('test_reminder', '1/1/2020', EveningReminder) except Exception as exc: pytest.fail('Could not pass an `EveningReminder` to `add_reminder`')
def test_task_8_update_interface(backup_reminders_csv): add_reminder_params = inspect.signature(database.add_reminder).parameters assert len(add_reminder_params) >= 2,\ '`database.add_reminder()` should take two parameters' assert 'text' == list(add_reminder_params)[0],\ '`database.add_reminder() should still take the `text` as first parameter' assert 'date' == list(add_reminder_params)[1],\ '`database.add_reminder() should take the `date` as second parameter' assert add_reminder_params['date'].default is inspect.Parameter.empty,\ '`date` should not have a default value in `database.add_reminder()`' if len(add_reminder_params) > 2: return try: database.add_reminder('test_string', '1/2/2020') except Exception as ex: pytest.fail(f'Could not add reminder with text and date. Error: {ex}') else: with open('reminders.csv', 'r') as f: lines = f.readlines() reader = csv.reader(lines[-1:]) try: row = next(reader) except StopIteration: pytest.fail('database.add_reminder() had no effect') else: assert row[0] == 'test_string',\ 'database.add_reminder() did not serialize text correctly. Check your DateReminder text' assert row[1] == '2020-02-01T00:00:00',\ 'database.add_reminder() did not serialize date correctly. Check your DateReminder date'
def handle_input(): choice = input("Choice: ") if choice == "3": return False if (choice == "1"): list_reminders() elif (choice == "2"): print() reminder = input("What would you like to be reminded about?: ") date = input("When will it be due?") add_reminder(reminder, date, PoliteReminder) list_reminders() else: print("Invalid menu option") return True
def handle_input(): choice = input("Choice: ") if choice == "3": return False if choice == "1": list_reminders() elif choice == "2": print() reminder = input("What would you like to be reminded about?: ") add_reminder(reminder) list_reminders() else: print("Invalid menu option") return True
def handle_input(): choice = input("Choice: ") if choice == "3": return False if (choice == "1"): list_reminders() elif (choice == "2"): print() reminder = input("What would you like to be reminded about?: ") date = input("When is the due?: ") # if issubclass(EveningReminder, DeadlinedReminder): add_reminder(reminder, date, PoliteReminder) list_reminders() else: print("Invalid menu option") return True
def test_task_9_accept_class(backup_reminders_csv): test_task_6_is_due() test_task_7_iter() # --- correct_imports --------------------------------------------- assert not hasattr(database, 'PoliteReminder'),\ 'You should no longer import `PoliteReminder` in `database`' assert not hasattr(database, 'DateReminder'),\ 'You should no longer import `DateReminder` in `database`' assert hasattr(database, 'DeadlinedReminder'),\ 'You should import `DeadlinedReminder` in `database`' # --- add_reminder_third_parameter -------------------------------- signature = inspect.signature(database.add_reminder) params = list(signature.parameters) assert len(params) == 3,\ 'You should pass a third parameter to `add_reminder`' assert params[2] == 'ReminderClass',\ 'The third parameter should be `ReminderClass`' # --- add_reminder_date ------------------------------------------- database.add_reminder('test_reminder', '1/1/2020', dr.DateReminder) # --- add_reminder_incorrect -------------------------------------- # NOTE: pytest.raises(TypeError) does not work here as we want custom message # for the other exceptions, which would bubble up otherwise error_message = 'You should only allow conforming classes in `add_reminder`.'\ ' Did you forget `issubclass()`?' try: database.add_reminder('test_reminder', '1/1/2020', DummyReminder) pytest.fail(error_message) except TypeError as e: assert str(e) == 'Invalid Reminder Class', error_message except Exception: pytest.fail(error_message)