### Run All E2E Tests Source: https://github.com/memfuse/memfuse-python/blob/main/tests/TEST.md Executes all end-to-end tests for the MemFuse SDK using Poetry. ```bash poetry run python scripts/run_tests.py --layer e2e ``` -------------------------------- ### Install MemFuse Python SDK using Pip Source: https://github.com/memfuse/memfuse-python/blob/main/README.md Installs the MemFuse Python SDK from the Python Package Index (PyPI). This is the recommended method for most users. ```bash pip install memfuse ``` -------------------------------- ### Pytest Assertion Examples (Python) Source: https://github.com/memfuse/memfuse-python/blob/main/tests/TEST.md Illustrates effective assertion patterns in pytest, emphasizing specificity and leveraging pytest's features like `pytest.raises` for exception testing and checking mock call counts. This promotes robust and readable tests. ```python # Be specific with assertions assert response.status_code == 200 # Not just assert response assert user.id == "expected_id" assert len(users) == 5 # Use pytest features with pytest.raises(ValueError, match="Invalid API key"): client = MemFuse(api_key="") # Check call counts and arguments mock_session.request.assert_called_once_with( "POST", "https://api.example.com/users", json={"name": "Test User"} ) ``` -------------------------------- ### Install MemFuse Python SDK from Source Source: https://github.com/memfuse/memfuse-python/blob/main/README.md Installs the MemFuse Python SDK by cloning the repository and installing it in editable mode. This is useful for development or when using the latest unreleased features. ```bash git clone https://github.com/memfuse/memfuse-python.git cd memfuse-python pip install -e . ``` -------------------------------- ### Run All MemFuse Python SDK Tests Source: https://github.com/memfuse/memfuse-python/blob/main/tests/TEST.md Executes all defined test layers sequentially: smoke, unit, error_handling, integration, dx, e2e, and benchmarks. This provides a full regression test suite. ```bash poetry run python scripts/run_tests.py ``` -------------------------------- ### Pytest Timeout Configuration (Commented) Source: https://github.com/memfuse/memfuse-python/blob/main/tests/TEST.md This section shows how to configure timeouts for pytest tests using the pytest-timeout plugin. It is commented out in the example, indicating it's an optional or currently disabled configuration. ```pytest.ini # timeout = 30 # timeout_method = thread ``` -------------------------------- ### Running Benchmark Tests Source: https://github.com/memfuse/memfuse-python/blob/main/tests/TEST.md Command to execute tests specifically for the benchmarks layer using the project's test runner script. This command leverages Poetry to run Python scripts. ```bash poetry run python scripts/run_tests.py --layer benchmarks ``` -------------------------------- ### Pytest Configuration (pytest.ini) Source: https://github.com/memfuse/memfuse-python/blob/main/tests/TEST.md Configuration file for pytest, defining test discovery paths, file/class/function naming conventions, default command-line options like verbosity and traceback style, and custom markers for categorizing tests (e.g., smoke, unit, integration, e2e, benchmarks). ```ini [pytest] # Test discovery testpaths = tests python_files = test_*.py python_classes = Test* python_functions = test_* # Output options addopts = -ra --strict-markers --strict-config --tb=short -v # Markers markers = smoke: Basic functionality tests unit: Unit tests with mocked dependencies integration: Integration tests with mocked HTTP e2e: End-to-end tests requiring real server benchmarks: Performance and benchmark tests slow: Tests that take significant time asyncio: Async tests ``` -------------------------------- ### Run Complete Evaluation with Data Loading (Bash) Source: https://github.com/memfuse/memfuse-python/blob/main/scripts/usage.md Executes the load_and_run.py script to perform a complete evaluation, including data loading. This is suitable for first-time evaluations or after dataset updates. ```bash poetry run python scripts/load_and_run.py msc --num-questions 20 --random --top-k 5 ``` -------------------------------- ### List Available Test Layers Source: https://github.com/memfuse/memfuse-python/blob/main/tests/TEST.md Lists all the testable layers within the MemFuse Python SDK test suite, along with their current status or configuration. This helps in understanding the test organization and available execution targets. ```bash poetry run python scripts/run_tests.py --list ``` -------------------------------- ### Run MemFuse Python SDK Tests with Verbose Output Source: https://github.com/memfuse/memfuse-python/blob/main/tests/TEST.md Executes tests for a specified layer with verbose output enabled. This provides detailed information about each test's execution, including individual test outcomes and potential captured output, which is helpful for debugging. ```bash poetry run python scripts/run_tests.py --layer e2e --verbose ``` -------------------------------- ### Async Configuration for Pytest Source: https://github.com/memfuse/memfuse-python/blob/main/tests/TEST.md Configures pytest to automatically detect and run asynchronous tests, setting the default loop scope to 'function'. This requires the pytest-asyncio package. ```pytest.ini asyncio_mode = auto asyncio_default_fixture_loop_scope = function ``` -------------------------------- ### Run Specific Test File with Pytest Source: https://github.com/memfuse/memfuse-python/blob/main/tests/TEST.md Executes a single, specific test file using pytest with verbose output. This allows for isolated testing of a particular test file, providing detailed feedback on its execution. ```bash poetry run pytest tests/smoke/test_smoke_basic.py -v ``` -------------------------------- ### Run Evaluation Only (Bash) Source: https://github.com/memfuse/memfuse-python/blob/main/scripts/usage.md Executes the run_evaluation.py script for evaluation only, assuming data is already loaded into MemFuse memory. This is useful for re-evaluating with different parameters or for quicker tests. ```bash poetry run python scripts/run_evaluation.py msc --num-questions 20 --random --top-k 5 ``` -------------------------------- ### Test Runner Script for MemFuse Python SDK (Python) Source: https://github.com/memfuse/memfuse-python/blob/main/tests/TEST.md The `run_tests.py` script provides a centralized way to execute different layers of tests (smoke, unit, integration, e2e, benchmarks). It uses `subprocess` to run `pytest` for specified paths and includes arguments for layer selection, verbosity, and output display. It also supports listing available test layers. ```python # scripts/run_tests.py #!/usr/bin/env python3 import sys import subprocess from pathlib import Path import argparse LAYERS = [ ("smoke", "tests/smoke"), ("unit", "tests/unit"), ("error_handling", "tests/error_handling"), ("integration", "tests/integration"), ("dx", "tests/dx"), ("e2e", "tests/e2e"), ("benchmarks", "tests/benchmarks") ] def run_layer(name, path): """Run tests for a specific layer.""" print(f"\n{'='*60}") print(f"Running {name} tests...") print(f"{ '='*60}") result = subprocess.run( [sys.executable, "-m", "pytest", path, "-v"], capture_output=True, text=True ) if result.returncode != 0: print(f"\n{name} tests FAILED!") print(result.stdout) print(result.stderr) return False print(f"{name} tests PASSED!") return True def main(): """Run all test layers in sequence.""" parser = argparse.ArgumentParser(description='Run MemFuse Python SDK tests') parser.add_argument('--layer', '-l', help='Run specific layer only') parser.add_argument('--verbose', '-v', action='store_true', help='Verbose output') parser.add_argument('--show-output', '-s', action='store_true', help='Show test output (stdout/print statements)') parser.add_argument('--list', action='store_true', help='List available layers') args = parser.parse_args() if args.list: print("Available test layers:") for name, path in LAYERS: exists = "✅" if Path(path).exists() else "❌" print(f" {exists} {name:<15} - {path}") return if args.layer: # Placeholder for running a specific layer, needs implementation # success = run_specific_layer(args.layer, args.verbose, args.show_output) # sys.exit(0 if success else 1) pass # Simplified for this example for name, path in LAYERS: if not Path(path).exists(): print(f"Skipping {name} tests - path {path} not found") continue if not run_layer(name, path): print(f"\nStopping test run due to {name} layer failure") sys.exit(1) print("\n✅ All test layers passed!") if __name__ == "__main__": main() ``` -------------------------------- ### Pytest Warning Filtering Source: https://github.com/memfuse/memfuse-python/blob/main/tests/TEST.md Configures pytest to filter specific types of warnings during test execution. This includes errors, deprecation warnings, pending deprecation warnings, and specific pytest warnings. ```pytest.ini filterwarnings = error ignore::DeprecationWarning ignore::PendingDeprecationWarning ignore::pytest.PytestUnraisableExceptionWarning ``` -------------------------------- ### Run Specific Test Function with Pytest Source: https://github.com/memfuse/memfuse-python/blob/main/tests/TEST.md Executes a particular test function within a specified test file using pytest. This offers the most granular level of testing, enabling focused debugging of individual test cases with captured output enabled. ```bash poetry run pytest tests/e2e/test_e2e_memory_followup.py::test_memory_followup_includes_mars_reference -v -s ``` -------------------------------- ### Run MemFuse Python SDK Tests Hiding Output Source: https://github.com/memfuse/memfuse-python/blob/main/tests/TEST.md Executes tests for a specified layer while suppressing their standard output and standard error. This is useful for cleaner test runs when only the test success/failure status is needed, or when investigating specific output capturing issues. ```bash poetry run python scripts/run_tests.py --layer e2e --hide-output ``` -------------------------------- ### Run Specific Layer of MemFuse Python SDK Tests Source: https://github.com/memfuse/memfuse-python/blob/main/tests/TEST.md Executes tests for a single, specified layer. This is useful for targeted testing or when debugging issues within a particular test category. Replace `` with the desired layer (e.g., smoke, unit, integration). ```bash poetry run python scripts/run_tests.py --layer ``` -------------------------------- ### Pytest Fixture for Mocked Session (Python) Source: https://github.com/memfuse/memfuse-python/blob/main/tests/TEST.md Defines a pytest fixture named `mock_session` using `unittest.mock.AsyncMock` to simulate an asynchronous HTTP session. This is useful for testing components that interact with external services without making actual network requests. It mocks the `request` method and its return value, including the `json` method for async responses. ```python # conftest.py import pytest from unittest.mock import Mock, AsyncMock @pytest.fixture def mock_session(): """Provides a mocked aiohttp session.""" session = AsyncMock() session.request.return_value.__aenter__.return_value.json = AsyncMock() return session @pytest.fixture def mock_client(mock_session): """Provides a client with mocked session.""" # Implementation here ``` -------------------------------- ### Initialize MemFuse and OpenAI Client Source: https://github.com/memfuse/memfuse-python/blob/main/README.md Demonstrates initializing the MemFuse client and an OpenAI client with memory integration. It shows how to set up a user and agent for memory management and then use this memory scope with the LLM. ```python from memfuse.llm import OpenAI from memfuse import MemFuse import os memfuse_client = MemFuse( # api_key=os.getenv("MEMFUSE_API_KEY") # base_url=os.getenv("MEMFUSE_BASE_URL"), ) memory = memfuse_client.init( user="alice", # agent="agent_default", # session= ) # Initialize your LLM client with the memory scope llm_client = OpenAI( api_key=os.getenv("OPENAI_API_KEY"), # Your OpenAI API key memory=memory ) # Make a chat completion request response = llm_client.chat.completions.create( model="gpt-4o", # Or any model supported by your LLM provider messages=[{"role": "user", "content": "I'm planning a trip to Mars. What is the gravity there?"}] ) print(f"Response: {response.choices[0].message.content}") # Example Output: Response: Mars has a gravity of about 3.721 m/s², which is about 38% of Earth's gravity. ``` -------------------------------- ### Basic Data Loading Commands Source: https://github.com/memfuse/memfuse-python/blob/main/benchmarks/loading-guide.md Demonstrates basic usage of the load_data.py script with different parameters for controlling the data loading range. ```bash poetry run python benchmarks/load_data.py msc --start-id 450 --load-all # Load questions 100-200 poetry run python benchmarks/load_data.py msc --start-id 100 --end-id 200 # Load 50 questions starting from question 450 poetry run python benchmarks/load_data.py lme --start-id 450 --num-questions 50 ``` -------------------------------- ### Batch Loading Data Source: https://github.com/memfuse/memfuse-python/blob/main/benchmarks/loading-guide.md Illustrates how to load data in batches using the --start-id and --end-id parameters for defined ranges, or --start-id with --load-all for the remainder of the dataset. ```bash # Batch 1: Questions 1-200 poetry run python benchmarks/load_data.py locomo --start-id 1 --end-id 200 # Batch 2: Questions 201-400 poetry run python benchmarks/load_data.py locomo --start-id 201 --end-id 400 # Batch 3: Questions 401 to end poetry run python benchmarks/load_data.py locomo --start-id 401 --load-all ``` -------------------------------- ### Contextual Follow-up with MemFuse Source: https://github.com/memfuse/memfuse-python/blob/main/README.md Shows how to make a follow-up request to the LLM client, demonstrating MemFuse's ability to automatically recall relevant context from previous interactions. This allows for more natural and stateful conversations. ```python # Ask a follow-up question. MemFuse automatically recalls relevant context. followup_response = llm_client.chat.completions.create( model="gpt-4o", messages=[{"role": "user", "content": "What are some challenges of living on that planet?"}] ) print(f"Follow-up: {followup_response.choices[0].message.content}") ``` -------------------------------- ### Recover from Interrupted Loading Source: https://github.com/memfuse/memfuse-python/blob/main/benchmarks/loading-guide.md Shows how to resume data loading after a failure by specifying the --start-id parameter. ```bash # Original command (failed at question 445) poetry run python benchmarks/load_data.py msc --load-all # Recovery command poetry run python benchmarks/load_data.py msc --start-id 445 --load-all ``` -------------------------------- ### Run Memfuse-Python Smoke Tests Source: https://github.com/memfuse/memfuse-python/blob/main/tests/smoke/SMOKE.md Executes the full smoke test suite for the Memfuse-Python project using pytest. This command is used to verify the project's core functionality and ensure all tests pass before proceeding to integration testing. ```bash pytest tests/smoke/ -v ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.