Skip to content

Commit ea9f3c4

Browse files
author
NefAI
committed
fix: flatc fallback and skip custom-op test when test_lib missing
- _flatbuffer: when FLATC_EXECUTABLE is set but path does not exist (e.g. placeholder /path/to/flatc), fall back to 'flatc' on PATH so serialization tests pass without editing the environment. - test_passes: skip test_to_out_variant_none_output when my_awesome_3rdparty_ns awesome_op is unavailable (test_lib not loaded under pytest).
1 parent e489b15 commit ea9f3c4

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

exir/_serialize/_flatbuffer.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ def _run_flatc(args: Sequence[str]) -> None:
197197
else:
198198
# Expect the `flatc` tool to be on the system path or set as an env var.
199199
flatc_path = os.getenv("FLATC_EXECUTABLE")
200+
if flatc_path and not os.path.isfile(flatc_path):
201+
# Env set to a path that doesn't exist (e.g. placeholder); use PATH.
202+
flatc_path = "flatc"
200203
if not flatc_path:
201204
flatc_path = "flatc"
202205
subprocess.run([flatc_path] + list(args), check=True)

exir/tests/test_passes.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,15 @@ def collect_ops(gm: torch.fx.GraphModule):
115115
return ops
116116

117117

118+
def _has_awesome_op_out() -> bool:
119+
"""True if test_lib is loaded and my_awesome_3rdparty_ns.awesome_op is available."""
120+
try:
121+
getattr(torch.ops.my_awesome_3rdparty_ns, "awesome_op").out
122+
return True
123+
except AttributeError:
124+
return False
125+
126+
118127
lib = Library("DO_NOT_USE_TEST_ONLY", "DEF")
119128

120129
lib.define("foo(Tensor self) -> (Tensor, Tensor)")
@@ -351,6 +360,10 @@ def forward(self, x: torch.Tensor) -> torch.Tensor:
351360
# TODO(angelayi): Add a utility function that verifies a model is in
352361
# the edge dialect
353362

363+
@unittest.skipIf(
364+
not _has_awesome_op_out(),
365+
"test_lib not loaded (my_awesome_3rdparty_ns.awesome_op unavailable)",
366+
)
354367
def test_to_out_variant_none_output(self) -> None:
355368
class CompositeModel(torch.nn.Module):
356369
def __init__(self, _weight):

0 commit comments

Comments
 (0)