Skip to content

Commit

Permalink
alwaysProvidesOrientation Patch and Test (#300)
Browse files Browse the repository at this point in the history
* 'alwaysProvidesOrientation Patch and Test

* Modified warning message.
  • Loading branch information
Eric-Vin authored Aug 15, 2024
1 parent 50eed8e commit e6b5f26
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/scenic/syntax/veneer.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@
import sys
import traceback
import typing
import warnings

from scenic.core.distributions import (
Distribution,
Expand Down Expand Up @@ -1521,6 +1522,11 @@ def alwaysProvidesOrientation(region):
return sample.orientation is not None or sample is nowhere
except RejectionException:
return False
except Exception as e:
warnings.warn(
f"While sampling internally to determine if a random region provides an orientation, the following exception was raised: {repr(e)}"
)
return False


def OffsetBy(offset):
Expand Down
16 changes: 16 additions & 0 deletions tests/syntax/test_specifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1198,3 +1198,19 @@ def test_color():
ego = new Object with color (1,1,1,1,1)
"""
sampleEgoFrom(program)


# alwaysProvidesOrientation
def test_alwaysProvidesOrientation_exception():
with pytest.warns(UserWarning):
compileScenic(
"""
from scenic.core.distributions import distributionFunction
@distributionFunction
def foo(bar):
assert False
new Object in foo(Range(0,1))
"""
)

0 comments on commit e6b5f26

Please sign in to comment.