Generate test samples from data structures
1.1. Use Case Name
Generate test samples from data structures
1.2. Tags
Unit-Test, Data-Structure, Serialization, Python-Dataclass, CSV-to-Code, Automation
1.3. Introduction
Transform raw data samples into structured code effortlessly. This use case allows developers to take existing data files (e.g., CSV, JSON) and automatically generate the corresponding data classes (structs) along with serialization and deserialization functions. It also includes the automatic generation of unit tests to validate that the data is processed correctly, ensuring data integrity across your application.
1.4. Outcome
- Data Class/Struct: A clean code representation of your data schema.
- Serialization Logic: Automated functions to convert data to and from various formats.
- Validation Tests: Unit tests that verify every data row against the generated structure.
1.5. Starter Prompt
# Environment
Language: Python
Data Format: CSV
# Context
I have a CSV data file where the first row is the header. I want to use this data in Python as a dataclass. The data file is @current_file.
# Action
Generate a dataclass, including functions to serialize and deserialize the data, along with unit tests for each function.
# With constraints for action
Unit tests should not only test functions but also validate each data row.
The file path of the data will be set later by a variable.
# Output Format
Output of the above action is Python code.
1.6. Inputs Required
- Sample Data File: An open CSV or JSON file that serves as the schema reference.
- Target Language: The programming language for the generated struct (e.g., Python, C++, Go).
- Specific Constraints: Any specific validation rules or variable handling requirements.
1.7. Prerequisites
- The raw data file must have a clear header or structure.
- The AI assistant (CodeVista) must have access to the active file context.
1.8. How to Use
- Open your data sample (e.g.,
data.csv) in the editor. - Open CodeVista panel and paste the Starter Prompt.
- AI will generate the dataclass, the serialize/deserialize logic, and the unittest code.
- Copy the generated Python code into a new file and run it to verify your data processing logic.