@@ -442,6 +442,44 @@ def test_has_any_false(self):
442442 states = States (RAW_STATES )
443443 assert not states .has_any (["nonexistent" , "also_nonexistent" ])
444444
445+ def test_getitem_raises_keyerror_on_missing (self ):
446+ """Subscript access raises KeyError for missing states."""
447+ states = States (RAW_STATES )
448+ with pytest .raises (KeyError , match = "nonexistent" ):
449+ states ["nonexistent" ]
450+
451+ def test_getitem_returns_state_on_hit (self ):
452+ """Subscript access returns the State for a known name."""
453+ states = States (RAW_STATES )
454+ state = states [STATE ]
455+ assert state .name == STATE
456+
457+ def test_contains_existing (self ):
458+ """'in' operator returns True for existing state names."""
459+ states = States (RAW_STATES )
460+ assert STATE in states
461+
462+ def test_contains_missing (self ):
463+ """'in' operator returns False for missing state names."""
464+ states = States (RAW_STATES )
465+ assert "nonexistent" not in states
466+
467+ def test_setitem_replaces_existing (self ):
468+ """Setting an existing state replaces it."""
469+ states = States (RAW_STATES )
470+ new_state = State (name = STATE , type = DataType .INTEGER , value = 42 )
471+ states [STATE ] = new_state
472+ assert states .get (STATE ).value == 42
473+
474+ def test_setitem_appends_new (self ):
475+ """Setting a new state appends it."""
476+ states = States (RAW_STATES )
477+ initial_len = len (states )
478+ new_state = State (name = "new:State" , type = DataType .INTEGER , value = 1 )
479+ states ["new:State" ] = new_state
480+ assert len (states ) == initial_len + 1
481+ assert states .get ("new:State" ).value == 1
482+
445483
446484class TestCommandDefinitions :
447485 """Tests for CommandDefinitions container and helper methods."""
@@ -472,6 +510,33 @@ def test_has_any_false(self):
472510 cmds = CommandDefinitions ([{"command_name" : "close" , "nparams" : 0 }])
473511 assert not cmds .has_any (["nonexistent" , "also_nonexistent" ])
474512
513+ def test_getitem_raises_keyerror_on_missing (self ):
514+ """Subscript access raises KeyError for missing commands."""
515+ cmds = CommandDefinitions ([{"command_name" : "close" , "nparams" : 0 }])
516+ with pytest .raises (KeyError , match = "nonexistent" ):
517+ cmds ["nonexistent" ]
518+
519+ def test_getitem_returns_command_on_hit (self ):
520+ """Subscript access returns the CommandDefinition for a known command."""
521+ cmds = CommandDefinitions ([{"command_name" : "close" , "nparams" : 0 }])
522+ cmd = cmds ["close" ]
523+ assert cmd .command_name == "close"
524+
525+ def test_get_returns_none_on_missing (self ):
526+ """get() returns None for missing commands."""
527+ cmds = CommandDefinitions ([{"command_name" : "close" , "nparams" : 0 }])
528+ assert cmds .get ("nonexistent" ) is None
529+
530+ def test_contains_existing (self ):
531+ """'in' operator returns True for existing command names."""
532+ cmds = CommandDefinitions ([{"command_name" : "close" , "nparams" : 0 }])
533+ assert "close" in cmds
534+
535+ def test_contains_missing (self ):
536+ """'in' operator returns False for missing command names."""
537+ cmds = CommandDefinitions ([{"command_name" : "close" , "nparams" : 0 }])
538+ assert "nonexistent" not in cmds
539+
475540
476541class TestDefinition :
477542 """Tests for Definition model and its helper methods."""
0 commit comments