def test_split_date_range_string(self):
     tests = {
         'October - December 2016': convert_date_string('November 16, 2016'),
         'July - September 2016': convert_date_string('August 16, 2016'),
         'April - June 2016': convert_date_string('May 16, 2016'),
         'January March 2016': False,
     }
     for before, after in tests.items():
         if after:
             self.assertEqual(split_date_range_string(before), after)
         else:
             with self.assertRaises(Exception):
                 split_date_range_string(before)
 def test_split_date_range_string(self):
     tests = {
         "October - December 2016":
         convert_date_string("November 16, 2016"),
         "July - September 2016": convert_date_string("August 16, 2016"),
         "April - June 2016": convert_date_string("May 16, 2016"),
         "January March 2016": False,
     }
     for before, after in list(tests.items()):
         if after:
             self.assertEqual(split_date_range_string(before), after)
         else:
             with self.assertRaises(Exception):
                 split_date_range_string(before)
Beispiel #3
0
 def _get_case_dates(self):
     dates = []
     for element in self.html.xpath(self.date_string_path):
         # Determine the number of opinions below the
         # date and add them all to the date list.
         count = len(element.xpath(self.sub_opinion_path))
         # Handle different date formats
         date_string = element.text_content().strip()
         try:
             # Normal date
             date = convert_date_string(date_string)
         except ValueError:
             # It a date range string like 'January - March 2016'
             # return the middle date, unless its in the future
             # in which case return today's date
             middle_date = split_date_range_string(date_string)
             date = min(datetime.date.today(), middle_date)
         dates.extend([date] * count)
     return dates