| 1 |
import io |
| 2 |
import os |
| 3 |
|
| 4 |
import pytest |
| 5 |
import pyglet |
| 6 |
|
| 7 |
from pyglet.util import DecodeException |
| 8 |
|
| 9 |
test_data_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'data')) |
| 10 |
|
| 11 |
|
| 12 |
def get_test_data_file(path, file_name): |
| 13 |
"""Get a file from the test data directory in an OS independent way. |
| 14 |
|
| 15 |
Supply relative file name as you would in os.path.join(). |
| 16 |
""" |
| 17 |
return os.path.join(test_data_path, path, file_name) |
| 18 |
|
| 19 |
|
| 20 |
def test_load_from_disk(): |
| 21 |
file_path = get_test_data_file('models', 'logo3d.obj') |
| 22 |
scene = pyglet.model.load(file_path) |
| 23 |
assert isinstance(scene, pyglet.model.Scene) |
| 24 |
|
| 25 |
|
| 26 |
def test_load_from_object_str(): |
| 27 |
file_path = get_test_data_file('models', 'logo3d.obj') |
| 28 |
with open(file_path, 'r') as f: |
| 29 |
file_obj = io.StringIO(f.read()) |
| 30 |
scene = pyglet.model.load(file_path, file=file_obj) |
| 31 |
assert isinstance(scene, pyglet.model.Scene) |
| 32 |
|
| 33 |
|
| 34 |
def test_load_from_object_bytes(): |
| 35 |
file_path = get_test_data_file('models', 'logo3d.obj') |
| 36 |
with open(file_path, 'rb') as f: |
| 37 |
file_obj = io.BytesIO(f.read()) |
| 38 |
scene = pyglet.model.load(file_path, file=file_obj) |
| 39 |
assert isinstance(scene, pyglet.model.Scene) |
| 40 |
|
| 41 |
|
| 42 |
def test_no_decoders_available(): |
| 43 |
|
| 44 |
file_path = get_test_data_file('media', 'alert.wav') |
| 45 |
|
| 46 |
with pytest.raises(DecodeException) as e: |
| 47 |
scene = pyglet.model.load(file_path) |
| 48 |
|
| 49 |
|
| 50 |
def test_resource_module(): |
| 51 |
folder_path = os.path.join(test_data_path, 'models') |
| 52 |
pyglet.resource.path.append(folder_path) |
| 53 |
pyglet.resource.reindex() |
| 54 |
|
| 55 |
scene = pyglet.resource.scene('logo3d.obj') |
| 56 |
assert isinstance(scene, pyglet.model.Scene) |