potiuk commented on code in PR #30775:
URL: https://github.com/apache/airflow/pull/30775#discussion_r1174318564


##########
scripts/ci/pre_commit/pre_commit_unittest_testcase.py:
##########
@@ -0,0 +1,47 @@
+#!/usr/bin/env python
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from __future__ import annotations
+
+import ast
+import pathlib
+import sys
+
+
+def check_test_file(file: str) -> int:
+    node = ast.parse(pathlib.Path(file).read_text("utf-8"), file)
+
+    found = 0
+    classes = [c for c in node.body if isinstance(c, ast.ClassDef)]
+    for c in classes:
+        # Some classes are returned as an ast.Attribute, some as an ast.Name 
object. Not quite sure why

Review Comment:
   The Name is when you use class directly imported:
   
   ```
   from airflow.providers.common.sql.hooks.sql import DbApiHook 
   class DbApiHookInProvider(DbApiHook):
   ```
   
   
   The Attr is when you are using "module.name" expression - because then from 
the Python syntax point of view you are reading an attribute of a Name defined 
by import.
   
   ```
   from airflow import plugins_manager
   class FakePlugin(plugins_manager.AirflowPlugin):
   ```
   
   Then what you load is effectivally an attribute of loaded 'plugins_manager' 
Name:
   
   ```
   ["Attribute(value=Name(id='plugins_manager', ctx=Load()), 
attr='AirflowPlugin', ctx=Load())"]
   ```
   
   
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to