示例#1
0
def test_object_in_requirement():
    scenario = compileScenic("""
        require Object
        ego = Object
    """)
    with pytest.raises(ScenicSyntaxError):
        sampleScene(scenario, maxIterations=1)
示例#2
0
def test_runtime_parse_error_in_requirement():
    scenario = compileScenic("""
        require visible 4
        ego = Object
    """)
    with pytest.raises(ScenicSyntaxError):
        sampleScene(scenario, maxIterations=1)
示例#3
0
def test_polygonal_empty_intersection():
    scenario = compileScenic(
        'r1 = PolygonalRegion([0@0, 10@0, 10@10, 0@10])\n'
        'ego = Object at -10@0, facing Range(-90, 0) deg, with viewAngle 60 deg\n'
        'Object in visible r1, with requireVisible False'
    )
    for i in range(30):
        sampleScene(scenario, maxIterations=1000)
示例#4
0
def test_curb(cached_maps):
    scenario = compileDrivingScenario(
        cached_maps, """
        ego = Car
        spot = OrientedPoint on visible curb
        Car left of spot by 0.25
    """)
    sampleScene(scenario, maxIterations=1000)
示例#5
0
def test_lazy_value_in_requirement_2():
    # Case where the lazy value is detected during requirement evaluation
    scenario = compileScenic(
        'vf = VectorField("Foo", lambda pos: 3 * pos.x)\n'
        'require 0 relative to vf\n'
        'ego = Object\n'
    )
    with pytest.raises(InvalidScenarioError):
        sampleScene(scenario, maxIterations=1)
示例#6
0
def test_behavior_random_argument():
    scenario = compileScenic('behavior Foo(arg):\n'
                             '    take arg\n'
                             'ego = Object with behavior Foo(Range(10, 25))')
    scene = sampleScene(scenario)
    actions1 = sampleEgoActionsFromScene(scene)
    assert 10 <= actions1[0] <= 25
    actions2 = sampleEgoActionsFromScene(scene)
    assert actions1 == actions2
    scene2 = sampleScene(scenario)
    actions3 = sampleEgoActionsFromScene(scene2)
    assert actions1 != actions3
示例#7
0
def test_opendrive(path, cached_maps):
    try:
        # First, try the original .xodr file
        scenario = compileDrivingScenario(cached_maps,
                                          path=path,
                                          code=basicScenario,
                                          useCache=False)
        sampleScene(scenario, maxIterations=1000)
        # Second, try the cached version of the network
        scenario = compileDrivingScenario(cached_maps,
                                          path=path,
                                          code=basicScenario,
                                          useCache=True)
        sampleScene(scenario, maxIterations=1000)
    except TriangulationError:
        pytest.skip('need better triangulation library to run this test')
示例#8
0
def test_elements_at(cached_maps):
    scenario = compileDrivingScenario(
        cached_maps, """
        ego = Car
        posTuple = (ego.position.x, ego.position.y)
        # functions should accept Points, Vectors, and tuples
        for spot in (ego, ego.position, posTuple):
            param element = network.elementAt(spot)
            param road = network.roadAt(spot)
            param lane = network.laneAt(spot)
            param laneSection = network.laneSectionAt(spot)
            param laneGroup = network.laneGroupAt(spot)
            param crossing = network.crossingAt(spot)
            param intersection = network.intersectionAt(spot)
    """)
    scene = sampleScene(scenario, maxIterations=1000)
    ego = scene.egoObject
    for param in ('element', 'road', 'lane', 'laneSection', 'laneGroup',
                  'crossing', 'intersection'):
        val = scene.params[param]
        if val is None:
            with pytest.raises(RejectionException):
                getattr(ego, param)
        else:
            assert val is getattr(ego, param), param
示例#9
0
def test_visible_from_point():
    scenario = compileScenic(
        'x = Point at 300@200, with visibleDistance 2\n'
        'ego = Object visible from x'
    )
    for i in range(30):
        scene = sampleScene(scenario, maxIterations=1)
        assert scene.egoObject.position.distanceTo(Vector(300, 200)) <= 2
示例#10
0
def test_object_expression():
    scenario = compileScenic("""
        v = Uniform((Object at Range(-2,-1) @ 0), Object at Range(1,2) @ 5).position.x
        ego = Object facing v, at 0 @ 10
        require abs(v) > 1.5
    """)
    for i in range(3):
        scene = sampleScene(scenario, maxIterations=50)
        assert len(scene.objects) == 3
示例#11
0
文件: test_basic.py 项目: t27/Scenic
def test_ego_second():
    scenario = compileScenic('Object\n' 'ego = Object at 0 @ -5')
    assert len(scenario.objects) == 2
    obj = scenario.objects[0]
    assert obj is scenario.egoObject
    scene = sampleScene(scenario, maxIterations=1)
    assert len(scene.objects) == 2
    obj = scene.objects[0]
    assert obj is scene.egoObject
示例#12
0
def test_visibility_requirement():
    scenario = compileScenic("""
        ego = Object with visibleDistance 10, with viewAngle 90 deg, facing 45 deg
        other = Object at Range(-10, 10) @ 0
    """)
    xs = [
        sampleScene(scenario, maxIterations=60).objects[1].position.x
        for i in range(60)
    ]
    assert all(-10 <= x <= 0.5 for x in xs)
示例#13
0
文件: test_basic.py 项目: t27/Scenic
def test_noninterference():
    scenario = compileScenic('ego = Object')
    assert len(scenario.objects) == 1
    ego1 = scenario.egoObject
    for i in range(5):
        scene = sampleScene(scenario, maxIterations=1)
    scenario = compileScenic('ego = Object')
    assert len(scenario.objects) == 1
    ego2 = scenario.egoObject
    assert ego1 is not ego2
示例#14
0
def test_caching(cached_maps):
    """Test caching of road networks.

    In particular, make sure that links between network elements and maneuvers
    are properly reconnected after unpickling.
    """
    for cache in (False, True):
        scenario = compileDrivingScenario(
            cached_maps,
            """
            lanes = filter(lambda l: l._successor, network.lanes)
            lane = Uniform(*lanes)
            ego = Car on lane, with foo lane.network.lanes
            Car on ego.lane.successor.centerline, with requireVisible False
            Car on ego.lane.maneuvers[0].endLane.centerline, with requireVisible False
        """,
            useCache=cache,
            path='tests/formats/opendrive/maps/opendrive.org/CulDeSac.xodr')
        sampleScene(scenario, maxIterations=1000)
示例#15
0
def test_in():
    scenario = compileScenic(
        'r = RectangularRegion(100 @ 200, 90 deg, 50, 10)\n'
        'ego = Object in r'
    )
    for i in range(30):
        scene = sampleScene(scenario, maxIterations=1)
        pos = scene.egoObject.position
        assert 95 <= pos.x <= 105
        assert 150 <= pos.y <= 250
        assert scene.egoObject.heading == 0
示例#16
0
def test_multiple_imports(runLocally):
    with runLocally():
        scenario = compileScenic("""
            import helper
            import helper
            ego = Object
            import helper
        """)
        assert len(scenario.objects) == 2
        scene = sampleScene(scenario)
        assert len(scene.objects) == 2
示例#17
0
def test_visible():
    scenario = compileScenic(
        'ego = Object at 100 @ 200, facing -45 deg,\n'
        '             with visibleDistance 10, with viewAngle 90 deg\n'
        'ego = Object visible'
    )
    for i in range(30):
        scene = sampleScene(scenario, maxIterations=50)
        ego, base = scene.objects
        assert ego.position.distanceTo(base.position) <= 10
        assert ego.position.x >= base.position.x
        assert ego.position.y >= base.position.y
示例#18
0
def test_in_heading():
    scenario = compileScenic(
        'r = PolylineRegion([50 @ -50, -20 @ 20])\n'
        'ego = Object on r'
    )
    for i in range(30):
        scene = sampleScene(scenario, maxIterations=1)
        pos = scene.egoObject.position
        assert -20 <= pos.x <= 50
        assert -50 <= pos.y <= 50
        assert pos.x == pytest.approx(-pos.y)
        assert scene.egoObject.heading == pytest.approx(math.radians(45))
示例#19
0
def test_shared_dependency_lazy():
    scenario = compileScenic('vf = VectorField("Foo", lambda pos: 2 * pos.x)\n'
                             'x = Range(0, 1) relative to vf\n'
                             'ego = Object at 1 @ 0, facing x\n'
                             'other = Object at -1 @ 0, facing x')
    for i in range(60):
        scene = sampleScene(scenario, maxIterations=1)
        egoH = scene.objects[0].heading
        assert 2 <= egoH <= 3
        otherH = scene.objects[1].heading
        assert -2 <= otherH <= -1
        assert (egoH - otherH) == pytest.approx(4)
示例#20
0
def test_visible_from_oriented_point():
    scenario = compileScenic(
        'op = OrientedPoint at 100 @ 200, facing 45 deg,\n'
        '                   with visibleDistance 5, with viewAngle 90 deg\n'
        'ego = Object visible from op'
    )
    base = Vector(100, 200)
    for i in range(30):
        scene = sampleScene(scenario, maxIterations=1)
        pos = scene.egoObject.position
        assert pos.distanceTo(base) <= 5
        assert pos.x <= base.x
        assert pos.y >= base.y
示例#21
0
文件: test_basic.py 项目: t27/Scenic
def test_minimal():
    scenario = compileScenic('ego = Object')
    assert len(scenario.objects) == 1
    obj = scenario.objects[0]
    assert type(obj) is Object
    assert obj is scenario.egoObject
    assert len(scenario.params) == 0
    assert len(scenario.requirements) == 0
    scene = sampleScene(scenario, maxIterations=1)
    assert len(scene.objects) == 1
    obj = scene.objects[0]
    assert type(obj) is Object
    assert obj is scene.egoObject
    assert len(scene.params) == 0
示例#22
0
def test_behavior_ordering_default():
    scenario = compileScenic("""
        count = 0
        behavior Foo():
            global count
            count += 1
            take count
        Object with name 'A', with behavior Foo
        Object with name 'B', at 10@0, with behavior Foo
        ego = Object with name 'C', at 20@0, with behavior Foo
    """)
    scene = sampleScene(scenario)
    objsByName = {}
    for obj in scene.objects:
        objsByName[obj.name] = obj
    actions = sampleActionsFromScene(scene, asMapping=True)
    assert len(actions) == 1
    actions = actions[0]
    assert actions[objsByName['C']] == 1
    assert actions[objsByName['A']] == 2
    assert actions[objsByName['B']] == 3
    assert tuple(actions.keys()) == scene.objects
示例#23
0
def test_everywhere():
    scenario = compileScenic('ego = Object with regionContainedIn everywhere')
    sampleScene(scenario, maxIterations=1)