def test_get_process_raise(): class NotAProcess: pass with pytest.raises(NotAProcessClassError) as excinfo: get_process_cls(NotAProcess) assert "is not a process-decorated class" in str(excinfo.value) with pytest.raises(NotAProcessClassError) as excinfo: get_process_obj(NotAProcess) assert "is not a process-decorated class" in str(excinfo.value)
def test_process_repr( example_process_obj, processes_with_state, example_process_repr, example_process_in_model_repr, ): assert repr_process(example_process_obj) == example_process_repr _, _, process_in_model = processes_with_state assert repr_process(process_in_model) == example_process_in_model_repr @xs.process class Dummy: def initialize(self): pass def run_step(self): pass expected = dedent("""\ <Dummy (xsimlab process)> Variables: *empty* Simulation stages: initialize run_step """) assert repr_process(get_process_obj(Dummy)) == expected
def _init_process(p_cls, p_name, model, state, state_keys=None, od_keys=None): p_obj = get_process_obj(p_cls) p_obj.__xsimlab_name__ = p_name p_obj.__xsimlab_model__ = model p_obj.__xsimlab_state__ = state p_obj.__xsimlab_state_keys__ = state_keys or {} p_obj.__xsimlab_od_keys__ = od_keys or {} return p_obj
def example_process_obj(): return get_process_obj(ExampleProcess)
def test_get_process_obj(example_process_obj): p_cls = get_process_cls(ExampleProcess) assert type(get_process_obj(ExampleProcess)) is p_cls # get_process_obj returns a new instance assert get_process_obj(example_process_obj) is not example_process_obj