Applying black formatting

- Fixing flake8 configuration to agree with black
- Adding black validation check to github actions
This commit is contained in:
Jacob Alexander
2021-10-01 11:00:22 -07:00
parent 5dade41aeb
commit 6e7fffd7de
51 changed files with 2536 additions and 1837 deletions

View File

@@ -7,7 +7,18 @@ from random import choice
MAKES = ["Toyota", "GM", "Ford", "Honda", "Tesla"]
MODELS = ["Camry", "Prius", "Volt", "Accord", "Leaf", "Model S"]
COLORS = ["black", "white", "red", "green", "blue", "cyan", "magenta", "yellow", "silver"]
COLORS = [
"black",
"white",
"red",
"green",
"blue",
"cyan",
"magenta",
"yellow",
"silver",
]
def random_car(car):
car.make = choice(MAKES)
@@ -17,7 +28,7 @@ def random_car(car):
car.seats = 2 + rand_int(6)
car.doors = 2 + rand_int(3)
for wheel in car.init('wheels', 4):
for wheel in car.init("wheels", 4):
wheel.diameter = 25 + rand_int(15)
wheel.airPressure = 30 + rand_double(20)
wheel.snowTires = rand_int(16) == 0
@@ -27,7 +38,7 @@ def random_car(car):
car.height = 54 + rand_int(48)
car.weight = car.length * car.width * car.height // 200
engine = car.init('engine')
engine = car.init("engine")
engine.horsepower = 100 * rand_int(400)
engine.cylinders = 4 + 2 * rand_int(3)
engine.cc = 800 + rand_int(10000)
@@ -42,6 +53,7 @@ def random_car(car):
car.cupHolders = rand_int(12)
car.hasNavSystem = rand_bool()
def calc_value(car):
result = 0
@@ -57,9 +69,9 @@ def calc_value(car):
result += engine.horsepower * 40
if engine.usesElectric:
if engine.usesGas:
result += 5000
result += 5000
else:
result += 3000
result += 3000
result += 100 if car.hasPowerWindows else 0
result += 200 if car.hasPowerSteering else 0
@@ -70,11 +82,12 @@ def calc_value(car):
return result
class Benchmark:
def __init__(self, compression):
self.Request = carsales_capnp.ParkingLot.new_message
self.Response = carsales_capnp.TotalValue.new_message
if compression == 'packed':
if compression == "packed":
self.from_bytes_request = carsales_capnp.ParkingLot.from_bytes_packed
self.from_bytes_response = carsales_capnp.TotalValue.from_bytes_packed
self.to_bytes = lambda x: x.to_bytes_packed()
@@ -85,17 +98,17 @@ class Benchmark:
def setup(self, request):
result = 0
for car in request.init('cars', rand_int(200)):
random_car(car)
result += calc_value(car)
for car in request.init("cars", rand_int(200)):
random_car(car)
result += calc_value(car)
return result
def handle(self, request, response):
result = 0
for car in request.cars:
result += calc_value(car)
result += calc_value(car)
response.amount = result
def check(self, response, expected):
return response.amount == expected
return response.amount == expected