class LazySessionStateTests(unittest.TestCase): reserved_key = f"{GENERATED_WIDGET_KEY_PREFIX}-some_key" def setUp(self): self.lazy_session_state = LazySessionState() def test_iter(self, _): state_iter = iter(self.lazy_session_state) assert next(state_iter) == "foo" with pytest.raises(StopIteration): next(state_iter) def test_len(self, _): assert len(self.lazy_session_state) == 1 def test_validate_key(self, _): with pytest.raises(StreamlitAPIException) as e: self.lazy_session_state._validate_key(self.reserved_key) assert "are reserved" in str(e.value) def test_to_dict(self, _): assert self.lazy_session_state.to_dict() == {"foo": "bar"} # NOTE: We only test the error cases of {get, set, del}{item, attr} below # since the others are tested in another test class. def test_getitem_reserved_key(self, _): with pytest.raises(StreamlitAPIException): self.lazy_session_state[self.reserved_key] def test_setitem_reserved_key(self, _): with pytest.raises(StreamlitAPIException): self.lazy_session_state[self.reserved_key] = "foo" def test_delitem_reserved_key(self, _): with pytest.raises(StreamlitAPIException): del self.lazy_session_state[self.reserved_key] def test_getattr_reserved_key(self, _): with pytest.raises(StreamlitAPIException): getattr(self.lazy_session_state, self.reserved_key) def test_setattr_reserved_key(self, _): with pytest.raises(StreamlitAPIException): setattr(self.lazy_session_state, self.reserved_key, "foo") def test_delattr_reserved_key(self, _): with pytest.raises(StreamlitAPIException): delattr(self.lazy_session_state, self.reserved_key)
_arrow_table = _main._arrow_table _arrow_altair_chart = _main._arrow_altair_chart _arrow_area_chart = _main._arrow_area_chart _arrow_bar_chart = _main._arrow_bar_chart _arrow_line_chart = _main._arrow_line_chart _arrow_vega_lite_chart = _main._arrow_vega_lite_chart # Config get_option = _config.get_option from streamlit.commands.page_config import set_page_config # Session State from streamlit.state.session_state import LazySessionState session_state = LazySessionState() # Beta APIs beta_container = _main.beta_container beta_expander = _main.beta_expander beta_columns = _main.beta_columns def set_option(key, value): """Set config option. Currently, only the following config options can be set within the script itself: * client.caching * client.displayEnabled
def test_session_state(self): """Test st.write with st.session_state.""" with patch("streamlit.delta_generator.DeltaGenerator.json") as p: st.write(LazySessionState()) p.assert_called_once()
def setUp(self): self.lazy_session_state = LazySessionState()