Пример #1
0
 def test_2(self):
     field = "Mo,Th 09:00-12:00,13:00-19:00"
     hoh = humanized_opening_hours.HumanizedOpeningHours(field)
     # Is open?
     dt = datetime.datetime(2016, 2, 1, 15, 30, tzinfo=pytz.timezone("UTC"))
     self.assertTrue(hoh.is_open(dt))
     dt = datetime.datetime(2016, 2, 1, 19, 30, tzinfo=pytz.timezone("UTC"))
     self.assertFalse(hoh.is_open(dt))
     dt = datetime.datetime(2016, 2, 1, 12, 10, tzinfo=pytz.timezone("UTC"))
     self.assertFalse(hoh.is_open(dt))
     # Periods per day.
     self.assertEqual(len(hoh._opening_periods[0].periods), 2)
     self.assertEqual(len(hoh._opening_periods[1].periods), 0)
     self.assertEqual(len(hoh._opening_periods[3].periods), 2)
     # Next change.
     self.assertEqual(
         hoh.next_change(dt),
         datetime.datetime(2016, 2, 1, 13, 0, tzinfo=pytz.timezone("UTC"))
     )
     # Time before next change.
     self.assertEqual(
         hoh.time_before_next_change(dt),
         datetime.timedelta(minutes=50)
     )
     # Rendering.
     hohr = humanized_opening_hours.HOHRenderer(hoh)
     self.assertEqual(
         hohr.render_moment(hoh[0].periods[0].m2),
         "12:00"
     )
     self.assertEqual(
         hohr.render_period(hoh[0].periods[0]),
         "09:00 - 12:00"
     )
Пример #2
0
 def test_3(self):
     field = "Mo-Sa 09:00-19:00 ; Su 09:00-12:00"
     hoh = humanized_opening_hours.HumanizedOpeningHours(field)
     # Is open?
     dt = datetime.datetime(2017, 1, 2, 15, 30, tzinfo=pytz.timezone("UTC"))
     self.assertTrue(hoh.is_open(dt))
     # Periods per day.
     self.assertEqual(len(hoh._opening_periods[0].periods), 1)
     self.assertEqual(len(hoh._opening_periods[1].periods), 1)
     self.assertEqual(len(hoh._opening_periods[6].periods), 1)
     # Next change.
     self.assertEqual(
         hoh.next_change(dt),
         datetime.datetime(2017, 1, 2, 19, 0, tzinfo=pytz.timezone("UTC"))
     )
     # Time before next change.
     dt = datetime.datetime(2017, 1, 8, 15, 30, tzinfo=pytz.timezone("UTC"))
     self.assertEqual(
         hoh.time_before_next_change(dt),
         datetime.timedelta(days=1, hours=3, minutes=30)
     )
     # Rendering.
     hohr = humanized_opening_hours.HOHRenderer(hoh)
     self.assertEqual(
         hohr.render_moment(hoh[6].periods[0].m1),
         "09:00"
     )
     self.assertEqual(
         hohr.render_period(hoh[6].periods[0]),
         "09:00 - 12:00"
     )
Пример #3
0
 def test_holidays(self):
     field = "Mo-We 09:00-19:00 ; SH off ; PH 09:00-12:00"
     hoh = humanized_opening_hours.HumanizedOpeningHours(field)
     hohr = humanized_opening_hours.HOHRenderer(hoh)
     self.assertEqual(
         hohr.holidays(),
         {
             "main": "Open on public holidays. Closed on school holidays.",
             "PH": (True, ["09:00 - 12:00"]),
             "SH": (False, []),
         }
     )
     return
Пример #4
0
 def test_periods_per_day_solar_universal(self):
     field = "Mo-We sunrise-19:00"
     hoh = humanized_opening_hours.HumanizedOpeningHours(field)
     hohr = humanized_opening_hours.HOHRenderer(hoh)
     field_dict = {
         0: ("Monday", ["sunrise - 19:00"]),
         1: ("Tuesday", ["sunrise - 19:00"]),
         2: ("Wednesday", ["sunrise - 19:00"]),
         3: ('Thursday', []),
         4: ('Friday', []),
         5: ('Saturday', []),
         6: ('Sunday', []),
     }
     self.assertDictEqual(hohr.periods_per_day(), field_dict)
Пример #5
0
    def test_description(self):
        field = "Mo-We 09:00-19:00 ; SH off ; PH 09:00-12:00"
        description = """\
Monday: 09:00 - 19:00
Tuesday: 09:00 - 19:00
Wednesday: 09:00 - 19:00
Thursday: closed
Friday: closed
Saturday: closed
Sunday: closed

Public holidays: 09:00 - 12:00
Open on public holidays. Closed on school holidays."""
        hoh = humanized_opening_hours.HumanizedOpeningHours(field)
        hohr = humanized_opening_hours.HOHRenderer(hoh)
        self.assertEqual(
            hohr.description(),
            description
        )
        
        # With translation.
        field = "Mo,SH 09:00-19:00"
        hoh = humanized_opening_hours.HumanizedOpeningHours(field)
        hohr = humanized_opening_hours.HOHRenderer(hoh, lang="fr")
        description = """\
Lundi : 09:00 - 19:00
Mardi : fermé
Mercredi : fermé
Jeudi : fermé
Vendredi : fermé
Samedi : fermé
Dimanche : fermé

Vacances scolaires : 09:00 - 19:00
Ouvert durant les vacances scolaires."""
        self.assertEqual(
            hohr.description(),
            description
        )
        
        # Without holidays.
        field = "Mo,SH 09:00-19:00"
        hoh = humanized_opening_hours.HumanizedOpeningHours(field)
        hohr = humanized_opening_hours.HOHRenderer(hoh, lang="fr")
        description = """\
Lundi : 09:00 - 19:00
Mardi : fermé
Mercredi : fermé
Jeudi : fermé
Vendredi : fermé
Samedi : fermé
Dimanche : fermé"""
        self.assertEqual(
            hohr.description(holidays=False),
            description
        )
        
        # 24/7.
        field = "24/7"
        hoh = humanized_opening_hours.HumanizedOpeningHours(field)
        hohr = humanized_opening_hours.HOHRenderer(hoh)
        description = "Open 24 hours a day and 7 days a week."
        self.assertEqual(
            hohr.description(),
            description
        )
        return
Пример #6
0
 def test_closed_days(self):
     field = "Mo-We 09:00-19:00 ; Dec 25 off ; May 1 off"
     hoh = humanized_opening_hours.HumanizedOpeningHours(field)
     hohr = humanized_opening_hours.HOHRenderer(hoh)
     self.assertEqual(hohr.closed_days(), ["25 December", "1st May"])
     return
Пример #7
0
 def test_periods_per_day_solar_not_universal(self):
     field = "Mo-We sunrise-19:00"
     hoh = humanized_opening_hours.HumanizedOpeningHours(field)
     with self.assertRaises(humanized_opening_hours.NotParsedError) as context:
         hohr = humanized_opening_hours.HOHRenderer(hoh, universal=False)