betodealmeida commented on a change in pull request #17655: URL: https://github.com/apache/superset/pull/17655#discussion_r765158437
########## File path: tests/unit_tests/dataframe_test.py ########## @@ -0,0 +1,55 @@ +# 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. +# pylint: disable=unused-argument, import-outside-toplevel +from superset.dataframe import df_to_records +from superset.typing import DbapiDescription + + +def test_df_to_records(app_context: None) -> None: + from superset.db_engine_specs import BaseEngineSpec + from superset.result_set import SupersetResultSet + + data = [("a1", "b1", "c1"), ("a2", "b2", "c2")] + cursor_descr: DbapiDescription = [ + (column, "string", None, None, None, None, False) for column in ("a", "b", "c") + ] + results = SupersetResultSet(data, cursor_descr, BaseEngineSpec) + df = results.to_pandas_df() + + assert df_to_records(df) == [ + {"a": "a1", "b": "b1", "c": "c1"}, + {"a": "a2", "b": "b2", "c": "c2"}, + ] + + +def test_js_max_int(app_context: None) -> None: + from superset.db_engine_specs import BaseEngineSpec Review comment: Yeah, these imports need to be done inside an `app_context`, otherwise they fail: ```python >>> from superset.db_engine_specs import BaseEngineSpec Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/beto/Projects/incubator-superset/superset/db_engine_specs/__init__.py", line 43, in <module> from superset.db_engine_specs.base import BaseEngineSpec File "/Users/beto/Projects/incubator-superset/superset/db_engine_specs/base.py", line 61, in <module> from superset.models.sql_lab import Query File "/Users/beto/Projects/incubator-superset/superset/models/__init__.py", line 17, in <module> from . import ( File "/Users/beto/Projects/incubator-superset/superset/models/alerts.py", line 53, in <module> class Alert(Model, AuditMixinNullable): File "/Users/beto/Projects/incubator-superset/superset/models/alerts.py", line 66, in Alert owners = relationship(security_manager.user_model, secondary=alert_owner) File "/Users/beto/.pyenv/versions/superset/lib/python3.8/site-packages/werkzeug/local.py", line 347, in __getattr__ return getattr(self._get_current_object(), name) AttributeError: 'NoneType' object has no attribute 'user_model' >>> ``` The `app_context` fixture will do the initialization needed for the import. This way, it works when ran inside the test, but fails as a top-level import. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
