import os, sys sys.path.insert(0,os.path.dirname(os.path.dirname(os.path.abspath( __file__ )))) import opening_hours import datetime, logging debug=True if debug: logging.basicConfig(level=logging.DEBUG) else: logging.basicConfig(level=logging.INFO) exceptional_closures=["22/09/2017", "20/09/2017-22/09/2017", "20/09/2017-22/09/2017 18/09/2017","25/11/2017", "26/11/2017 9h30-12h30"] print "Raw exceptional closures value : %s" % exceptional_closures print "Parsed exceptional closures : %s" % opening_hours.parse_exceptional_closures(exceptional_closures) normal_opening_hours=["lundi-mardi jeudi 9h30-12h30 14h-16h30", "mercredi vendredi 9h30-12h30 14h-17h"] print "Raw normal opening hours : %s" % normal_opening_hours print "Parsed normal opening hours : %s" % opening_hours.parse_normal_opening_hours(normal_opening_hours) nonworking_public_holidays=[ '1janvier', 'paques', 'lundi_paques', '1mai', '8mai', 'jeudi_ascension', 'lundi_pentecote', '14juillet', '15aout', '1novembre', '11novembre', 'noel', ] print "Raw nonworking_public_holidays values : %s" % nonworking_public_holidays print "Is closed (now) : %s" % opening_hours.is_closed(normal_opening_hours,exceptional_closures,nonworking_public_holidays) tests=[ { 'date_time': datetime.datetime(2017, 5, 1, 20, 15), 'result': {'exceptional_closure': False, 'closed': True, 'exceptional_closure_all_day': False} }, { 'date_time': datetime.datetime(2017, 5, 2, 15, 15), 'result': {'exceptional_closure': False, 'closed': False, 'exceptional_closure_all_day': False} }, { 'date_time': datetime.datetime(2017, 12, 25, 20, 15), 'result': {'exceptional_closure': False, 'closed': True, 'exceptional_closure_all_day': False} }, { 'date_time': datetime.datetime(2017, 9, 22, 15, 15), 'result': {'exceptional_closure': True, 'closed': True, 'exceptional_closure_all_day': True} }, { 'date_time': datetime.datetime(2017, 11, 25, 15, 15), 'result': {'exceptional_closure': True, 'closed': True, 'exceptional_closure_all_day': True} }, { 'date_time': datetime.datetime(2017, 11, 26, 11, 15), 'result': {'exceptional_closure': True, 'closed': True, 'exceptional_closure_all_day': False} }, ] for test in tests: result=opening_hours.is_closed(normal_opening_hours,exceptional_closures,nonworking_public_holidays, test['date_time']) if result == test['result']: status='OK' else: status='ERROR' print "Is closed (%s) : %s => %s" % (test['date_time'].isoformat(), result, status)