-
-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Assets 2: Chained assets #436
Changes from all commits
5bdadaf
574d913
d69e22e
9ee8f63
de570d8
7401145
b7394b4
3550570
e5facf2
7546077
611e19d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,10 @@ | |
from ppb import GameEngine, BaseScene | ||
import ppb.events | ||
import ppb.assetlib | ||
from ppb.assetlib import DelayedThreadExecutor, Asset, AssetLoadingSystem | ||
from ppb.assetlib import ( | ||
DelayedThreadExecutor, Asset, AssetLoadingSystem, BackgroundMixin, | ||
ChainingMixin, AbstractAsset, | ||
) | ||
from ppb.testutils import Failer | ||
|
||
|
||
|
@@ -181,3 +184,63 @@ def test_timeout(clean_assets): | |
|
||
with pytest.raises(concurrent.futures.TimeoutError): | ||
a.load(timeout=0.1) | ||
|
||
|
||
def test_chained(clean_assets): | ||
class Const(BackgroundMixin, AbstractAsset): | ||
def __init__(self, value): | ||
self.value = value | ||
self._start() | ||
|
||
def _background(self): | ||
return self.value | ||
|
||
class Concat(ChainingMixin, AbstractAsset): | ||
def __init__(self, delimiter, *values): | ||
self.delimiter = delimiter | ||
self.values = values | ||
self._start(*values) | ||
|
||
def _background(self): | ||
return self.delimiter.join(a.load() for a in self.values) | ||
|
||
a = Concat( | ||
' ', | ||
Const("spam"), Const("eggs"), Const("foo"), Const("bar"), | ||
) | ||
engine = GameEngine( | ||
AssetTestScene, basic_systems=[AssetLoadingSystem, Failer], | ||
fail=lambda e: False, message=None, run_time=1, | ||
) | ||
with engine: | ||
engine.start() | ||
|
||
assert a.load() == "spam eggs foo bar" | ||
|
||
|
||
def test_chained_big(clean_assets): | ||
class Concat(ChainingMixin, AbstractAsset): | ||
def __init__(self, delimiter, *values): | ||
self.delimiter = delimiter | ||
self.values = values | ||
self._start(*values) | ||
|
||
def _background(self): | ||
return self.delimiter.join(a.load() for a in self.values) | ||
|
||
a = Concat( | ||
b'\n', | ||
*( | ||
Asset(f"ppb/{fname}") | ||
for fname in ppb.vfs.iterdir('ppb') | ||
if ppb.vfs.exists(f"ppb/{fname}") | ||
) | ||
) | ||
engine = GameEngine( | ||
AssetTestScene, basic_systems=[AssetLoadingSystem, Failer], | ||
fail=lambda e: False, message=None, run_time=1, | ||
) | ||
with engine: | ||
engine.start() | ||
|
||
assert a.load(timeout=5) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure what this is intended to test? Just that all of these workers are loaded in less than 5 seconds? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's so that if the chaining deadlocks, the test fails instead of pytest just sitting. (Yes, this happened quite a bit in development.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is kind of magical, can we get a comment that this is essentially a threaded string.join so folks at least get the intent?