def test_get_engine_node_internal(tmpdir, engine_json, expected_error):

    if engine_json:
        engine_json_content = json.dumps(engine_json,
                                         sort_keys=True,
                                         separators=(',', ': '),
                                         indent=4)
        tmpdir.ensure('dev', dir=True)
        tmpdir.join('dev/engine.json').write(engine_json_content)

    try:
        fake_context = unit_test.FakeContext(str(tmpdir.realpath()), False)
        fake_context.path = fake_context.srcnode
        lumberyard.get_engine_node(fake_context)
    except expected_error:
        pass
def test_get_engine_node_external(tmpdir, external_engine_json,
                                  ext_engine_subpath, expected_error):

    tmp_working_path = str(tmpdir.realpath())
    c = os.path.join(tmp_working_path, os.path.normpath(ext_engine_subpath))
    b = os.path.normpath(c)
    tmp_working_engine_path = os.path.realpath(b)

    if ext_engine_subpath.startswith('..'):
        json_external_engine_path = ext_engine_subpath
    else:
        json_external_engine_path = tmp_working_engine_path

    engine_json = {
        'ExternalEnginePath': json_external_engine_path,
        'FileVersion': 1,
        'LumberyardVersion': '0.0.0.0',
        'LumberyardCopyrightYear': 2019
    }

    rel_path = os.path.relpath(tmp_working_engine_path, tmp_working_path)
    tmpdir.ensure(rel_path, dir=True)

    engine_json_content = json.dumps(engine_json,
                                     sort_keys=True,
                                     separators=(',', ': '),
                                     indent=4)
    tmpdir.ensure('dev', dir=True)
    tmpdir.join('dev/engine.json').write(engine_json_content)

    if external_engine_json:
        external_engine_json_content = json.dumps(external_engine_json,
                                                  sort_keys=True,
                                                  separators=(',', ': '),
                                                  indent=4)
        if rel_path.startswith('..'):
            rel_path = rel_path[3:]

        tmpdir.ensure(rel_path, dir=True)
        tmpdir.join('{}/engine.json'.format(rel_path)).write(
            external_engine_json_content)
    try:
        fake_context = unit_test.FakeContext(tmp_working_path, False)
        fake_context.path = fake_context.srcnode
        lumberyard.get_engine_node(fake_context)
    except expected_error:
        pass