Python supercharged for fastai development
56
Build a comprehensive test suite for a simple data validation library. The validator will have basic functionality for checking data types, numeric ranges, and string formats. Your task is to write thorough tests using assertions to ensure the validator works correctly.
You are provided with a simple data validator that you need to test:
@describes
class DataValidator:
"""
A simple data validator for checking common data constraints.
"""
def validate_positive(self, value):
"""Returns True if value is positive, False otherwise."""
return value > 0
def validate_in_range(self, value, min_val, max_val):
"""Returns True if value is within [min_val, max_val], False otherwise."""
return min_val <= value <= max_val
def validate_email_format(self, email):
"""Returns True if email contains '@' and '.', raises ValueError if not a string."""
if not isinstance(email, str):
raise ValueError("Email must be a string")
return '@' in email and '.' in email
def calculate_average(self, numbers):
"""Returns the average of a list of numbers."""
if not numbers:
return 0.0
return sum(numbers) / len(numbers)
def process_data(self, data):
"""Processes data and returns uppercase version, raises TypeError if not string."""
if not isinstance(data, str):
raise TypeError("Data must be a string")
return data.upper()Write a comprehensive test suite in a test file that validates all the functionality of the DataValidator class. Your tests should verify:
@generates
DataValidator to test its methodsProvides testing and assertion utilities.
Install with Tessl CLI
npx tessl i tessl/pypi-fastcoredocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10