Unit test mock object issue?

Trying to fix my issue tracked at https://github.com/ansible/ansible/issues/11320. From what I can tell v2 does not process includes properly.

So I started playing around with test/playbook/test_playbook.py, here’s a simple test.

`
def test_basic_include(self):
fake_loader = DictDataLoader({
“test_file.yml”:“”"

  • include: good.yml
  • hosts: all
    “”",
    })
    p = Playbook.load(“test_file.yml”, loader=fake_loader)

`

My first question: That is a valid playbook, right?

Test suite throws AnsibleParserError: ERROR! playbooks must be a list of plays

Debugging I’m finding the problem in tests/mock/init.py:load_from_file()

ansible/test/units/mock/loader.py(38)load_from_file() -> if path in self._file_mapping: (Epdb) type(path) <type 'unicode'> (Epdb) type(self._file_mapping) <type 'dict'> (Epdb) p path u'good.yml' (Epdb) p self._file_mapping {'test_file.yml': '\n - include: good.yml\n - hosts: all\n '} (Epdb) self._file_mapping.keys() ['test_file.yml']

So looking for u’good.yml’ inside a dict() is going to return False and the include file is not going to be loaded.

Some interactive python shows this logic.

`

file_mapping={‘test_file.yml’: '\n - include: good.yml\n - hosts: all\n ‘}
type(file_mapping)
<type ‘dict’>
path=u’good.yml’
type(path)
<type ‘unicode’>
path in file_mapping
False
`

So I do not know if the problem is in the mock object or the parser?

The include seems to be working correctly, failing when the file is
not there also seems to be correct behavior. I'm not sure what you
expected here.

That would be a correct playbook if good.yml contained a valid play.

I understand your view point.

I would expect something more specific like “… file good.yml does not exist or is not readable …” and then chain the exception to “ERROR! playbooks must be a list of plays”