state pattern def switch_state(self)self state_machine state self state_machine state class statemachine(object)def __init__(self)self state concretestate (selfself state concretestate (selfself state self state def switch(self)self state switch_state(def __str__(self)return str(self statedef main()state_machine statemachine(print(state_machinestate_machine switch(print(state_machineif __name__ ="__main__"main(from the resultyou can see where the switch happens from concretestate to concretestate the statemachine class represents the context of execution and provides single interface to the outside world as you progress down the path to becoming better programmeryou will find yourself spending more and more time thinking about how you can test certain code constructs state machines are no different sowhat can we test about state machine that the state machine initializes correctly that the action method for each concrete state class does what it should dolike return the correct value