def test_inside_top_level_two_sections(self): c = sd.Context() foo = c.object('foo') bar = c.object('bar') baz = c.object('baz') with c.alt(): with c.choice('ok'): with foo: bar.func() with c.choice('else'): with foo: baz.func() self.check(c, [ sd_action.FragBegin('alt'), sd_action.FragBegin('choice', 'ok'), sd_action.Call(foo, bar, 'func', sd.Params()), sd_action.ImplicitReturn(), sd_action.FragEnd('choice'), sd_action.FragBegin('choice', 'else'), sd_action.Call(foo, baz, 'func', sd.Params()), sd_action.ImplicitReturn(), sd_action.FragEnd('choice'), sd_action.FragEnd('alt'), ])
def test_inside_func_call_twice(self): c = sd.Context() foo = c.object('foo') bar = c.object('bar') baz = c.object('baz') with foo: with bar.func(): with c.opt(): baz.func() with c.opt(): baz.func() self.check(c, [ sd_action.Call(foo, bar, 'func', sd.Params()), sd_action.FragBegin('opt'), sd_action.Call(bar, baz, 'func', sd.Params()), sd_action.ImplicitReturn(), sd_action.FragEnd('opt'), sd_action.FragBegin('opt'), sd_action.Call(bar, baz, 'func', sd.Params()), sd_action.ImplicitReturn(), sd_action.FragEnd('opt'), sd_action.ImplicitReturn(), ])
def test_call_other_methods_of_the_same_object_from_destructr(self): c = sd.Context() foo = c.object('foo') bar = c.object('bar') with foo: with c.destroy(bar): bar.func()
def test_fail_if_create_object_twice(self): c = sd.Context() foo = c.object('foo') bar = c.object('bar') with foo: c.create(bar) with pytest.raises(sd.CreateError): c.create(bar)
def test_fail_when_call_destroyed_object(self): c = sd.Context() foo = c.object('foo') bar = c.object('bar') with foo: c.destroy(bar) with pytest.raises(sd.CallError): bar.func()
def test_noop_when_do_nothing_in_top_level_caller(self): c = sd.Context() foo = c.object('foo') with foo: pass self.check(c, [ ])
def test_fail_if_call_in_alt(self): c = sd.Context() foo = c.object('foo') bar = c.object('bar') with pytest.raises(sd.CallError): with c.alt(): with foo: bar.func() # need to be inside choice
def test_exception_inside(self): c = sd.Context() foo = c.object('foo') with pytest.raises(ZeroDivisionError): with foo: with c.opt(): 3 / 0 # Cause exception
def test_fail_when_destroy_twice_the_same_object(self): c = sd.Context() foo = c.object('foo') bar = c.object('bar') with foo: c.destroy(bar) with pytest.raises(sd.CallError): c.destroy(bar)
def test_fail_when_separate_return_called(self): c = sd.Context() foo = c.object('foo') bar = c.object('bar') with foo: bar.func() with pytest.raises(sd.CallError): c.ret()
def test_fail_if_create_object_already_being_used(self): c = sd.Context() foo = c.object('foo') bar = c.object('bar') with foo: bar.func() with pytest.raises(sd.CreateError): c.create(bar)
def test_fail_if_other_frag_in_alt(self): c = sd.Context() foo = c.object('foo') bar = c.object('bar') with pytest.raises(sd.FragError): with c.alt(): with c.opt(): # wrong frag with foo: bar.func()
def test_fail_when_top_level_caller_set_twice(self): c = sd.Context() foo = c.object('foo') bar = c.object('bar') with foo: bar.func() with pytest.raises(sd.TopLevelCallerError): with foo: bar.func()
def test_fail_if_empty_inside(self): c = sd.Context() foo = c.object('foo') bar = c.object('bar') with foo: with bar.func(): with pytest.raises(sd.FragError): with c.opt(): pass
def test_non_default_method(self): c = sd.Context() foo = c.object('foo') bar = c.object('bar') with foo: c.create(bar.new()) self.check(c, [ sd_action.Call(foo, bar, 'new', sd.Params(), flags='c'), sd_action.ImplicitReturn(), ])
def test_fail_when_call_after_returning_from_outside_func(self): c = sd.Context() foo = c.object('foo') bar = c.object('bar') baz = c.object('baz') with foo: with bar.func(): baz.func2() c.ret() with pytest.raises(sd.CallError): baz.func3()
def test_simple(self): c = sd.Context() foo = c.object('foo') bar = c.object('bar') with foo: c.create(bar) self.check(c, [ sd_action.Call(foo, bar, '<<create>>', sd.Params(), flags='c'), sd_action.ImplicitReturn(), ])
def test_fail_after_return_from_func(self): c = sd.Context() foo = c.object('foo') bar = c.object('bar') with foo: with bar.func(): c.ret() with pytest.raises(sd.FragError): with c.opt(): pass
def test_fail_when_return_again_from_outside_func(self): c = sd.Context() foo = c.object('foo') bar = c.object('bar') baz = c.object('baz') with foo: with bar.func(): baz.func2() c.ret() with pytest.raises(sd.ReturnError): c.ret()
def test_call_with_return(self): c = sd.Context() foo = c.object('foo') bar = c.object('bar') with foo: bar.func().ret('val') self.check(c, [ sd_action.Call(foo, bar, 'func', sd.Params()), sd_action.Return(sd.Params(('val',))), ])
def test_call(self): c = sd.Context() foo = c.object('foo') bar = c.object('bar') with foo: bar.func() self.check(c, [ sd_action.Call(foo, bar, 'func', sd.Params()), sd_action.ImplicitReturn(), ])
def test_return_from_outside_func_without_calling_any(self): c = sd.Context() foo = c.object('foo') bar = c.object('bar') with foo: with bar.func(): c.ret() self.check(c, [ sd_action.Call(foo, bar, 'func', sd.Params()), sd_action.Return(sd.Params()), ])
def test_do_nothing_in_outside_func(self): c = sd.Context() foo = c.object('foo') bar = c.object('bar') with foo: with bar.func(): pass self.check(c, [ sd_action.Call(foo, bar, 'func', sd.Params()), sd_action.ImplicitReturn(), ])
def test_over_object_implicit(self): c = sd.Context() foo = c.object('foo') bar = c.object('bar') with foo: c.note('blah') bar.func() self.check(c, [ sd_action.Note('blah', obj=foo), sd_action.Call(foo, bar, 'func', sd.Params()), sd_action.ImplicitReturn(), ])
def test_constructor_params(self): c = sd.Context() foo = c.object('foo') bar = c.object('bar') with foo: c.create(bar.new('a', name='bar')) self.check(c, [ sd_action.Call(foo, bar, 'new', params=sd.Params(('a',), dict(name='bar')), flags='c'), sd_action.ImplicitReturn(), ])
def test_simple(self): c = sd.Context() foo = c.object('foo') bar = c.object('bar') with foo: bar.func() c.destroy(bar) self.check(c, [ sd_action.Call(foo, bar, 'func', sd.Params()), sd_action.ImplicitReturn(), sd_action.Call(foo, bar, '<<destroy>>', sd.Params(), flags='d'), sd_action.ImplicitReturn(), ])
def test_with_condition(self): c = sd.Context() foo = c.object('foo') bar = c.object('bar') with c.opt('condition'): with foo: bar.func() self.check(c, [ sd_action.FragBegin('opt', 'condition'), sd_action.Call(foo, bar, 'func', sd.Params()), sd_action.ImplicitReturn(), sd_action.FragEnd('opt'), ])
def test_top_level(self): c = sd.Context() foo = c.object('foo') bar = c.object('bar') with c.group(): with foo: bar.func() self.check(c, [ sd_action.FragBegin('group'), sd_action.Call(foo, bar, 'func', sd.Params()), sd_action.ImplicitReturn(), sd_action.FragEnd('group'), ])
def test_call_with_return(self): c = sd.Context() foo = c.object('foo') bar = c.object('bar') baz = c.object('baz') with foo: with bar.func(): baz.func2().ret() self.check(c, [ sd_action.Call(foo, bar, 'func', sd.Params()), sd_action.Call(bar, baz, 'func2', sd.Params()), sd_action.Return(sd.Params()), sd_action.ImplicitReturn(), ])
def test_call_others_in_constructor(self): c = sd.Context() foo = c.object('foo') bar = c.object('bar') baz = c.object('baz') with foo: with c.create(bar): baz.func() self.check(c, [ sd_action.Call(foo, bar, '<<create>>', sd.Params(), flags='c'), sd_action.Call(bar, baz, 'func', sd.Params()), sd_action.ImplicitReturn(), sd_action.ImplicitReturn(), ])