def test_enqueue_same_id(self): cursor = LockedCursor(index=123) dg = DeltaGenerator(cursor=cursor) self.assertEqual(123, dg._cursor.index) test_data = "some test data" text_proto = TextProto() text_proto.body = test_data new_dg = dg._enqueue("text", text_proto) self.assertEqual(dg._cursor, new_dg._cursor) msg = self.get_message_from_queue() self.assertEqual(123, msg.metadata.delta_id) self.assertEqual(msg.delta.new_element.text.body, test_data)
def test_enqueue(self, container): dg = DeltaGenerator(container=container) self.assertEqual(0, dg._cursor.index) self.assertEqual(container, dg._container) test_data = "some test data" text_proto = TextProto() text_proto.body = test_data new_dg = dg._enqueue("text", text_proto) self.assertNotEqual(dg, new_dg) self.assertEqual(1, dg._cursor.index) self.assertEqual(container, new_dg._container) element = self.get_delta_from_queue().new_element self.assertEqual(element.text.body, test_data)
def text(self, body): """Write fixed-width and preformatted text. Parameters ---------- body : str The string to display. Example ------- >>> st.text('This is some text.') """ text_proto = TextProto() text_proto.body = clean_text(body) return self.dg._enqueue("text", text_proto)
def text(self, body: Any) -> "DeltaGenerator": """Write fixed-width and preformatted text. Parameters ---------- body : str The string to display. Example ------- >>> st.text('This is some text.') """ text_proto = TextProto() text_proto.body = clean_text(body) dg = self.dg._enqueue("text", text_proto) return cast("DeltaGenerator", dg)
def test_enqueue_same_id(self): cursor = LockedCursor(root_container=RootContainer.MAIN, index=123) dg = DeltaGenerator(root_container=RootContainer.MAIN, cursor=cursor) self.assertEqual(123, dg._cursor.index) test_data = "some test data" text_proto = TextProto() text_proto.body = test_data new_dg = dg._enqueue("text", text_proto) self.assertEqual(dg._cursor, new_dg._cursor) msg = self.get_message_from_queue() # The last element in delta_path is the delta's index in its container. self.assertEqual(make_delta_path(RootContainer.MAIN, (), 123), msg.metadata.delta_path) self.assertEqual(msg.delta.new_element.text.body, test_data)
def text(self, body): """Write fixed-width and preformatted text. Parameters ---------- body : str The string to display. Example ------- >>> st.text('This is some text.') .. output:: https://static.streamlit.io/0.25.0-2JkNY/index.html?id=PYxU1kee5ubuhGR11NsnT1 height: 50px """ text_proto = TextProto() text_proto.body = _clean_text(body) return self.dg._enqueue("text", text_proto)