Skip to content

Use Pydantic to generate and validate CodeTF data models#357

Merged
drdavella merged 3 commits intomainfrom
pydantic-codetf
Mar 12, 2024
Merged

Use Pydantic to generate and validate CodeTF data models#357
drdavella merged 3 commits intomainfrom
pydantic-codetf

Conversation

@drdavella
Copy link
Copy Markdown
Member

@drdavella drdavella commented Mar 11, 2024

Overview

Use pydantic to generate and validate CodeTF models

Description

  • Using pydantic is a good way to express data models using type hints and to enable validation
  • This enables straightforward representation of the CodeTF data model and provides JSON generation for free
  • These changes mean our data model is now precisely aligned with the CodeTF spec
  • Now that we have a JSON Schema for CodeTF I added validation for our integration tests: https://github.com/pixee/codemodder-specs/blob/main/codetf.schema.json

@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Passed Quality Gate passed

Issues
1 New issue
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@drdavella drdavella marked this pull request as ready for review March 11, 2024 20:27
import requests


@pytest.fixture(scope="module")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new fixture means every time a test module runs we're making a request. I see this is also defined below, so now both unit tests and integration tests rely on internet connectivity. Just pointing that out.
Do we need it per module, or could this fixture run per test run session only?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@clavedeluna good catch. I did think about making it session scoped but I think we're running unit tests and integration tests in separate workflows so it would run twice anyway.

Comment thread src/codemodder/codetf.py
references: Optional[list[Reference]] = None
properties: Optional[dict] = None
failedFiles: Optional[list[str]] = None
changeset: list[ChangeSet]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this have = []?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I don't think it's strictly necessary since this is a required field but it might be a good idea.

@drdavella drdavella added this pull request to the merge queue Mar 12, 2024
Merged via the queue into main with commit 658bc91 Mar 12, 2024
@drdavella drdavella deleted the pydantic-codetf branch March 12, 2024 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants