Skip to content

Commit 52a4283

Browse files
committed
validation into a diff module
1 parent e139c8b commit 52a4283

File tree

3 files changed

+67
-66
lines changed

3 files changed

+67
-66
lines changed

dbldatagen/spec/generator_spec.py

Lines changed: 1 addition & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from .compat import BaseModel
1212
from .output_targets import FilePathTarget, UCSchemaTarget
13+
from .validation import ValidationResult
1314

1415

1516
logger = logging.getLogger(__name__)
@@ -41,71 +42,6 @@ class TableDefinition(BaseModel):
4142
columns: list[ColumnDefinition]
4243

4344

44-
class ValidationResult:
45-
"""Container for validation results that collects errors and warnings during spec validation.
46-
47-
This class accumulates validation issues found while checking a DatagenSpec configuration.
48-
It distinguishes between errors (which prevent data generation) and warnings (which
49-
indicate potential issues but don't block generation).
50-
51-
.. note::
52-
Validation passes if there are no errors, even if warnings are present
53-
"""
54-
55-
def __init__(self) -> None:
56-
"""Initialize an empty ValidationResult with no errors or warnings."""
57-
self.errors: list[str] = []
58-
self.warnings: list[str] = []
59-
60-
def add_error(self, message: str) -> None:
61-
"""Add an error message to the validation results.
62-
63-
Errors indicate critical issues that will prevent successful data generation.
64-
65-
:param message: Descriptive error message explaining the validation failure
66-
"""
67-
self.errors.append(message)
68-
69-
def add_warning(self, message: str) -> None:
70-
"""Add a warning message to the validation results.
71-
72-
Warnings indicate potential issues or non-optimal configurations that may affect
73-
data generation but won't prevent it from completing.
74-
75-
:param message: Descriptive warning message explaining the potential issue
76-
"""
77-
self.warnings.append(message)
78-
79-
def is_valid(self) -> bool:
80-
"""Check if validation passed without errors.
81-
82-
:returns: True if there are no errors (warnings are allowed), False otherwise
83-
"""
84-
return len(self.errors) == 0
85-
86-
def __str__(self) -> str:
87-
"""Generate a formatted string representation of all validation results.
88-
89-
:returns: Multi-line string containing formatted errors and warnings with counts
90-
"""
91-
lines = []
92-
if self.is_valid():
93-
lines.append("✓ Validation passed successfully")
94-
else:
95-
lines.append("✗ Validation failed")
96-
97-
if self.errors:
98-
lines.append(f"\nErrors ({len(self.errors)}):")
99-
for i, error in enumerate(self.errors, 1):
100-
lines.append(f" {i}. {error}")
101-
102-
if self.warnings:
103-
lines.append(f"\nWarnings ({len(self.warnings)}):")
104-
for i, warning in enumerate(self.warnings, 1):
105-
lines.append(f" {i}. {warning}")
106-
107-
return "\n".join(lines)
108-
10945
class DatagenSpec(BaseModel):
11046
"""Top-level specification for synthetic data generation across one or more tables.
11147

dbldatagen/spec/validation.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
class ValidationResult:
2+
"""Container for validation results that collects errors and warnings during spec validation.
3+
4+
This class accumulates validation issues found while checking a DatagenSpec configuration.
5+
It distinguishes between errors (which prevent data generation) and warnings (which
6+
indicate potential issues but don't block generation).
7+
8+
.. note::
9+
Validation passes if there are no errors, even if warnings are present
10+
"""
11+
12+
def __init__(self) -> None:
13+
"""Initialize an empty ValidationResult with no errors or warnings."""
14+
self.errors: list[str] = []
15+
self.warnings: list[str] = []
16+
17+
def add_error(self, message: str) -> None:
18+
"""Add an error message to the validation results.
19+
20+
Errors indicate critical issues that will prevent successful data generation.
21+
22+
:param message: Descriptive error message explaining the validation failure
23+
"""
24+
self.errors.append(message)
25+
26+
def add_warning(self, message: str) -> None:
27+
"""Add a warning message to the validation results.
28+
29+
Warnings indicate potential issues or non-optimal configurations that may affect
30+
data generation but won't prevent it from completing.
31+
32+
:param message: Descriptive warning message explaining the potential issue
33+
"""
34+
self.warnings.append(message)
35+
36+
def is_valid(self) -> bool:
37+
"""Check if validation passed without errors.
38+
39+
:returns: True if there are no errors (warnings are allowed), False otherwise
40+
"""
41+
return len(self.errors) == 0
42+
43+
def __str__(self) -> str:
44+
"""Generate a formatted string representation of all validation results.
45+
46+
:returns: Multi-line string containing formatted errors and warnings with counts
47+
"""
48+
lines = []
49+
if self.is_valid():
50+
lines.append("✓ Validation passed successfully")
51+
else:
52+
lines.append("✗ Validation failed")
53+
54+
if self.errors:
55+
lines.append(f"\nErrors ({len(self.errors)}):")
56+
for i, error in enumerate(self.errors, 1):
57+
lines.append(f" {i}. {error}")
58+
59+
if self.warnings:
60+
lines.append(f"\nWarnings ({len(self.warnings)}):")
61+
for i, warning in enumerate(self.warnings, 1):
62+
lines.append(f" {i}. {warning}")
63+
64+
return "\n".join(lines)

tests/test_specs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
ColumnDefinition,
77
UCSchemaTarget,
88
FilePathTarget,
9-
ValidationResult
109
)
10+
from dbldatagen.spec.validation import ValidationResult
11+
1112

1213
class TestValidationResult:
1314
"""Tests for ValidationResult class"""

0 commit comments

Comments
 (0)