def test_entryToLatex(self): # No color, no 'for', no note, no modifier: desc = "descriptionstring & **formatted**" ent = cue.Entry(cue.Instruction.RIGHT, desc, 0.0, note="", modifier=cue.Modifier.NONE, for_distance=None) expected = r' \textbf{R} & 0.0 & descriptionstring \& \textbf{formatted} & \\ \hline' self.assertEqual(expected, latex._entryToLatex(ent)) # color, 'for', note, and modifier: desc = "descriptionstring & **formatted**" ent = cue.Entry(cue.Instruction.LEFT, desc, 0.0, note="*formatted note*", modifier=cue.Modifier.QUICK, for_distance=12.34, color=cue.Color.GRAY) expected = r'\rowcolor[gray]{0.7} \textbf{QL} & 0.0 & descriptionstring \& \textbf{formatted} \newline \textbf{Note:} \emph{formatted note} & 12.3 \\ \hline' self.assertEqual(expected, latex._entryToLatex(ent)) # Custom description desc = "descriptionstring" ent = cue.Entry("Custom Instruction", desc, 0.0, for_distance=12.34) expected = r' \textbf{Custom Instruction} & 0.0 & descriptionstring & 12.3 \\ \hline' self.assertEqual(expected, latex._entryToLatex(ent))
def _RWGPS_EntryToCueEntry(rwgps_entry): ''' Converts a RWGPS_Entry into a cue.CueEntry. ''' # We figure out the color from the RWGPS-provided instruction: instruction = _instructionStrToCueInstruction(rwgps_entry.instruction_str) modifier = _getModifierFromRWGPSEntry(rwgps_entry) color = cue.ColorFromInstruction(instruction) # Once that's done, overwrite the instruction with the user-provided custom one: custom_instruction = _parseCustomInstruction(rwgps_entry.description_str) if custom_instruction: instruction = custom_instruction modifier = cue.Modifier.NONE clean_desc = _cleanDescription(rwgps_entry.description_str) for_distance = None if rwgps_entry.next_absolute_distance: for_distance = rwgps_entry.next_absolute_distance - rwgps_entry.absolute_distance if rwgps_entry.note_str is None: rwgps_entry.note_str = "" return cue.Entry(instruction, clean_desc, rwgps_entry.absolute_distance, rwgps_entry.note_str, modifier, for_distance, color)
def test_entryColor(self): # Just verify entries get the right colors: nocolor_ent = cue.Entry(cue.Instruction.NONE, "", 0.0, color=cue.Color.NONE) graycolor_ent = cue.Entry(cue.Instruction.NONE, "", 0.0, color=cue.Color.GRAY) yellowcolor_ent = cue.Entry(cue.Instruction.NONE, "", 0.0, color=cue.Color.YELLOW) self.assertEqual(ur'{yellow}', latex._entryColor(yellowcolor_ent)) self.assertEqual(ur'[gray]{0.7}', latex._entryColor(graycolor_ent)) self.assertEqual(None, latex._entryColor(nocolor_ent))
def test_instructionToLatex_renders(self): # Verify all instructions render correctly: ents = [] for i in cue.Instruction.__dict__: if '__' in i: continue instruction = cue.Instruction.__dict__[i] ents.append(cue.Entry(instruction, r"Description", 0.0)) r = cue.Route(ents, route_id=123, length_mi=0.0) latex_code = latex.makeLatex(r) pdf_data = tex.latex2pdf(latex_code)
def test_latexRenderTest(self): ''' Create a few very pathological cue entries, verify the latex rendering doesn't choke: ''' ents = [ cue.Entry(cue.Instruction.LEFT, r"Are we escaping everything # & $ | < > % \\ {} ???", 0.0), cue.Entry( cue.Instruction.LEFT, r"What **about *formatting***? **Does **it** work, too?**", 0.1) ] r = cue.Route(ents, route_id=123, route_name=r"\terrible &oute Name \\ %%%", elevation_gain_ft=123.45, length_mi=123.456) latex_code = latex.makeLatex(r) pdf_data = tex.latex2pdf(latex_code)
def _QuickRender(instruction=cue.Instruction.NONE, modifier=cue.Modifier.NONE, description="", note="", abs_dist=0.0, for_dist=0.0, color=cue.Color.NONE): ''' Renders a single instruction to PDF. ''' ent = [ cue.Entry(instruction, description, abs_dist, note, modifier, for_dist, color) ] r = cue.Route(ent, route_id=123, length_mi=0.0) latex_code = latex.makeLatex(r) pdf = tex.latex2pdf(latex_code)
def MakeRoute(): entries = [ cue.Entry(cue.Instruction.RIGHT, "Start of route", 0.0, for_distance=1.0), cue.Entry(cue.Instruction.RIGHT, "Entry 1", 1.0, for_distance=0.5), cue.Entry(cue.Instruction.RIGHT, "Entry 2", 1.5, for_distance=2.5), cue.Entry(cue.Instruction.RIGHT, "Entry 3", 4.0, for_distance=1.0), cue.Entry(cue.Instruction.RIGHT, "Entry 4", 5.0, for_distance=3.0), cue.Entry(cue.Instruction.RIGHT, "End of route", 8.0) ] return cue.Route(entries, 8.0, 12345, "Test Route", 1000)