'Test DAG as a context manager.
When used as a context manager, Operators are automatically added to
the DAG (unless they specifiy a different DAG)'

def test_dag_as_context_manager(self):

    dag = DAG(u'dag', start_date=DEFAULT_DATE, default_args={u'owner': u'owner1'})
    dag2 = DAG(u'dag2', start_date=DEFAULT_DATE, default_args={u'owner': u'owner2'})
    with dag:
        op1 = DummyOperator(task_id=u'op1')
        op2 = DummyOperator(task_id=u'op2', dag=dag2)
    self.assertIs(op1.dag, dag)
    self.assertEqual(op1.owner, u'owner1')
    self.assertIs(op2.dag, dag2)
    self.assertEqual(op2.owner, u'owner2')
    with dag2:
        op3 = DummyOperator(task_id=u'op3')
    self.assertIs(op3.dag, dag2)
    self.assertEqual(op3.owner, u'owner2')
    with dag:
        with dag2:
            op4 = DummyOperator(task_id=u'op4')
        op5 = DummyOperator(task_id=u'op5')
    self.assertIs(op4.dag, dag2)
    self.assertIs(op5.dag, dag)
    self.assertEqual(op4.owner, u'owner2')
    self.assertEqual(op5.owner, u'owner1')
    with DAG(u'creating_dag_in_cm', start_date=DEFAULT_DATE) as dag:
        DummyOperator(task_id=u'op6')
    self.assertEqual(dag.dag_id, u'creating_dag_in_cm')
    self.assertEqual(dag.tasks[0].task_id, u'op6')
