'Test nested includes with alternative tasks and variables.
Variables from outer roles should be inherited, but overridden in inner
roles.'

@patch('ansible.playbook.role.definition.unfrackpath', mock_unfrackpath_noop)
def test_nested_alt_files(self):

    play = Play.load(dict(name='test    play', hosts=['foo'], gather_facts=False, tasks=[{'include_role': 'name=l1    tasks_from=alt    defaults_from=alt'}]), loader=self.loader, variable_manager=self.var_manager)
    tasks = play.compile()
    for (role, task_vars) in self.get_tasks_vars(play, tasks):
        if (role == 'l1'):
            self.assertEqual(task_vars.get('l1_variable'), 'l1-alt')
            self.assertEqual(task_vars.get('l2_variable'), None)
            self.assertEqual(task_vars.get('l3_variable'), None)
            self.assertEqual(task_vars.get('test_variable'), 'l1-alt')
        elif (role == 'l2'):
            self.assertEqual(task_vars.get('l1_variable'), 'l1-alt')
            self.assertEqual(task_vars.get('l2_variable'), 'l2-alt')
            self.assertEqual(task_vars.get('l3_variable'), None)
            self.assertEqual(task_vars.get('test_variable'), 'l2-alt')
        elif (role == 'l3'):
            self.assertEqual(task_vars.get('l1_variable'), 'l1-alt')
            self.assertEqual(task_vars.get('l2_variable'), 'l2-alt')
            self.assertEqual(task_vars.get('l3_variable'), 'l3-alt')
            self.assertEqual(task_vars.get('test_variable'), 'l3-alt')
