function test_discovery
Tests the hierarchical discovery functionality of a RemarkableDiscovery instance by discovering and cataloging all nodes (folders and documents) from a reMarkable device session.
/tf/active/vicechatdev/e-ink-llm/cloudtest/test_suite.py
48 - 78
moderate
Purpose
This function serves as a test harness for the RemarkableDiscovery class. It creates a discovery instance with a test output directory, runs a complete discovery operation to traverse the reMarkable device's file hierarchy, and reports statistics about discovered nodes including folders, documents, and data downloaded. It provides detailed logging and error handling for testing the discovery process.
Source Code
def test_discovery(session):
"""Test hierarchical discovery"""
print("\n" + "=" * 60)
print("š TESTING HIERARCHICAL DISCOVERY")
print("=" * 60)
try:
# Create discovery instance with test output directory
output_dir = Path.cwd() / "remarkable_test_output"
discovery = RemarkableDiscovery(session, str(output_dir))
print(f"š Output directory: {output_dir}")
# Run complete discovery
success = discovery.discover_all()
if success:
print(f"\nā
Discovery successful!")
print(f" Nodes discovered: {discovery.stats['total_nodes']}")
print(f" Folders: {discovery.stats['folders']}")
print(f" Documents: {discovery.stats['documents']}")
print(f" Data downloaded: {discovery.stats['bytes_downloaded']:,} bytes")
print(f" š Detailed log: {output_dir}/discovery_detailed.log")
return True
else:
print("ā Discovery failed")
return False
except Exception as e:
print(f"ā Discovery error: {e}")
return False
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
session |
- | - | positional_or_keyword |
Parameter Details
session: An authenticated session object (likely from RemarkableAuth) that provides access to the reMarkable device API. This session must be valid and authenticated before being passed to this function. It is used to initialize the RemarkableDiscovery instance and perform API calls to discover the device's file structure.
Return Value
Returns a boolean value: True if the discovery operation completed successfully (all nodes were discovered and cataloged), False if the discovery failed or an exception occurred. The function also prints detailed status information and statistics to stdout, including the number of nodes discovered, folders, documents, bytes downloaded, and the location of the detailed log file.
Dependencies
pathlibsystraceback
Required Imports
from pathlib import Path
from auth import RemarkableAuth
from auth import authenticate_remarkable
from discovery import RemarkableDiscovery
import traceback
Usage Example
from pathlib import Path
from auth import authenticate_remarkable
from discovery import RemarkableDiscovery
# First authenticate to get a session
auth = authenticate_remarkable()
session = auth.get_session()
# Run the discovery test
if session:
success = test_discovery(session)
if success:
print("Discovery test passed")
# Check output in ./remarkable_test_output/
else:
print("Discovery test failed")
else:
print("Failed to authenticate")
Best Practices
- Ensure the session parameter is properly authenticated before calling this function
- Check that the current working directory has write permissions before running
- The function creates a 'remarkable_test_output' directory in the current working directory - ensure this path is acceptable
- Review the detailed log file at 'remarkable_test_output/discovery_detailed.log' for troubleshooting
- This is a test function that prints to stdout - not suitable for production use without modification
- The function catches all exceptions broadly - consider more specific exception handling for production code
- Clean up the test output directory after testing if needed
- The function returns boolean but also prints extensive output - consider separating concerns for reusability
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function test_basic_discovery 93.8% similar
-
function test_remarkable_discovery 74.4% similar
-
class RemarkableDiscovery 69.9% similar
-
function test_root_finding 69.5% similar
-
function run_full_test_suite 64.3% similar