"""Quick tests for the analysis tools.""" import sys import os # Add src to path sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'src')) from tools import WordCounter, KeywordExtractor, SentimentAnalyzer def test_word_counter(): """Test word counter tool.""" print("Testing Word Counter...") tool = WordCounter() test_text = "This is a test. This is only a test. Testing is important." result = tool.run(test_text) print(f" Total words: {result['total_words']}") print(f" Unique words: {result['unique_words']}") print(f" Top words: {result['top_10_words'][:3]}") print(" ✓ Word Counter works!\n") def test_keyword_extractor(): """Test keyword extractor tool.""" print("Testing Keyword Extractor...") tool = KeywordExtractor() test_text = """ Machine learning is a subset of artificial intelligence. Deep learning algorithms use neural networks to process data. Natural language processing helps computers understand human language. """ result = tool.run(test_text) print(f" Keywords found: {result['num_keywords']}") print(f" Top 3 keywords:") for kw in result['keywords'][:3]: print(f" - {kw['word']}: {kw['score']}") print(" ✓ Keyword Extractor works!\n") def test_sentiment_analyzer(): """Test sentiment analyzer tool.""" print("Testing Sentiment Analyzer...") tool = SentimentAnalyzer() # Positive text positive_text = "This is wonderful! I love it. Great experience, highly recommended!" result = tool.run(positive_text) print(f" Positive text sentiment: {result['sentiment_label']} ({result['sentiment_score']})") # Negative text negative_text = "This is terrible. I hate it. Awful experience, very disappointed." result = tool.run(negative_text) print(f" Negative text sentiment: {result['sentiment_label']} ({result['sentiment_score']})") # Neutral text neutral_text = "The product arrived on Tuesday. It has a blue color." result = tool.run(neutral_text) print(f" Neutral text sentiment: {result['sentiment_label']} ({result['sentiment_score']})") print(" ✓ Sentiment Analyzer works!\n") if __name__ == "__main__": print("=" * 60) print("ReAct Text Analyzer - Tool Tests") print("=" * 60 + "\n") try: test_word_counter() test_keyword_extractor() test_sentiment_analyzer() print("=" * 60) print("✅ All tests passed!") print("=" * 60) print("\nYou can now run the Streamlit app:") print(" cd src && streamlit run app.py") print("\nOr use the quick start script:") print(" ./run.sh") except Exception as e: print(f"\n❌ Test failed: {e}") import traceback traceback.print_exc()