Tommy Carpenter | f9cd5cc | 2020-03-09 13:46:37 -0400 | [diff] [blame] | 1 | # ================================================================================== |
| 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 | # ================================================================================== |
| 17 | import time |
| 18 | import pytest |
| 19 | from rmr.exceptions import InitFailed |
| 20 | from ricxappframe.xapp_frame import Xapp, RMRXapp |
| 21 | |
| 22 | |
| 23 | def 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 | |
| 41 | def 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 | |
| 52 | def 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 Carpenter | 1c9ce6b | 2020-03-13 09:36:36 -0400 | [diff] [blame^] | 60 | # pytest will never return without thread and stop |
| 61 | rmr_xapp.run(thread=True) |
Tommy Carpenter | f9cd5cc | 2020-03-09 13:46:37 -0400 | [diff] [blame] | 62 | time.sleep(1) |
Tommy Carpenter | 1c9ce6b | 2020-03-13 09:36:36 -0400 | [diff] [blame^] | 63 | rmr_xapp.stop() |