class LockdownRuleset(RuleSet): WEEK_DAY_RESTRICTIONS = { week_day: {1, 2, 3, 4, 5, 6, 7, 8, 9, 0} - digits for week_day, digits in RuleSet.WEEK_DAY_RESTRICTIONS.items() } TIME_WINDOWS = ((to_time('00:00'), to_time('5:00')), (to_time('14:00'), to_time('23:59')))
class GeneralRuleset(RuleSet): TIME_WINDOWS = ((to_time('7:00'), to_time('9:30')), (to_time('16:00'), to_time('19:30')))
class ExtendedRuleset(RuleSet): TIME_WINDOWS = ((to_time('5:00'), to_time('20:00')), )
def test_to_time_with_invalid_input(time_input): with pytest.raises(ValueError, match=f"{time_input} .*") as excinfo: parser.to_time(time_input) assert 'InputValidationError' == excinfo.typename
def test_to_time_with_valid_input(time_input, expected_time): expected_hour, expected_minute = expected_time time_output = parser.to_time(time_input) assert isinstance(time_output, struct_time) assert time_output.tm_hour == expected_hour assert time_output.tm_min == expected_minute
def test_is_car_restricted(plate_input, date_input, time_input, ruleset, expected_output): assert RoadRestrictionChecker(ruleset).is_car_restricted( Plate(plate_input), to_date(date_input).isoweekday(), to_time(time_input)) == expected_output
def test_is_time_restricted(time_input, ruleset, expected_output): assert RoadRestrictionChecker(ruleset).is_time_restricted( to_time(time_input)) == expected_output
from utils import parser from models.plate import Plate from checker import RoadRestrictionChecker from config.restrictions import GeneralRuleset if __name__ == "__main__": args = parser.configure_argument_parser().parse_args() time = parser.to_time(args.time) week_day = parser.to_date(args.date).isoweekday() plate = Plate(args.plate) if RoadRestrictionChecker(GeneralRuleset).is_car_restricted( plate, week_day, time): print("You have road restriction at the moment") else: print("You don't have road restriction at the moment")