def finish(): assert len(counts) == len(styles) from mwlib.parser import styleanalyzer states = styleanalyzer.compute_path(counts) last_apocount = 0 for i, s in enumerate(states): apos = "'" * (s.apocount - last_apocount) if apos: styles[i].children.insert(0, T(type=T.t_text, text=apos)) last_apocount = s.apocount if s.is_bold and s.is_italic: styles[i].caption = "'''" inner = T(type=T.t_complex_style, caption="''", children=styles[i].children) styles[i].children = [inner] elif s.is_bold: styles[i].caption = "'''" elif s.is_italic: styles[i].caption = "''" else: styles[i].type = T.t_complex_node
def test_many_styles(): signal.alarm(2) #, signal.siginterrupt) signal.signal(signal.SIGALRM, signal.default_int_handler) counts = [2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2] try: states = styleanalyzer.compute_path(counts) except KeyboardInterrupt: states = None finally: signal.alarm(0) if states is None: raise RuntimeError("styleanaluzer.compute_path took more then 2 seconds to finish")
def test_many_styles(): signal.alarm(2) # , signal.siginterrupt) signal.signal(signal.SIGALRM, signal.default_int_handler) counts = [ 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2 ] try: states = styleanalyzer.compute_path(counts) except KeyboardInterrupt: states = None finally: signal.alarm(0) if states is None: raise RuntimeError( "styleanaluzer.compute_path took more then 2 seconds to finish")