lpschedule-generator

libreplanet schedule generator - ricketyspace.net/lpschedule-generator
git clone git://git.ricketyspace.net/lpschedule-generator.git
Log | Files | Refs

commit 7f6af7acf2bdeb216ed6db847d98eeaf13326010
parent d17f9e74e4d409fb9f07cfd38c956d6b9af7f43c
Author: rsiddharth <rsd@gnu.org>
Date:   Tue, 15 Mar 2016 23:31:16 -0400

Add LPiCal class

Contains two methods at the moment:

   - get_timeslot
   - get_month_day

Addresses issue #8.

Diffstat:
lps_gen.py | 39+++++++++++++++++++++++++++++++++++++++
tests/test_lps_gen.py | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 100 insertions(+), 0 deletions(-)

diff --git a/lps_gen.py b/lps_gen.py @@ -19,6 +19,7 @@ # <http://www.gnu.org/licenses/>. import json +import re import sys from argparse import ArgumentParser @@ -102,6 +103,44 @@ def json_read(filename): object_pairs_hook=OrderedDict) +class LPiCal(object): + """ + Used for producing iCal for LP schedule. + """ + + def __init__(self, lps_dict): + self.lps_dict = lps_dict + + # Matches strings like '09:45 - 10:30: Lorem ipsum dolor sit.' + self.timeslot_re = re.compile(r'(\d+:\d+).+?(\d+:\d+)') + # Matches strings like 'Saturday, March 19' + self.month_day_re = re.compile(r'\w+,\s*([a-zA-Z]+)\s*(\d+)') + + + def get_timeslot(self, s): + """Get start and end time for a timeslot. + """ + + timeslot = self.timeslot_re.search(s) + + start = timeslot.group(1) + end = timeslot.group(2) + + return start, end + + + def get_month_day(self, s): + """Get month and day. + """ + + month_day = self.month_day_re.search(s) + + month = month_day.group(1) + day = month_day.group(2) + + return month, day + + class LPSRenderer(Renderer): """Helps in converting Markdown version of LP schedule to a dictionary. """ diff --git a/tests/test_lps_gen.py b/tests/test_lps_gen.py @@ -110,6 +110,67 @@ class TestJSONUtils(object): os.chdir(self.old_cwd) +class TestLPiCal(object): + """ + Testing LPiCal class. + """ + + @classmethod + def setup_class(self): + """Setting up things for Testing LPiCal class. + """ + self.lp_ical = LPiCal({}) + + + def test_get_timeslot(self): + """ + Testing LPiCal.get_timeslot. + """ + + timeslots = { + '09:00-09:45: Registration and Breakfast': ['09:00', '09:45'], + ' 09:45 - 10:45: Opening Keynote': ['09:45', '10:45'], + '10:5 - 10:55: Break': ['10:5', '10:55'], + ' 10:55 - 11:40: Session Block 1A': ['10:55', '11:40'], + ' 11:40 - 11:50: Break': ['11:40', '11:50'], + '9:45 - 10:30: Keynote ': ['9:45', '10:30'], + '16:55 - 17:40:Session Block 6B': ['16:55', '17:40'], + '17:50 - 18:35: Closing keynote': ['17:50', '18:35'], + } + + for string, timeslot in timeslots.iteritems(): + start, end = self.lp_ical.get_timeslot(string) + assert_equal(start, timeslot[0]) + assert_equal(end, timeslot[1]) + + + def test_get_month_day(self): + """Testing LPiCal.get_month_day. + """ + + month_days = { + 'Sunday, March 20': ['March', '20'], + 'Saturday, March 19': ['March', '19'], + 'Monday,March 20 ': ['March', '20'], + 'Tuesday,March21': ['March', '21'], + ' Wednesday, March 22': ['March', '22'], + 'Thursday, March 23 ': ['March', '23'], + } + + for string, month_day in month_days.iteritems(): + month, day = self.lp_ical.get_month_day(string) + assert_equal(month, month_day[0]) + assert_equal(day, month_day[1]) + + + @classmethod + def teardown_class(self): + """ + Tearing down the mess created by Testing LPiCal class. + """ + pass + + class TestLPS(object): """ Class that tests everything related LP Schedule.