def test_should_read_scene_data():
    blend = BlenderFile('fixtures/test1.blend')

    worlds = blend.list('World')
    assert worlds.file is blend, 'World file is not blend'
    assert len(worlds) == 1, 'Test blend should have one world'

    world = worlds.find_by_name('TestWorld')
    assert world.file is blend
    assert isinstance(world, worlds.object)
    assert world.VERSION == blend.header.version
    assert len(world.mtex) == 18
    assert world.aodist > 12.8999 and world.aodist < 12.90001
    assert world.id.name[0:11] == b'WOTestWorld'

    scenes = blend.list('Scene')
    assert len(scenes) == 1, 'Test blend should have one scene'

    rctfs = blend.list('rctf')
    pytest.raises(BlenderFileReadException, rctfs.find_by_name,
                  'blah')  # rctf object do not have a name
    pytest.raises(BlenderFileReadException, blend.list,
                  'foos')  # foos is not a valid structure
    pytest.raises(
        KeyError, worlds.find_by_name,
        'BOO')  # There are no worlds by the name of BOO in the blend file

    blend.close()
def test_open_blend_file_28():
    blend = BlenderFile('fixtures/test_blender28.blend')

    head = blend.header
    assert 'VersionInfo(major=2, minor=8, rev=0)', repr(head.version)
    assert BlenderFile.Arch.X64, head.arch
    assert BlenderFile.Endian.Little, head.endian

    blend.close()
def test_should_read_scene_data_28():
    blend = BlenderFile('fixtures/test_blender28.blend')

    worlds = blend.list('World')
    assert worlds.file is blend, 'World file is not blend'
    assert len(worlds) == 1, 'Test blend should have one world'

    scenes = blend.list('Scene')
    assert len(scenes) == 1, 'Test blend should have one scene'

    blend.close()
def test_blend_struct_lookup():
    blend = BlenderFile('fixtures/test1.blend')

    scene_index = blend.index.type_names.index('Scene')
    float_index = blend.index.type_names.index('float')
    bad_index = 983742

    struct = blend._struct_lookup(scene_index)
    assert struct.index == scene_index, 'Struct index is not scene index'

    pytest.raises(BlenderFileReadException, blend._struct_lookup, float_index)
    pytest.raises(BlenderFileReadException, blend._struct_lookup, 983742)

    blend.close()
def test_cache_lookup():
    blend = BlenderFile('fixtures/test1.blend')
    v = blend.header.version

    worlds = blend.list('World')

    assert BlenderObjectFactory.CACHE[v]['World']() is not None
    assert BlenderObject.CACHE[v]['World']() is not None

    del worlds
    gc.collect()

    assert BlenderObjectFactory.CACHE[v]['World']() is None
    assert BlenderObject.CACHE[v]['World']() is None

    worlds = blend.list('World')
    assert isinstance(worlds, BlenderObjectFactory)
    assert BlenderObjectFactory.CACHE[v]['World']() is not None
    assert BlenderObject.CACHE[v]['World']() is not None

    blend.close()