Remove junit option from pytest invocation
[ric-plt/xapp-frame-py.git] / tests / test_xapp.py
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 pytest
18 from rmr.exceptions import InitFailed
19 from ricxappframe.xapp_frame import Xapp
20
21 gen_xapp = None
22 rmr_xapp = None
23
24
25 def test_bad_gen_xapp():
26     """test that an xapp that does not implement entrypoint blows up"""
27
28     class MyXapp(Xapp):
29         def post_init(self):
30             pass
31
32     with pytest.raises(NotImplementedError):
33         # missing entrypoint
34         bad_xapp = MyXapp(rmr_wait_for_ready=False, use_fake_sdl=True)
35         bad_xapp.run()
36
37
38 def test_bad_init():
39     """test that an xapp whose rmr fails to init blows up"""
40
41     class MyXapp(Xapp):
42         def entrypoint(self):
43             pass
44
45     with pytest.raises(InitFailed):
46         bad_xapp = MyXapp(rmr_port=-1)
47         bad_xapp.run()  # we wont get here
48
49
50 def test_init_general_xapp():
51     class MyXapp(Xapp):
52         def post_init(self):
53             self.sdl_set("testns", "mykey", 6)
54
55         def entrypoint(self):
56             assert self.sdl_get("testns", "mykey") == 6
57             assert self.sdl_find_and_get("testns", "myk") == {"mykey": 6}
58             assert self.healthcheck()
59             # normally we would have some kind of loop here
60             print("bye")
61
62     global gen_xapp
63     gen_xapp = MyXapp(rmr_wait_for_ready=False, use_fake_sdl=True)
64     gen_xapp.run()
65
66
67 def teardown_module():
68     """
69     module teardown
70
71     pytest will never return without this.
72     """
73     gen_xapp.stop()