-
Notifications
You must be signed in to change notification settings - Fork 322
test: microgen - adds tests to confirm attribute extraction from classes #2315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: microgen - adds tests to confirm attribute extraction from classes #2315
Conversation
daniel-sanche
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, with suggestions
| """ | ||
| class MyClass: | ||
| CLASS_VAR = 123 | ||
| """, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this would probably be more readable using parentheses for the multiline string, to avoid breaking indentation:
pytest.param(
(
"class MyClass:"
" CLASS_VAR = 123",
),
[
{
"class_name": "MyClass",
"methods": [],
"attributes": [{"name": "CLASS_VAR", "type": None}],
}
],
id="class_var_assign",
),
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might also be easier to read/scale if test cases are stored in a yaml file. We did something similar for bigtable here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good idea. I will make a note of this. For now, the priority is to get a complete set of working unit tests, so not gonna jump on this refactor right away.
This PR introduces unit tests for the
CodeAnalyzer's ability to extract class attributes.These tests are located in
test_generate_analyzer.pywithin theTestCodeAnalyzerAttributesclass.
Key Features of the New Tests:
__init__.@pytest.mark.parametrizeto efficiently test differentcode snippets and their expected structural output.
structure using built-in assertion capabilities, after normalizing the attribute
lists for order-independent comparison.
Why this change?
These tests ensure the
CodeAnalyzeraccurately parses Python code to identify class andinstance attributes, which is crucial for the microgenerator's functionality.
Broader Context:
The
CodeAnalyzerand its tests are essential components supporting the development of amicrogenerator for the BigQuery Python SDK. This microgenerator is being created to
automatically generate a centralized
BigQueryClient.The primary goal of this centralized client is to ease the transition for our customers from
the traditional, largely handwritten BigQuery library to the newer GAPIC-generated version. It
aims to provide a unified interface, allowing users to interact with a single
BigQueryClientrather than multiple disparate
*ServiceClientclasses (e.g.,JobServiceClient,TableServiceClient,ModelServiceClient).The
CodeAnalyzerplays a critical role by parsing the existing*ServiceClientclasses toextract structural information (like methods and attributes). This information is then used by
the microgenerator to build the passthrough methods on the centralized
BigQueryClient,ensuring a user experience that remains familiar and convenient for our customers.
These new tests for
CodeAnalyzer's attribute extraction ensure that we are correctlyunderstanding the structure of the underlying service clients, which is fundamental for the
microgenerator to generate a correct and useful
BigQueryClient.