Skip to content

Commit

Permalink
fix: further paramterizing blueprint tests and adding package scope f…
Browse files Browse the repository at this point in the history
…or getCarlaSimulator
  • Loading branch information
abanuelo committed Jul 10, 2024
1 parent 291cf09 commit 47c79f9
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 172 deletions.
25 changes: 19 additions & 6 deletions tests/simulators/carla/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ def checkCarlaPath():

def launchCarlaServer():
CARLA_ROOT = checkCarlaPath()
subprocess.Popen(f"bash {CARLA_ROOT}/CarlaUE4.sh -RenderOffScreen", shell=True)
server_process = subprocess.Popen(
f"bash {CARLA_ROOT}/CarlaUE4.sh -RenderOffScreen", shell=True
)
return server_process


def terminateCarlaServer(server_process):
server_process.terminate()
server_process.wait()


def isCarlaServerRunning(host="localhost", port=2000):
Expand All @@ -34,21 +42,26 @@ def isCarlaServerRunning(host="localhost", port=2000):
return False


@pytest.fixture
@pytest.fixture(scope="package")
def getCarlaSimulator(getAssetPath):
from scenic.simulators.carla import CarlaSimulator

base = getAssetPath("maps/CARLA")

if not isCarlaServerRunning():
server_process = launchCarlaServer()
else:
server_process = None

def _getCarlaSimulator(town):
if not isCarlaServerRunning():
launchCarlaServer()
path = os.path.join(base, town + ".xodr")
simulator = CarlaSimulator(map_path=path, carla_map=town)

return (simulator, town, path)

return _getCarlaSimulator
yield _getCarlaSimulator

if server_process:
terminateCarlaServer(server_process)


def test_throttle(getCarlaSimulator):
Expand Down
204 changes: 38 additions & 166 deletions tests/simulators/carla/test_blueprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,170 +57,42 @@ def model_blueprint(simulator, mapPath, town, modelType, modelName):
assert obj.blueprint == modelName


@pytest.mark.parametrize("modelName", carModels)
def test_car_blueprints(getCarlaSimulator, modelName):
simulator, town, mapPath = getCarlaSimulator("Town01")
model_blueprint(simulator, mapPath, town, "Car", modelName)


@pytest.mark.parametrize("modelName", bicycleModels)
def test_bicycle_blueprints(getCarlaSimulator, modelName):
simulator, town, mapPath = getCarlaSimulator("Town01")
model_blueprint(simulator, mapPath, town, "Bicycle", modelName)


@pytest.mark.parametrize("modelName", motorcycleModels)
def test_motorcycle_blueprints(getCarlaSimulator, modelName):
simulator, town, mapPath = getCarlaSimulator("Town01")
model_blueprint(simulator, mapPath, town, "Motorcycle", modelName)


@pytest.mark.parametrize("modelName", truckModels)
def test_truck_blueprints(getCarlaSimulator, modelName):
simulator, town, mapPath = getCarlaSimulator("Town01")
model_blueprint(simulator, mapPath, town, "Truck", modelName)


@pytest.mark.parametrize("modelName", trashModels)
def test_trash_blueprints(getCarlaSimulator, modelName):
simulator, town, mapPath = getCarlaSimulator("Town01")
model_blueprint(simulator, mapPath, town, "Trash", modelName)


@pytest.mark.parametrize("modelName", coneModels)
def test_cone_blueprints(getCarlaSimulator, modelName):
simulator, town, mapPath = getCarlaSimulator("Town01")
model_blueprint(simulator, mapPath, town, "Cone", modelName)


@pytest.mark.parametrize("modelName", debrisModels)
def test_debris_blueprints(getCarlaSimulator, modelName):
simulator, town, mapPath = getCarlaSimulator("Town01")
model_blueprint(simulator, mapPath, town, "Debris", modelName)


@pytest.mark.parametrize("modelName", vendingMachineModels)
def test_vending_machine_blueprints(getCarlaSimulator, modelName):
simulator, town, mapPath = getCarlaSimulator("Town01")
model_blueprint(simulator, mapPath, town, "VendingMachine", modelName)


@pytest.mark.parametrize("modelName", chairModels)
def test_chair_blueprints(getCarlaSimulator, modelName):
simulator, town, mapPath = getCarlaSimulator("Town01")
model_blueprint(simulator, mapPath, town, "Chair", modelName)


@pytest.mark.parametrize("modelName", busStopModels)
def test_bus_stop_blueprints(getCarlaSimulator, modelName):
simulator, town, mapPath = getCarlaSimulator("Town01")
model_blueprint(simulator, mapPath, town, "BusStop", modelName)


@pytest.mark.parametrize("modelName", advertisementModels)
def test_advertisement_blueprints(getCarlaSimulator, modelName):
simulator, town, mapPath = getCarlaSimulator("Town01")
model_blueprint(simulator, mapPath, town, "Advertisement", modelName)


@pytest.mark.parametrize("modelName", garbageModels)
def test_garbage_blueprints(getCarlaSimulator, modelName):
pytest.importorskip("carla")
simulator, town, mapPath = getCarlaSimulator("Town01")
model_blueprint(simulator, mapPath, town, "Garbage", modelName)


@pytest.mark.parametrize("modelName", containerModels)
def test_container_blueprints(getCarlaSimulator, modelName):
simulator, town, mapPath = getCarlaSimulator("Town01")
model_blueprint(simulator, mapPath, town, "Container", modelName)


@pytest.mark.parametrize("modelName", tableModels)
def test_table_blueprints(getCarlaSimulator, modelName):
simulator, town, mapPath = getCarlaSimulator("Town01")
model_blueprint(simulator, mapPath, town, "Table", modelName)


@pytest.mark.parametrize("modelName", barrierModels)
def test_barrier_blueprints(getCarlaSimulator, modelName):
simulator, town, mapPath = getCarlaSimulator("Town01")
model_blueprint(simulator, mapPath, town, "Barrier", modelName)


@pytest.mark.parametrize("modelName", plantpotModels)
def test_plant_pots_blueprints(getCarlaSimulator, modelName):
simulator, town, mapPath = getCarlaSimulator("Town01")
model_blueprint(simulator, mapPath, town, "PlantPot", modelName)


@pytest.mark.parametrize("modelName", mailboxModels)
def test_mailbox_blueprints(getCarlaSimulator, modelName):
simulator, town, mapPath = getCarlaSimulator("Town01")
model_blueprint(simulator, mapPath, town, "Mailbox", modelName)


@pytest.mark.parametrize("modelName", gnomeModels)
def test_gnome_blueprints(getCarlaSimulator, modelName):
simulator, town, mapPath = getCarlaSimulator("Town01")
model_blueprint(simulator, mapPath, town, "Gnome", modelName)


@pytest.mark.parametrize("modelName", creasedboxModels)
def test_creased_box_blueprints(getCarlaSimulator, modelName):
simulator, town, mapPath = getCarlaSimulator("Town01")
model_blueprint(simulator, mapPath, town, "CreasedBox", modelName)


@pytest.mark.parametrize("modelName", caseModels)
def test_case_blueprints(getCarlaSimulator, modelName):
simulator, town, mapPath = getCarlaSimulator("Town01")
model_blueprint(simulator, mapPath, town, "Case", modelName)


@pytest.mark.parametrize("modelName", boxModels)
def test_box_blueprints(getCarlaSimulator, modelName):
simulator, town, mapPath = getCarlaSimulator("Town01")
model_blueprint(simulator, mapPath, town, "Box", modelName)


@pytest.mark.parametrize("modelName", benchModels)
def test_bench_blueprints(getCarlaSimulator, modelName):
simulator, town, mapPath = getCarlaSimulator("Town01")
model_blueprint(simulator, mapPath, town, "Bench", modelName)


@pytest.mark.parametrize("modelName", barrelModels)
def test_barrel_blueprints(getCarlaSimulator, modelName):
simulator, town, mapPath = getCarlaSimulator("Town01")
model_blueprint(simulator, mapPath, town, "Barrel", modelName)


@pytest.mark.parametrize("modelName", atmModels)
def test_atm_blueprints(getCarlaSimulator, modelName):
simulator, town, mapPath = getCarlaSimulator("Town01")
model_blueprint(simulator, mapPath, town, "ATM", modelName)


@pytest.mark.parametrize("modelName", kioskModels)
def test_kiosk_blueprints(getCarlaSimulator, modelName):
simulator, town, mapPath = getCarlaSimulator("Town01")
model_blueprint(simulator, mapPath, town, "Kiosk", modelName)


@pytest.mark.parametrize("modelName", ironplateModels)
def test_iron_plate_blueprints(getCarlaSimulator, modelName):
simulator, town, mapPath = getCarlaSimulator("Town01")
model_blueprint(simulator, mapPath, town, "IronPlate", modelName)


@pytest.mark.parametrize("modelName", trafficwarningModels)
def test_traffic_warning_blueprints(getCarlaSimulator, modelName):
simulator, town, mapPath = getCarlaSimulator("Town01")
model_blueprint(simulator, mapPath, town, "TrafficWarning", modelName)


@pytest.mark.parametrize("modelName", walkerModels)
def test_pedestrian_blueprints(getCarlaSimulator, modelName):
model_data = {
"Car": carModels,
"Bicycle": bicycleModels,
"Motorcycle": motorcycleModels,
"Truck": truckModels,
"Trash": trashModels,
"Cone": coneModels,
"Debris": debrisModels,
"VendingMachine": vendingMachineModels,
"Chair": chairModels,
"BusStop": busStopModels,
"Advertisement": advertisementModels,
"Garbage": garbageModels,
"Container": containerModels,
"Table": tableModels,
"Barrier": barrierModels,
"PlantPot": plantpotModels,
"Mailbox": mailboxModels,
"Gnome": gnomeModels,
"CreasedBox": creasedboxModels,
"Case": caseModels,
"Box": boxModels,
"Bench": benchModels,
"Barrel": barrelModels,
"ATM": atmModels,
"Kiosk": kioskModels,
"IronPlate": ironplateModels,
"TrafficWarning": trafficwarningModels,
"Pedestrian": walkerModels,
}


@pytest.mark.parametrize(
"modelType, modelName",
[(type, name) for type, names in model_data.items() for name in names],
)
def test_model_blueprints(getCarlaSimulator, modelType, modelName):
simulator, town, mapPath = getCarlaSimulator("Town01")
model_blueprint(simulator, mapPath, town, "Pedestrian", modelName)
model_blueprint(simulator, mapPath, town, modelType, modelName)

0 comments on commit 47c79f9

Please sign in to comment.