deepanshuk | 588acf1 | 2021-01-06 16:10:44 +0530 | [diff] [blame] | 1 | # ================================================================================== |
| 2 | # Copyright (c) 2020 HCL Technologies Limited. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | # ================================================================================== |
| 16 | from ad import main |
| 17 | from ricxappframe.xapp_frame import Xapp |
| 18 | from contextlib import suppress |
| 19 | import os |
| 20 | from ad.ad_train import train |
| 21 | import json |
| 22 | |
| 23 | |
deepanshuk | 91624d7 | 2021-07-06 13:07:04 +0530 | [diff] [blame] | 24 | def test_database_connection(monkeypatch): |
| 25 | # start qp |
| 26 | main.connectdb(thread=True) |
deepanshuk | 588acf1 | 2021-01-06 16:10:44 +0530 | [diff] [blame] | 27 | |
| 28 | |
deepanshuk | 91624d7 | 2021-07-06 13:07:04 +0530 | [diff] [blame] | 29 | def test_trainModel(monkeypatch): |
| 30 | if not os.path.isfile('model'): |
| 31 | train(thread=True) |
| 32 | |
| 33 | |
| 34 | def test_predict_anomaly(monkeypatch, ad_ue): |
| 35 | main.predict_anomaly(monkeypatch, ad_ue) |
deepanshuk | 588acf1 | 2021-01-06 16:10:44 +0530 | [diff] [blame] | 36 | |
| 37 | |
| 38 | def test_msg_to_ts(monkeypatch, ad_to_ts): |
| 39 | |
| 40 | def mock_ad_entry(self): |
| 41 | val = json.dumps(ad_to_ts).encode() |
| 42 | self.rmr_send(val, 30003) |
| 43 | global mock_ad_xapp |
| 44 | mock_ad_xapp = Xapp(entrypoint=mock_ad_entry, rmr_port=4564, use_fake_sdl=True) |
| 45 | mock_ad_xapp.run() # this will return since mock_ad_entry isn't a loop # this will return since mock_ad_entry isn't a loop |
| 46 | |
| 47 | |
| 48 | def teardown_module(): |
| 49 | """ |
| 50 | this is like a "finally"; the name of this function is pytest magic |
| 51 | safer to put down here since certain failures above can lead to pytest never returning |
| 52 | for example if an exception gets raised before stop is called in any test function above, |
| 53 | pytest will hang forever |
| 54 | """ |
| 55 | with suppress(Exception): |
| 56 | mock_ad_xapp.stop() |