code: def test_attr():
      """Testing of attributes such as long only"""
      indicator_name = "SMA"
      tech_params = TechParams()
  
      # Test Case 1: Only longs or only shorts
      # Test Case 1.1: Only longs
      cols = get_cols_name(1)
      tech_params.sma_period = 3
      tech_params.only_allow_longs = True
      data_df = pd.DataFrame(
          index=dates, columns=cols, data=list(range(1, 9))
      )
      tech_ind.create_tech_ind(data_df, indicator_name, tech_params)
      expected_signal_df = pd.DataFrame(
          index=dates,
          columns=[
              " ".join([col, indicator_name, "Signal"]) for col in cols
          ],
          data=1,
      )
      expected_df = pd.DataFrame(
          index=dates,
          columns=[" ".join([col, indicator_name]) for col in cols],
          data=data_df.shift().values,
      )
      df = tech_ind.get_techind()
      signal_df = tech_ind.get_signal()
  
      expected_signal_df.iloc[: tech_params.sma_period] = np.nan
      expected_df.iloc[: tech_params.sma_period - 1] = np.nan
  
      assert_frame_equal(df, expected_df)
      assert_frame_equal(signal_df, expected_signal_df)
  
      data_df = pd.DataFrame(
          index=dates, columns=cols, data=list(range(8, 0, -1))
      )
      tech_ind.create_tech_ind(data_df, indicator_name, tech_params)
      expected_signal_df = pd.DataFrame(
          index=dates,
          columns=[
              " ".join([col, indicator_name, "Signal"]) for col in cols
          ],
          data=0,
      )
      expected_df = pd.DataFrame(
          index=dates,
          columns=[" ".join([col, indicator_name]) for col in cols],
          data=data_df.shift().values,
      )
      df = tech_ind.get_techind()
      signal_df = tech_ind.get_signal()
  
      expected_signal_df.iloc[: tech_params.sma_period] = np.nan
      expected_df.iloc[: tech_params.sma_period - 1] = np.nan
  
      assert_frame_equal(df, expected_df)
      assert_frame_equal(signal_df, expected_signal_df)
  
      # Test Case 1.1: Only shorts
      tech_params = TechParams()
      tech_params.sma_period = 3
      tech_params.only_allow_shorts = True
      data_df = pd.DataFrame(
          index=dates, columns=cols, data=list(range(1, 9))
      )
      tech_ind.create_tech_ind(data_df, indicator_name, tech_params)
      expected_signal_df = pd.DataFrame(
          index=dates,
          columns=[
              " ".join([col, indicator_name, "Signal"]) for col in cols
          ],
          data=0,
      )
      expected_df = pd.DataFrame(
          index=dates,
          columns=[" ".join([col, indicator_name]) for col in cols],
          data=data_df.shift().values,
      )
      df = tech_ind.get_techind()
      signal_df = tech_ind.get_signal()
  
      expected_signal_df.iloc[: tech_params.sma_period] = np.nan
      expected_df.iloc[: tech_params.sma_period - 1] = np.nan
  
      assert_frame_equal(df, expected_df)
      assert_frame_equal(signal_df, expected_signal_df)
  
      data_df = pd.DataFrame(
          index=dates, columns=cols, data=list(range(8, 0, -1))
      )
      tech_ind.create_tech_ind(data_df, indicator_name, tech_params)
      expected_signal_df = pd.DataFrame(
          index=dates,
          columns=[
              " ".join([col, indicator_name, "Signal"]) for col in cols
          ],
          data=-1,
      )
      expected_df = pd.DataFrame(
          index=dates,
          columns=[" ".join([col, indicator_name]) for col in cols],
          data=data_df.shift().values,
      )
      df = tech_ind.get_techind()
      signal_df = tech_ind.get_signal()
  
      expected_signal_df.iloc[: tech_params.sma_period] = np.nan
      expected_df.iloc[: tech_params.sma_period - 1] = np.nan
  
      assert_frame_equal(df, expected_df)
      assert_frame_equal(signal_df, expected_signal_df)
  
      # Test Case 2: Check incompatibility between only_allow_longs and only_allow_shorts
      tech_params = TechParams()
      tech_params.only_allow_shorts = True
      with pytest.raises(Exception):
          tech_params.only_allow_longs = True
  
      tech_params = TechParams()
      tech_params.only_allow_longs = True
      with pytest.raises(Exception):
          tech_params.only_allow_shorts = True
  
      # Test Case 3: test strip_signal_name
      tech_params = TechParams()
      tech_params.sma_period = 3
      tech_params.strip_signal_name = True
      data_df = pd.DataFrame(
          index=dates, columns=cols, data=list(range(1, 9))
      )
      tech_ind.create_tech_ind(data_df, indicator_name, tech_params)
      expected_signal_df = pd.DataFrame(
          index=dates, columns=cols, data=1
      )
      expected_df = pd.DataFrame(
          index=dates,
          columns=[" ".join([col, indicator_name]) for col in cols],
          data=data_df.shift().values,
      )
      df = tech_ind.get_techind()
      signal_df = tech_ind.get_signal()
  
      expected_signal_df.iloc[: tech_params.sma_period] = np.nan
      expected_df.iloc[: tech_params.sma_period - 1] = np.nan
  
      assert_frame_equal(df, expected_df)
      assert_frame_equal(signal_df, expected_signal_df)
  
      # Test Case 4: test signal multiplier
      tech_params = TechParams()
      tech_params.sma_period = 3
      tech_params.signal_mult = -1
      data_df = pd.DataFrame(
          index=dates, columns=cols, data=list(range(1, 9))
      )
      tech_ind.create_tech_ind(data_df, indicator_name, tech_params)
      expected_signal_df = pd.DataFrame(
          index=dates,
          columns=[
              " ".join([col, indicator_name, "Signal"]) for col in cols
          ],
          data=-1,
      )
      expected_df = pd.DataFrame(
          index=dates,
          columns=[" ".join([col, indicator_name]) for col in cols],
          data=data_df.shift().values,
      )
      df = tech_ind.get_techind()
      signal_df = tech_ind.get_signal()
  
      expected_signal_df.iloc[: tech_params.sma_period] = np.nan
      expected_df.iloc[: tech_params.sma_period - 1] = np.nan
  
      assert_frame_equal(df, expected_df)
      assert_frame_equal(signal_df, expected_signal_df)
  
      tech_params.signal_mult = 0
      data_df = pd.DataFrame(
          index=dates, columns=cols, data=list(range(1, 9))
      )
      tech_ind.create_tech_ind(data_df, indicator_name, tech_params)
      expected_signal_df = pd.DataFrame(
          index=dates,
          columns=[
              " ".join([col, indicator_name, "Signal"]) for col in cols
          ],
          data=0,
      )
      expected_df = pd.DataFrame(
          index=dates,
          columns=[" ".join([col, indicator_name]) for col in cols],
          data=data_df.shift().values,
      )
      df = tech_ind.get_techind()
      signal_df = tech_ind.get_signal()
  
      expected_signal_df.iloc[: tech_params.sma_period] = np.nan
      expected_df.iloc[: tech_params.sma_period - 1] = np.nan
  
      assert_frame_equal(df, expected_df)
      assert_frame_equal(signal_df, expected_signal_df)
  
      tech_params.signal_mult = 3
      data_df = pd.DataFrame(
          index=dates, columns=cols, data=list(range(1, 9))
      )
      tech_ind.create_tech_ind(data_df, indicator_name, tech_params)
      expected_signal_df = pd.DataFrame(
          index=dates,
          columns=[
              " ".join([col, indicator_name, "Signal"]) for col in cols
          ],
          data=3,
      )
      expected_df = pd.DataFrame(
          index=dates,
          columns=[" ".join([col, indicator_name]) for col in cols],
          data=data_df.shift().values,
      )
      df = tech_ind.get_techind()
      signal_df = tech_ind.get_signal()
  
      expected_signal_df.iloc[: tech_params.sma_period] = np.nan
      expected_df.iloc[: tech_params.sma_period - 1] = np.nan
  
      assert_frame_equal(df, expected_df)
      assert_frame_equal(signal_df, expected_signal_df)
  
file_path: finmarketpy/tests/test_techindicator.py
imports: import pytest
  import pandas
  import numpy
  from pandas.testing import assert_frame_equal
  from finmarketpy.economics.techindicator import TechParams, TechIndicator
label_desc: Use image node_id 6 for calling a global function with example usage: test_attr() without return types