text: # Refer from airflow:
  #
  #   airflow/tests/decorators/test_python.py
  #
  # with the following license:
  #
  # 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 datetime import timedelta
  import unittest
  
  from airflow.models import DAG, DagRun, TaskInstance as TI
  from airflow.utils import timezone
  from airflow.utils.session import create_session
  
  DEFAULT_DATE = timezone.datetime(2016, 1, 1)
  END_DATE = timezone.datetime(2016, 1, 2)
  INTERVAL = timedelta(hours=12)
  FROZEN_NOW = timezone.datetime(2016, 1, 2, 12, 1, 1)
  
  TI_CONTEXT_ENV_VARS = [
      'AIRFLOW_CTX_DAG_ID',
      'AIRFLOW_CTX_TASK_ID',
      'AIRFLOW_CTX_EXECUTION_DATE',
      'AIRFLOW_CTX_DAG_RUN_ID',
  ]
  
  
  class TestPythonBase(unittest.TestCase):
      """Base test class for TestPythonOperator classes"""
  
      name = 'python_dag_on_vineyard'
  
      @classmethod
      def setUpClass(cls):
          super().setUpClass()
  
          with create_session() as session:
              session.query(DagRun).delete()
              session.query(TI).delete()
  
      def setUp(self):
          super().setUp()
          self.dag = DAG(self.name, default_args={'owner': 'airflow', 'start_date': DEFAULT_DATE})
          self.addCleanup(self.dag.clear)
          self.clear_run()
          self.addCleanup(self.clear_run)
  
      def tearDown(self):
          super().tearDown()
  
          with create_session() as session:
              session.query(DagRun).delete()
              session.query(TI).delete()
  
      def clear_run(self):
          self.run = False
  