Created
April 24, 2022 10:59
-
-
Save xnuinside/3cbf81a1001f82be11a424f4601100fa to your computer and use it in GitHub Desktop.
Example of test with running of generated code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def test_pydantic_models_are_working_as_expected(load_generated_code) -> None: | |
ddl = """ | |
CREATE table user_history ( | |
runid decimal(21) null | |
,job_id decimal(21) null | |
,id varchar(100) not null -- group_id or role_id | |
,user varchar(100) not null | |
,status varchar(10) not null | |
,event_time timestamp not null default now() | |
,comment varchar(1000) not null default 'none' | |
) ; | |
""" | |
result = create_models(ddl, models_type="pydantic")["code"] | |
module = load_generated_code(result) | |
used_model = module.UserHistory( | |
id="group_id", | |
user="user", | |
status="active", | |
) | |
assert used_model | |
os.remove(os.path.abspath(module.__file__)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment