import unittest import pandas as pd from app import download_stock_data, calculate_bollinger_bands, detect_anomalies # Replace 'app' with the actual name of your script if different class TestStockAnalysis(unittest.TestCase): def test_download_stock_data(self): ticker = 'RELIANCE.NS' df = download_stock_data(ticker) self.assertIsInstance(df, pd.DataFrame) self.assertFalse(df.empty) self.assertIn('Close', df.columns) def test_calculate_bollinger_bands(self): data = {'Close': [100, 101, 102, 103, 104, 105, 106, 107, 108, 109]} df = pd.DataFrame(data) window = 3 no_of_stds = 2 df_with_bands = calculate_bollinger_bands(df, window, no_of_stds) self.assertIn('Bollinger High', df_with_bands.columns) self.assertIn('Bollinger Low', df_with_bands.columns) def test_detect_anomalies(self): data = { 'Close': [100, 101, 102, 103, 104, 105, 106, 107, 108, 109], 'Bollinger High': [102, 103, 104, 105, 106, 107, 108, 109, 110, 111], 'Bollinger Low': [98, 99, 100, 101, 102, 103, 104, 105, 106, 107] } df = pd.DataFrame(data) anomalies = detect_anomalies(df) self.assertIsInstance(anomalies, pd.Series) self.assertEqual(len(anomalies), len(df)) if __name__ == '__main__': unittest.main()