Skip to content

Commit ebedc2d

Browse files
committed
Test effect templates
1 parent 74834e0 commit ebedc2d

File tree

9 files changed

+56
-11
lines changed

9 files changed

+56
-11
lines changed

demosys/core/finders.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ def __init__(self):
2323
"This is required when using a FileSystemFinder.".format(self.settings_attr)
2424
)
2525
self.paths = getattr(settings, self.settings_attr)
26-
self._cached_paths = {}
2726

2827
def find(self, path: Path):
2928
"""
@@ -35,7 +34,7 @@ def find(self, path: Path):
3534
"""
3635
# Update paths from settings to make them editable runtime
3736
# This is only possible for FileSystemFinders
38-
if self.settings_attr:
37+
if getattr(self, 'settings_attr', None):
3938
self.paths = getattr(settings, self.settings_attr)
4039

4140
path_found = None
@@ -53,13 +52,17 @@ class BaseEffectDirectoriesFinder(BaseFileSystemFinder):
5352
directory = None
5453

5554
def __init__(self):
56-
from demosys.effects.registry import effects
57-
self.paths = list(effects.get_dirs())
55+
pass
5856

5957
def find(self, path: Path):
6058
path = Path(self.directory) / Path(path)
6159
return super().find(path)
6260

61+
@property
62+
def paths(self):
63+
from demosys.effects.registry import effects
64+
return list(effects.get_dirs())
65+
6366

6467
@functools.lru_cache(maxsize=None)
6568
def get_finder(import_path):

demosys/effect_templates/raymarching_simple/effect.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ def __init__(self):
1414
# create plane to fit whole screen
1515
self.plane = geometry.plane.plane_xz(size=(self.window_width, self.window_height), resolution=(10, 10))
1616

17-
@effect.bind_target
1817
def draw(self, time, frametime, target):
1918
self.ctx.enable(moderngl.DEPTH_TEST)
2019

demosys/resources/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def load_pool(self):
3030
Loads all the data files using the configured finders.
3131
"""
3232
for path, data_file in self.file_map.items():
33-
if self.file_map[path] is None:
33+
if data_file is None:
3434
self._load(self.file_meta[path])
3535

3636
def delete(self, obj, destroy=False):
@@ -42,6 +42,7 @@ def delete(self, obj, destroy=False):
4242
if data == obj:
4343
del self.file_map[path]
4444
del self.file_meta[path]
45+
4546
if destroy:
4647
self._destroy(obj)
4748
break

demosys/resources/data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def load_deferred(self, path: str, cls=Data, mode='binary', **kwargs):
107107

108108
def _load(self, meta) -> Data:
109109
"""Internal loader"""
110-
found_path = self._find_last_of(meta.path, list(get_finders()))
110+
found_path = self._find_last_of(meta.path, get_finders())
111111

112112
if not found_path:
113113
raise ImproperlyConfigured("Cannot find data file {}".format(meta.path))

demosys/resources/scenes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def load_deferred(self, path: Union[str, Path], **kwargs) -> SceneMeta:
7272
return meta
7373

7474
def _load(self, meta) -> Scene:
75-
found_path = self._find_last_of(meta.path, list(get_finders()))
75+
found_path = self._find_last_of(meta.path, get_finders())
7676

7777
if not found_path:
7878
raise ImproperlyConfigured("Cannot find scene file {}".format(meta.path))

demosys/resources/shaders.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def load_deferred(self, path: Union[str, Path], **kwargs) -> ShaderMeta:
5656
return meta
5757

5858
def _load(self, meta, reload=False):
59-
found_path = self._find_last_of(meta.path, list(get_finders()))
59+
found_path = self._find_last_of(meta.path, get_finders())
6060

6161
if not found_path:
6262
raise ImproperlyConfigured("Cannot find shader {}".format(meta.path))

demosys/resources/textures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def _load(self, meta):
6363
"""
6464
Loads all the textures using the configured finders.
6565
"""
66-
found_path = self._find_last_of(meta.path, list(get_finders()))
66+
found_path = self._find_last_of(meta.path, get_finders())
6767

6868
if not found_path:
6969
raise ImproperlyConfigured("Cannot find texture {}".format(meta.path))

tests/test_effect_templates.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import os
2+
3+
from demosys.test import DemosysTestCase
4+
from demosys.effects.registry import effects
5+
from demosys.effects import Effect
6+
from demosys.scene import camera
7+
8+
9+
class EffectTemplateTestCase(DemosysTestCase):
10+
11+
def test_templates(self):
12+
templates = self.list_effect_templates()
13+
effects.polulate(templates)
14+
15+
Effect.ctx = self.ctx
16+
Effect.window_aspect = 16 / 9
17+
Effect.window_width = self.window.width
18+
Effect.window_height = self.window.height
19+
Effect.sys_camera = camera.SystemCamera()
20+
21+
for name, config in effects.effects.items():
22+
effect = config.cls()
23+
effect.post_load()
24+
effect.draw(0.0, 1 / 60, self.window.fbo)
25+
26+
self.window.fbo.clear()
27+
28+
def list_effect_templates(self):
29+
dirs = os.listdir(
30+
os.path.join(
31+
os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
32+
'demosys',
33+
'effect_templates'
34+
)
35+
)
36+
return ["demosys.effect_templates.{}".format(d) for d in dirs]

tests/test_resources.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
class ResourceTestCase(DemosysTestCase):
1010

1111
def test_datafiles(self):
12-
"""Loading data files"""
12+
resources.data.flush(destroy=True)
13+
1314
# string and binary data file
1415
data_str = resources.data.load('data.txt', mode="text")
1516
data_bin = resources.data.load('data.bin', mode="binary")
@@ -34,6 +35,8 @@ def test_datafiles(self):
3435
resources.data.load('notfound.bin')
3536

3637
def test_scene(self):
38+
resources.scenes.flush(destroy=True)
39+
3740
scene_obj = resources.scenes.load('cube.obj')
3841
self.assertEqual(len(scene_obj.nodes), 0)
3942
self.assertEqual(len(scene_obj.root_nodes), 1)
@@ -61,6 +64,7 @@ def test_scene(self):
6164

6265
def test_shaders(self):
6366
resources.shaders.flush(destroy=True)
67+
6468
shader1 = resources.shaders.load('vf_pos.glsl')
6569
shader2 = resources.shaders.load('vgf_quads.glsl')
6670
self.assertEqual(resources.shaders.count, 2)
@@ -85,6 +89,8 @@ def test_shaders(self):
8589
resources.shaders.load('notfound.glsl')
8690

8791
def test_textures(self):
92+
resources.textures.flush(destroy=True)
93+
8894
texture1 = resources.textures.load('wood.jpg')
8995
texture2 = resources.textures.load('crate.jpg')
9096
self.assertEqual(resources.textures.count, 2)

0 commit comments

Comments
 (0)