Skip to content

Commit 20db964

Browse files
committed
working test wireup
1 parent 3aca7f3 commit 20db964

File tree

5 files changed

+117
-10
lines changed

5 files changed

+117
-10
lines changed

dbldatagen/spec/compat.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# This module acts as a compatibility layer for Pydantic V1 and V2.
2+
3+
try:
4+
# This will succeed on environments with Pydantic V2.x
5+
# It imports the V1 API that is bundled within V2.
6+
from pydantic.v1 import BaseModel, Field, validator, constr
7+
8+
except ImportError:
9+
# This will be executed on environments with only Pydantic V1.x
10+
from pydantic import BaseModel, Field, validator, constr
11+
12+
# In your application code, do this:
13+
# from .compat import BaseModel
14+
# NOT this:
15+
# from pydantic import BaseModel
16+
17+
# FastAPI Notes
18+
# https://github.com/fastapi/fastapi/blob/master/fastapi/_compat.py

dbldatagen/spec/generator.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
from .compat import BaseModel
2+
from typing import Dict, Optional, Union, Any
3+
4+
5+
# class ColumnDefinition(BaseModel):
6+
# name: str
7+
# type: Optional[DbldatagenBasicType] = None
8+
# primary: bool = False
9+
# options: Optional[Dict[str, Any]] = {}
10+
# nullable: Optional[bool] = False
11+
# omit: Optional[bool] = False
12+
# baseColumn: Optional[str] = "id"
13+
# baseColumnType: Optional[str] = "auto"
14+
15+
# @model_validator(mode="after")
16+
# def check_constraints(self):
17+
# if self.primary:
18+
# if "min" in self.options or "max" in self.options:
19+
# raise ValueError(
20+
# f"Primary column '{self.name}' cannot have min/max options.")
21+
# if self.nullable:
22+
# raise ValueError(
23+
# f"Primary column '{self.name}' cannot be nullable.")
24+
# if self.primary and self.type is None:
25+
# raise ValueError(
26+
# f"Primary column '{self.name}' must have a type defined.")
27+
# return self
28+
29+
30+
# class TableDefinition(BaseModel):
31+
# number_of_rows: int
32+
# partitions: Optional[int] = None
33+
# columns: List[ColumnDefinition]
34+
35+
36+
# class DatagenSpec(BaseModel):
37+
# tables: Dict[str, TableDefinition]
38+
# output_destination: Optional[Union[UCSchemaTarget, FilePathTarget]] = None
39+
# generator_options: Optional[Dict[str, Any]] = {}
40+
# intended_for_databricks: Optional[bool] = None
41+
42+
43+
44+
# def display_all_tables(self):
45+
# for table_name, table_def in self.tables.items():
46+
# print(f"Table: {table_name}")
47+
48+
# if self.output_destination:
49+
# output = f"{self.output_destination}"
50+
# display(HTML(f"<strong>Output destination:</strong> {output}"))
51+
# else:
52+
# message = (
53+
# "<strong>Output destination:</strong> "
54+
# "<span style='color: red; font-weight: bold;'>None</span><br>"
55+
# "<span style='color: gray;'>Set it using the <code>output_destination</code> "
56+
# "attribute on your <code>DatagenSpec</code> object "
57+
# "(e.g., <code>my_spec.output_destination = UCSchemaTarget(...)</code>).</span>"
58+
# )
59+
# display(HTML(message))
60+
61+
# df = pd.DataFrame([col.dict() for col in table_def.columns])
62+
# try:
63+
# display(df)
64+
# except NameError:
65+
# print(df.to_string())
66+
67+
68+
class DatagenSpec(BaseModel):
69+
name: str

makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ clean:
88

99
.venv/bin/python:
1010
pip install hatch
11-
hatch env create
11+
hatch env create test-pydantic.pydantic==1.10.6-v1
1212

1313
dev: .venv/bin/python
1414
@hatch run which python
@@ -20,7 +20,7 @@ fmt:
2020
hatch run fmt
2121

2222
test:
23-
hatch run test
23+
hatch run test-pydantic:test
2424

2525
test-coverage:
2626
make test && open htmlcov/index.html

pyproject.toml

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,31 @@ dependencies = [
106106
]
107107

108108
python="3.10"
109-
110-
# store virtual env as the child of this folder. Helps VSCode (and PyCharm) to run better
111109
path = ".venv"
112110

113111
[tool.hatch.envs.default.scripts]
114112
test = "pytest tests/ -n 10 --cov --cov-report=html --timeout 600 --durations 20"
115-
fmt = ["ruff check . --fix",
116-
"mypy .",
117-
"pylint --output-format=colorized -j 0 dbldatagen tests"]
118-
verify = ["ruff check .",
119-
"mypy .",
120-
"pylint --output-format=colorized -j 0 dbldatagen tests"]
113+
fmt = [
114+
"ruff check . --fix",
115+
"mypy .",
116+
"pylint --output-format=colorized -j 0 dbldatagen tests"
117+
]
118+
verify = [
119+
"ruff check .",
120+
"mypy .",
121+
"pylint --output-format=colorized -j 0 dbldatagen tests"
122+
]
123+
124+
125+
[tool.hatch.envs.test-pydantic]
126+
template = "default"
127+
matrix = [
128+
{ pydantic_version = ["1.10.6", "2.8.2"] }
129+
]
130+
extra-dependencies = [
131+
"pydantic=={matrix:pydantic_version}"
132+
]
133+
121134

122135
# Ruff configuration - replaces flake8, isort, pydocstyle, etc.
123136
[tool.ruff]

tests/test_spec.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from dbldatagen.spec.generator import DatagenSpec
2+
3+
def test_spec():
4+
spec = DatagenSpec(name="test_spec")
5+
assert spec.name == "test_spec"
6+
7+

0 commit comments

Comments
 (0)