code: install_deps> python -I -m pip install coverage pytest pytest-cov
.pkg: install_requires> python -I -m pip install 'setuptools>=40.8.0'
.pkg: _optional_hooks> python /tmp/venv-KbE3/lib/python3.10/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
.pkg: get_requires_for_build_sdist> python /tmp/venv-KbE3/lib/python3.10/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
.pkg: get_requires_for_build_wheel> python /tmp/venv-KbE3/lib/python3.10/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
.pkg: freeze> python -m pip freeze --all
.pkg: pip==26.0.1,setuptools==82.0.0
.pkg: prepare_metadata_for_build_wheel> python /tmp/venv-KbE3/lib/python3.10/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
.pkg: build_sdist> python /tmp/venv-KbE3/lib/python3.10/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
code: install_package_deps> python -I -m pip install 'Scikit-learn>=0.18' influxdb 'joblib>=0.3.2' 'mdclogpy<=1.1.1' 'pandas>=1.1.3' ricxappframe==3.2.2 'schedule>=0.0.0'
code: install_package> python -I -m pip install --force-reinstall --no-deps /w/workspace/ric-app-ad-tox-sonarqube/.tox/.tmp/package/1/ad-1.0.1.tar.gz
code: freeze> python -m pip freeze --all
code: ad==1.0.1,async-timeout==5.0.1,build==1.4.2,certifi==2026.2.25,charset-normalizer==3.4.6,coverage==7.13.5,exceptiongroup==1.3.1,hiredis==2.0.0,idna==3.11,influxdb==5.3.2,iniconfig==2.3.0,inotify==0.2.12,inotify-simple==2.0.1,joblib==1.5.3,mdclogpy==1.1.1,msgpack==1.1.2,numpy==2.2.6,packaging==26.0,pandas==2.3.3,pip==26.0.1,pluggy==1.6.0,protobuf==3.20.3,Pygments==2.19.2,pyproject_hooks==1.2.0,pytest==9.0.2,pytest-cov==7.1.0,python-dateutil==2.9.0.post0,pytz==2026.1.post1,redis==4.3.6,requests==2.33.0,ricsdl==3.1.3,ricxappframe==3.2.2,schedule==1.2.2,scikit-learn==1.7.2,scipy==1.15.3,setuptools==82.0.0,six==1.17.0,threadpoolctl==3.6.0,tomli==2.4.1,typing_extensions==4.15.0,tzdata==2025.3,urllib3==2.6.3
code: commands[0]> pytest -v --cov src --cov-report xml --cov-report term-missing --cov-report html --cov-fail-under=50
============================= test session starts ==============================
platform linux -- Python 3.10.6, pytest-9.0.2, pluggy-1.6.0 -- /w/workspace/ric-app-ad-tox-sonarqube/.tox/code/bin/python
cachedir: .tox/code/.pytest_cache
rootdir: /w/workspace/ric-app-ad-tox-sonarqube
plugins: cov-7.1.0
collecting ... collected 4 items

tests/test_ad.py::test_database_connection PASSED                        [ 25%]
tests/test_ad.py::test_trainModel FAILED                                 [ 50%]
tests/test_ad.py::test_predict_anomaly FAILED                            [ 75%]
tests/test_ad.py::test_msg_to_ts PASSED                                  [100%]

=================================== FAILURES ===================================
_______________________________ test_trainModel ________________________________

monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x7fa1f49c82b0>

    def test_trainModel(monkeypatch):
>       main.train_model()

tests/test_ad.py:28: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
src/main.py:62: in train_model
    mt.train()
src/ad_train.py:122: in train
    f1, model = self.isoforest()
src/ad_train.py:89: in isoforest
    md = model.fit(self.train_data.values)
.tox/code/lib/python3.10/site-packages/sklearn/base.py:1365: in wrapper
    return fit_method(estimator, *args, **kwargs)
.tox/code/lib/python3.10/site-packages/sklearn/model_selection/_search.py:1051: in fit
    self._run_search(evaluate_candidates)
.tox/code/lib/python3.10/site-packages/sklearn/model_selection/_search.py:1992: in _run_search
    evaluate_candidates(
.tox/code/lib/python3.10/site-packages/sklearn/model_selection/_search.py:997: in evaluate_candidates
    out = parallel(
.tox/code/lib/python3.10/site-packages/sklearn/utils/parallel.py:82: in __call__
    return super().__call__(iterable_with_config_and_warning_filters)
.tox/code/lib/python3.10/site-packages/joblib/parallel.py:1986: in __call__
    return output if self.return_generator else list(output)
.tox/code/lib/python3.10/site-packages/joblib/parallel.py:1914: in _get_sequential_output
    res = func(*args, **kwargs)
.tox/code/lib/python3.10/site-packages/sklearn/utils/parallel.py:147: in __call__
    return self.function(*args, **kwargs)
.tox/code/lib/python3.10/site-packages/sklearn/model_selection/_validation.py:851: in _fit_and_score
    X_train, y_train = _safe_split(estimator, X, y, train)
.tox/code/lib/python3.10/site-packages/sklearn/utils/metaestimators.py:156: in _safe_split
    X_subset = _safe_indexing(X, indices)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

X = array([[ 3.77292128e-01,  2.86786711e-02,  1.11735082e-04, ...,
        -3.75802327e-01, -4.02027834e-03,  1.21858569e...0016081e-02,  7.00032162e-05, ...,
        -5.88727048e-01, -2.85562268e-02,  1.17085036e-02]],
      shape=(10000, 7))
indices = array(slice(None, None, None), dtype=object)

    def _safe_indexing(X, indices, *, axis=0):
        """Return rows, items or columns of X using indices.
    
        .. warning::
    
            This utility is documented, but **private**. This means that
            backward compatibility might be broken without any deprecation
            cycle.
    
        Parameters
        ----------
        X : array-like, sparse-matrix, list, pandas.DataFrame, pandas.Series
            Data from which to sample rows, items or columns. `list` are only
            supported when `axis=0`.
        indices : bool, int, str, slice, array-like
            - If `axis=0`, boolean and integer array-like, integer slice,
              and scalar integer are supported.
            - If `axis=1`:
                - to select a single column, `indices` can be of `int` type for
                  all `X` types and `str` only for dataframe. The selected subset
                  will be 1D, unless `X` is a sparse matrix in which case it will
                  be 2D.
                - to select multiples columns, `indices` can be one of the
                  following: `list`, `array`, `slice`. The type used in
                  these containers can be one of the following: `int`, 'bool' and
                  `str`. However, `str` is only supported when `X` is a dataframe.
                  The selected subset will be 2D.
        axis : int, default=0
            The axis along which `X` will be subsampled. `axis=0` will select
            rows while `axis=1` will select columns.
    
        Returns
        -------
        subset
            Subset of X on axis 0 or 1.
    
        Notes
        -----
        CSR, CSC, and LIL sparse matrices are supported. COO sparse matrices are
        not supported.
    
        Examples
        --------
        >>> import numpy as np
        >>> from sklearn.utils import _safe_indexing
        >>> data = np.array([[1, 2], [3, 4], [5, 6]])
        >>> _safe_indexing(data, 0, axis=0)  # select the first row
        array([1, 2])
        >>> _safe_indexing(data, 0, axis=1)  # select the first column
        array([1, 3, 5])
        """
        if indices is None:
            return X
    
        if axis not in (0, 1):
            raise ValueError(
                "'axis' should be either 0 (to index rows) or 1 (to index "
                " column). Got {} instead.".format(axis)
            )
    
        indices_dtype = _determine_key_type(indices)
    
        if axis == 0 and indices_dtype == "str":
>           raise ValueError("String indexing is not supported with 'axis=0'")
E           ValueError: String indexing is not supported with 'axis=0'

.tox/code/lib/python3.10/site-packages/sklearn/utils/_indexing.py:305: ValueError
----------------------------- Captured stdout call -----------------------------
{"ts": 1774744640428, "crit": "DEBUG", "id": "ad_train", "mdc": {}, "msg": "Training on 10000 Samples"}
{"ts": 1774744640444, "crit": "DEBUG", "id": "ad_train", "mdc": {}, "msg": "Validation on 10000 Samples"}
{"ts": 1774744640444, "crit": "DEBUG", "id": "ad_train", "mdc": {}, "msg": "Training Starts"}
{"ts": 1774744640514, "crit": "INFO", "id": "ad_train", "mdc": {}, "msg": "Training Isolation Forest"}
_____________________________ test_predict_anomaly _____________________________

monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x7fa1f441da80>
ad_ue =    du-id ServingCellId  RRU.PrbUsedDl  ...    x    y         measTimeStampRf
0   1002        c2/B13              8  ... -882 -959 2021-05-12 07:43:51.652

[1 rows x 12 columns]

    def test_predict_anomaly(monkeypatch, ad_ue):
        main.load_model()
>       main.predict_anomaly(monkeypatch, ad_ue)

tests/test_ad.py:33: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
src/main.py:99: in predict_anomaly
    df['Anomaly'] = md.predict(df)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <ad_model.modelling object at 0x7fa1f441d870>
df =    du-id ServingCellId  RRU.PrbUsedDl  ...    x    y         measTimeStampRf
0   1002        c2/B13              8  ... -882 -959 2021-05-12 07:43:51.652

[1 rows x 12 columns]

    def predict(self, df):
        """ Load the saved model and return predicted result.
        Parameters
        .........
        name:str
            name of model
    
        Return
        ......
        pred:int
            predict label on a given sample
    
        """
        self.data = df.loc[:, self.num]
        self.transformation()
>       pred = self.model.predict(self.data)
E       AttributeError: 'modelling' object has no attribute 'model'

src/ad_model.py:78: AttributeError
----------------------------- Captured stdout call -----------------------------
{"ts": 1774744641262, "crit": "ERROR", "id": "ad_model", "mdc": {}, "msg": "Model Does not exsist"}
{"ts": 1774744641265, "crit": "INFO", "id": "src.main", "mdc": {}, "msg": "throughput threshold parameter is set as 70% (default)"}
=============================== warnings summary ===============================
tests/test_ad.py::test_trainModel
tests/test_ad.py::test_trainModel
  /w/workspace/ric-app-ad-tox-sonarqube/src/processing.py:52: FutureWarning: ChainedAssignmentError: behaviour will change in pandas 3.0!
  You are setting values through chained assignment. Currently this works in certain cases, but when using Copy-on-Write (which will become the default behaviour in pandas 3.0) this will never work to update the original DataFrame or Series, because the intermediate object on which we are setting values will behave as a copy.
  A typical example is when you are setting values in a column of a DataFrame, like:
  
  df["col"][row_indexer] = value
  
  Use `df.loc[row_indexer, "col"] = values` instead, to perform the assignment in a single step and ensure this keeps updating the original `df`.
  
  See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  
    self.data.iloc[:]['DRB.UEThpDl'] = self.data['DRB.UEThpDl'].apply(lambda x: x*1024)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
================================ tests coverage ================================
_______________ coverage: platform linux, python 3.10.6-final-0 ________________

Name                Stmts   Miss  Cover   Missing
-------------------------------------------------
src/__init__.py         0      0   100%
src/ad_model.py        67     34    49%   41, 50-51, 57-58, 79-80, 98-115, 119-130
src/ad_train.py        69     22    68%   56-58, 66-68, 90-91, 94-101, 123-129
src/database.py        94     36    62%   64-75, 85-97, 106-110, 113-118, 161, 164
src/exceptions.py       4      4     0%   18-25
src/insert.py          50     50     0%   21-84
src/main.py           116     75    35%   41-46, 70-83, 100-114, 119-130, 139, 146-163, 167-170, 174-177, 181-185, 190-192
src/processing.py      44      0   100%
-------------------------------------------------
TOTAL                 444    221    50%
Coverage HTML written to dir htmlcov
Coverage XML written to file coverage.xml
Required test coverage of 50% reached. Total coverage: 50.23%
=========================== short test summary info ============================
FAILED tests/test_ad.py::test_trainModel - ValueError: String indexing is not...
FAILED tests/test_ad.py::test_predict_anomaly - AttributeError: 'modelling' o...
=================== 2 failed, 2 passed, 2 warnings in 19.49s ===================
code: exit 1 (22.17 seconds) /w/workspace/ric-app-ad-tox-sonarqube> pytest -v --cov src --cov-report xml --cov-report term-missing --cov-report html --cov-fail-under=50 pid=2573
code: FAIL ✖ in 1 minute 30.45 seconds
flake8: install_deps> python -I -m pip install flake8
flake8: freeze> python -m pip freeze --all
flake8: ad==1.0.1,flake8==7.3.0,mccabe==0.7.0,pip==26.0.1,pycodestyle==2.14.0,pyflakes==3.4.0,setuptools==82.0.0
flake8: commands[0]> flake8 setup.py src tests
  code: FAIL code 1 (90.45=setup[68.27]+cmd[22.17] seconds)
  flake8: OK (3.90=setup[3.45]+cmd[0.45] seconds)
  evaluation failed :( (94.41 seconds)
