lpschedule-generator

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

commit 8a818223805e74f64772e06926e3ae87be141e80
parent 227a9ee87dcb4269580bc1a1c2880792e877a68d
Author: rsiddharth <rsd@gnu.org>
Date:   Sat, 13 Feb 2016 13:40:23 -0500

LPSpeakersMarkdown writes speakers.ids to disk.

The `speaker.ids` file contains a mapping of the speakers and their
corresponding ids. This file will later be used by LPSMarkdown and
LPSRenderer to auto link speakers while generating the sessions page.

Addresses issue #7

Diffstat:
lps_gen.py | 30++++++++++++++++++------------
tests/test_lps_gen.py | 26+++++++++++++++++++++++---
2 files changed, 41 insertions(+), 15 deletions(-)

diff --git a/lps_gen.py b/lps_gen.py @@ -183,29 +183,29 @@ class LPSpeakersRenderer(Renderer): # 'keynote-speakers' or 'speakers'.' self.speaker_type = None - # Maintain a list of used IDs - self.used_ids = [] + # Maintain a dict of speakers and their IDs. + self.speakers_ids = OrderedDict() def mk_uid(self, text): """Returns a unique id. """ # 'John HÖcker, Onion Project' -> 'John HÖcker' - text = text.split(', ')[0] + speaker = unicode(text.split(', ')[0]) # 'John HÖcker' -> 'John Hacker' - ascii_text = unidecode(unicode(text)) + ascii_speaker = unidecode(speaker) # 'John Hacker' -> 'hacker' - id_ = ascii_text.split()[-1].lower() + id_ = ascii_speaker.split()[-1].lower() - if id_ not in self.used_ids: - self.used_ids.append(id_) + if id_ not in self.speakers_ids.values(): + self.speakers_ids[speaker]= id_ return id_ else: # 'John Hacker' -> 'john_hacker' - id_ = '_'.join([s.lower() for s in ascii_text.split()]) - self.used_ids.append(id_) + id_ = '_'.join([s.lower() for s in ascii_speaker.split()]) + self.speakers_ids[speaker] = id_ return id_ @@ -284,15 +284,21 @@ class LPSpeakersMarkdown(Markdown): """ Initialize with LPSpeakersRenderer as the renderer. """ - super(LPSpeakersMarkdown, self).__init__(renderer=LPSpeakersRenderer(), - inline=None, block=None, - **kwargs) + self.speakers_renderer = LPSpeakersRenderer() + super(LPSpeakersMarkdown, self).__init__( + renderer=self.speakers_renderer, + inline=None, block=None, + **kwargs) def parse(self, text): global lpspeakers_dict html = super(LPSpeakersMarkdown, self).parse(text) + + # Write mapping of speakers and their ids to speakers.ids. + json_write('speakers.ids', self.speakers_renderer.speakers_ids) + return lpspeakers_dict diff --git a/tests/test_lps_gen.py b/tests/test_lps_gen.py @@ -288,10 +288,14 @@ class TestLPSpeakers(object): def setup_class(self): """Runs before running any tests in this class.""" - self.MD_FILE = path.join('tests', 'files', 'lp-speakers.md') + # Change current working directory to the tests directory. + self.old_cwd = os.getcwd() + os.chdir('tests') + + self.MD_FILE = path.join('files', 'lp-speakers.md') self.MD_FILE_CONTENT = read_file(self.MD_FILE) - self.SPEAKERS_TEMPLATE = path.join('tests', 'files', + self.SPEAKERS_TEMPLATE = path.join('files', 'lp-speakers-2016.jinja2') self.markdown = LPSpeakersMarkdown() @@ -303,6 +307,16 @@ class TestLPSpeakers(object): pass + def test_speakers_id_file_exists(self): + """ + Testing if LPSpeakersMardown created speakers.ids file. + """ + speakers_ids = self.markdown.speakers_renderer.speakers_ids + + assert path.isfile('speakers.ids') + assert_equal(json_read('speakers.ids'), speakers_ids) + + def test_LPSpeakersMarkdown_keynotespeakers_name(self): """Testing LPSpeakersMarkdown keynote speakers' names. @@ -528,4 +542,10 @@ class TestLPSpeakers(object): @classmethod def teardown_class(self): """Purge the mess created by this test.""" - pass + + # Remove `speakers.ids` file if it exists. + if path.isfile('speakers.ids'): + os.remove('speakers.ids') + + # Change back to the old cwd + os.chdir(self.old_cwd)