Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/cmake-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ jobs:
working-directory: ${{ needs.setup.outputs.build_path }}
env:
PERFETTO_HEAP_PROFILE: ${{ github.event.inputs.perfetto-heap-profile || 'false' }}
PERFETTO_CPU_PROFILE: ${{ (github.event.inputs.perfetto-cpu-profile != null && github.event.inputs.perfetto-cpu-profile) || true }}
PERFETTO_CPU_PROFILE:
${{ (github.event.inputs.perfetto-cpu-profile != null && github.event.inputs.perfetto-cpu-profile) || true
}}
run: |
. /entrypoint.sh

Expand Down
50 changes: 28 additions & 22 deletions test/python/pyprovide.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@

from phlex import Variant

_specs = ((-42, np.int32, "ii32"),
(42, np.uint32, "iui32"),
(-27, np.int64, "ii64"),
(27, np.uint64, "iui64"),
(42., np.float32, "if32"),
(-42., np.float64, "if64"),
)
_specs = (
(-42, np.int32, "ii32"),
(42, np.uint32, "iui32"),
(-27, np.int64, "ii64"),
(27, np.uint64, "iui64"),
(42.0, np.float32, "if32"),
(-42.0, np.float64, "if64"),
)

specs = [(False, np.bool_, "ib")]
for x, t, sf in _specs:
specs.append((x, t, sf)) # type: ignore
specs.append((np.array([x], dtype=t), npt.NDArray[t], "v"+sf)) # type: ignore
specs.append((x, t, sf)) # type: ignore
specs.append((np.array([x], dtype=t), npt.NDArray[t], "v" + sf)) # type: ignore


def PHLEX_REGISTER_PROVIDERS(s, config):
Expand All @@ -38,15 +39,17 @@ def PHLEX_REGISTER_PROVIDERS(s, config):
Returns:
None
"""

def new_p(x):
def p(di):
assert 0 <= di.number()
return x

return p

for x, t, sf in specs:
f = Variant(new_p(x), {"di": "data_cell_index", "return": t}, "input_"+sf)
s.provide(f, {"creator": "input_"+sf, "layer": "event", "suffix": sf })
f = Variant(new_p(x), {"di": "data_cell_index", "return": t}, "input_" + sf)
s.provide(f, {"creator": "input_" + sf, "layer": "event", "suffix": sf})

# add a bunch of failures to check error reporting
try:
Expand All @@ -56,43 +59,45 @@ def p(di):
assert "missing required argument" in str(e)

try:

class C:
def __call__(self, di):
pass
s.provide(C(), {"creator": "a", "layer": "b", "suffix": "c" })
def __call__(self, di):
pass

s.provide(C(), {"creator": "a", "layer": "b", "suffix": "c"})
assert not "supposed to be here"
except AttributeError as e:
assert "__name__" in str(e)

try:
s.provide(42, {"creator": "a", "layer": "b", "suffix": "c" })
s.provide(42, {"creator": "a", "layer": "b", "suffix": "c"})
assert not "supposed to be here"
except TypeError as e:
assert "given provider is not callable" in str(e)

try:
s.provide(lambda: 42, {"creator": "a", "layer": "b", "suffix": "c" })
s.provide(lambda: 42, {"creator": "a", "layer": "b", "suffix": "c"})
assert not "supposed to be here"
except TypeError as e:
assert "data_cell_index" in str(e)

try:
f = Variant(lambda di: 42, {"di": "data_cell_index", "return": None}, "f")
s.provide(f, {"creator": "a", "layer": "b", "suffix": "c" })
s.provide(f, {"creator": "a", "layer": "b", "suffix": "c"})
assert not "supposed to be here"
except TypeError as e:
assert "provider must have an output" in str(e)

try:
f = Variant(lambda di: 42, {"di": "data_cell_index", "return": "object"}, "f")
s.provide(f, {"creator": "a", "layer": "b", "suffix": "c" })
s.provide(f, {"creator": "a", "layer": "b", "suffix": "c"})
assert not "supposed to be here"
except TypeError as e:
assert "unsupported output type" in str(e)

try:
f = Variant(lambda di: 42, {"di": "data_cell_index", "return": npt.NDArray[np.bool_]}, "f")
s.provide(f, {"creator": "a", "layer": "b", "suffix": "c" })
s.provide(f, {"creator": "a", "layer": "b", "suffix": "c"})
assert not "supposed to be here"
except TypeError as e:
assert "unsupported collection output type" in str(e)
Expand All @@ -112,12 +117,13 @@ def PHLEX_REGISTER_ALGORITHMS(m, config):
Returns:
None
"""

def new_a(x):
def a(y):
assert y == x

return a

for x, t, sf in specs:
f = Variant(new_a(x), {"y": t, "return": None}, sf+t.__name__)
m.observe(f, input_family=[{"creator": "input_"+sf, "layer": "event"}])

f = Variant(new_a(x), {"y": t, "return": None}, sf + t.__name__)
m.observe(f, input_family=[{"creator": "input_" + sf, "layer": "event"}])
Loading