From 2361b9374c49c2224eb66baf37f0417db62d438e Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Sat, 19 Mar 2016 00:52:11 -0400 Subject: Update LPiCal class. - Detects when timeslot is not given and ignores that timeslot. - Detects when month, day not given and ignores that day. Addresses issue #8. --- lps_gen.py | 14 ++++++++++++++ lpschedule_generator/_version.py | 2 +- tests/test_lps_gen.py | 23 +++++++++++++++++++++-- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/lps_gen.py b/lps_gen.py index 9e09f94..d16f983 100644 --- a/lps_gen.py +++ b/lps_gen.py @@ -150,6 +150,9 @@ class LPiCal(object): timeslot = self.timeslot_re.search(s) + if (not timeslot) or (len(timeslot.groups()) < 3): + return None, None, None + t_start = timeslot.group(1) t_end = timeslot.group(2) name = timeslot.group(3) @@ -163,6 +166,9 @@ class LPiCal(object): month_day = self.month_day_re.search(s) + if (not month_day) or (len(month_day.groups()) < 2): + return None, None + month = month_day.group(1) day = month_day.group(2) @@ -251,8 +257,16 @@ class LPiCal(object): for day_str, timeslots in self.lps_dict.iteritems(): month, day = self.get_month_day(day_str) + if not month: + # month, day not specified; cannot generate ical for + # this day + continue for timeslot_str, sessions in timeslots.iteritems(): t_start, t_end, t_name = self.get_timeslot(timeslot_str) + if not t_start: + # timeslot not specified; cannot generate ical for + # this timeslot + continue for session, session_info in sessions.iteritems(): self.add_event(month, day, t_start, t_end, session, session_info) diff --git a/lpschedule_generator/_version.py b/lpschedule_generator/_version.py index f5e30c0..915c383 100644 --- a/lpschedule_generator/_version.py +++ b/lpschedule_generator/_version.py @@ -18,4 +18,4 @@ # along with lpschedule-generator (see COPYING). If not, see # . -__version__ = '0.4.0rc1' +__version__ = '0.4.0rc2' diff --git a/tests/test_lps_gen.py b/tests/test_lps_gen.py index 850d600..7a55575 100644 --- a/tests/test_lps_gen.py +++ b/tests/test_lps_gen.py @@ -130,11 +130,15 @@ class TestLPiCal(object): self.MD_FILE = path.join('files', 'lp-sch.md') self.MD_FILE_CONTENT = read_file(self.MD_FILE) + self.MD_FILE_S_ONLY = path.join('files', 'lp-sch-sessions-only.md') + self.MD_FILE_S_ONLY_CONTENT = read_file(self.MD_FILE_S_ONLY) + self.SCH_TEMPLATE = path.join('..', 'libreplanet-templates/2016', 'lp-schedule.jinja2') self.markdown = LPSMarkdown() self.lps_dict = self.markdown(self.MD_FILE_CONTENT) + self.lps_dict_s_only = self.markdown(self.MD_FILE_S_ONLY_CONTENT) self.purge_list = ['speakers.noids'] @@ -178,7 +182,13 @@ class TestLPiCal(object): ['16:55', '17:40', 'Session Block 6B'], '17:50 - 18:35: Closing keynote': ['17:50', '18:35', 'Closing keynote'], - } + '': + [None, None, None], + '\t\t\t': + [None, None, None], + ' ': + [None, None, None], + } for string, timeslot in timeslots.iteritems(): start, end, name = self.lp_ical.get_timeslot(string) @@ -198,7 +208,10 @@ class TestLPiCal(object): 'Tuesday,March21': ['March', '21'], ' Wednesday, March 22': ['March', '22'], 'Thursday, March 23 ': ['March', '23'], - } + '': [None, None], + '\t\t': [None, None], + ' ': [None, None], + } for string, month_day in month_days.iteritems(): month, day = self.lp_ical.get_month_day(string) @@ -297,6 +310,12 @@ class TestLPiCal(object): print self.lp_ical.gen_ical() + def test_gen_ical_sessions_only(self): + """Testing LPiCal.gen_ical with sessions only schedule. + """ + print LPiCal(self.lps_dict_s_only, '2016').gen_ical() + + def test_to_ical(self): """Testing LPiCal.to_ical. """ -- cgit v1.2.3