To extend AndroidWorld with SQLite-based tasks, follow these steps to leverage the sqlite_validators abstractions.
- Define a Data Class: Create a
@dataclasses.dataclass(frozen=True) that mirrors the SQLite table structure. - Create a Base Task Class: Inherit from
sqlite_validators.SQLiteApp. Specify app_name_with_db, app_names, db_key, db_path, table_name, and row_type (your data class). - Implement Task Logic: Create a class that extends both your base class and
sqlite_validators.AddMultipleRows. Define:complexity: Integer value.template: A string with placeholders for task parameters._get_random_target_row(): Returns a target data instance.validate_addition_integrity(): Uses sqlite_validators.validate_rows_addition_integrity to compare before, after, and reference_rows using specific compare_fields.generate_random_params(): Returns a dictionary containing task parameters and special keys like sqlite_validators.ROW_OBJECTS and sqlite_validators.NOISE_ROW_OBJECTS.
Note: AndroidWorld automatically handles state via initialize_state and tear_down.
@dataclasses.dataclass(frozen=True)
class CalendarEvent:
start_ts: int
end_ts: int
title: str
location: str = ''
description: str = ''
repeat_interval: int = 0
repeat_rule: int = 0
class _SimpleCalendar(sqlite_validators.SQLiteApp):
app_name_with_db = "simple calendar pro"
app_names = ("simple calendar pro",)
db_key = "id"
db_path = "data/data/com.simplemobiletools.calendar.pro/databases/events.db"
table_name = "events"
row_type = CalendarEvent
class SimpleCalendarAddOneEvent(sqlite_validators.AddMultipleRows, _SimpleCalendar):
complexity = 2
template = "In Simple Calendar Pro, create a calendar event on {year}-{month}-{day}..."
def validate_addition_integrity(self, before, after, reference_rows) -> bool:
return sqlite_validators.validate_rows_addition_integrity(
before, after, reference_rows,
compare_fields=['start_ts', 'end_ts', 'title', 'location', 'description']
)