def hecho(self, formatted_text): """Send a highlights message to the console.""" message = { 'type': 'highlight', 'formatted_text': ConsoleMessage.construct(formatted_text).to_dict() } self.to_console(message)
def test_construct(): assert_raises(TypeError, ConsoleMessage.construct, None) assert_raises(TypeError, ConsoleMessage.construct, 1) assert_raises(ValueError, ConsoleMessage.construct, ()) assert_raises(ValueError, ConsoleMessage.construct, (None,)) assert_raises(ValueError, ConsoleMessage.construct, (None, None)) assert_raises(ValueError, ConsoleMessage.construct, (None, None, None)) assert_raises(ValueError, ConsoleMessage.construct, ('', '', '', '')) assert_raises(TypeError, ConsoleMessage.construct, ('', None, [1, 2, 3])) assert ConsoleMessage.construct(('span', None, ["text"])) == \ ConsoleMessage('span', {}, ["text"]) assert ConsoleMessage.construct(('span', None, "text")) == \ ConsoleMessage('span', {}, ["text"]) assert ConsoleMessage.construct(('span', {}, "text")) == \ ConsoleMessage('span', {}, ["text"]) assert ConsoleMessage.construct(('span', ["text"])) == \ ConsoleMessage('span', {}, ["text"]) assert ConsoleMessage.construct(('span', "text")) == \ ConsoleMessage('span', {}, ["text"]) assert ConsoleMessage.construct(('br', None, None)) == \ ConsoleMessage('br', {}, []) assert ConsoleMessage.construct(('br', [])) == \ ConsoleMessage('br', {}, []) assert ConsoleMessage.construct(('br',)) == \ ConsoleMessage('br', {}, []) assert ConsoleMessage.construct("foo") == "foo" assert ConsoleMessage.construct(ConsoleMessage.construct(('span', None, "foo"))) == \ ConsoleMessage('span', {}, ['foo']) assert ConsoleMessage.construct(('div', 'system', ('span', None, "foo"))) == \ ConsoleMessage('div', {'class': 'system'}, [ConsoleMessage('span', {}, ['foo'])]) assert ConsoleMessage.construct(('span', None, [u"unicode"])) == \ ConsoleMessage('span', {}, [u"unicode"]) assert ConsoleMessage.construct(u"unicode") == u"unicode" assert ConsoleMessage.construct(('a', {'href': '#foo'}, "bar")) == \ ConsoleMessage('a', {'href': '#foo'}, ["bar"]) assert ConsoleMessage.construct(('div', {'class': 'system'}, ["some ", "text"])) == \ ConsoleMessage('div', {'class': 'system'}, ["some ", "text"]) assert ConsoleMessage.construct(('div', 'system', ["some ", "text"])) == \ ConsoleMessage('div', {'class': 'system'}, ["some ", "text"]) assert ConsoleMessage.construct(('div', 'red', ["A red text ", ('span', 'green', "with some green"), " in between."])) == \ ConsoleMessage('div', {'class': 'red'}, ["A red text ", ConsoleMessage('span', {'class': 'green'}, ["with some green"]), " in between."])