blob: 0e2bdcd0e0884cb7bfba6b1f036afca773ad5af6 [file] [log] [blame]
Tommy Carpenterf9cd5cc2020-03-09 13:46:37 -04001# ==================================================================================
2# Copyright (c) 2020 Nokia
3# Copyright (c) 2020 AT&T Intellectual Property.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16# ==================================================================================
17import time
18import pytest
Tommy Carpenter3a6ac012020-04-06 14:42:57 -040019from ricxappframe.rmr.exceptions import InitFailed
Tommy Carpenterf9cd5cc2020-03-09 13:46:37 -040020from ricxappframe.xapp_frame import Xapp, RMRXapp
21
22
23def test_bad_init():
24 """test that an xapp whose rmr fails to init blows up"""
25
26 def entry(self):
27 pass
28
29 with pytest.raises(InitFailed):
30 bad_xapp = Xapp(entrypoint=entry, rmr_port=-1)
31 bad_xapp.run() # we wont get here
32
33 def defh(self):
34 pass
35
36 with pytest.raises(InitFailed):
37 bad_xapp = RMRXapp(default_handler=defh, rmr_port=-1)
38 bad_xapp.run() # we wont get here
39
40
41def test_init_general_xapp():
42 def entry(self):
43 # normally we would have some kind of loop here
44 print("bye")
45
46 gen_xapp = Xapp(entrypoint=entry, rmr_wait_for_ready=False, use_fake_sdl=True)
47 gen_xapp.run()
48 time.sleep(1)
49 gen_xapp.stop() # pytest will never return without this.
50
51
52def test_init_rmr_xapp():
53 def post_init(self):
54 print("hey")
55
56 def foo(self, _summary, _sbuf):
57 pass
58
59 rmr_xapp = RMRXapp(foo, post_init=post_init, rmr_wait_for_ready=False, use_fake_sdl=True)
Tommy Carpenter1c9ce6b2020-03-13 09:36:36 -040060 # pytest will never return without thread and stop
61 rmr_xapp.run(thread=True)
Tommy Carpenterf9cd5cc2020-03-09 13:46:37 -040062 time.sleep(1)
Tommy Carpenter1c9ce6b2020-03-13 09:36:36 -040063 rmr_xapp.stop()