Skip to content

Commit

Permalink
style: format code with Autopep8, Black, Go fmt, Gofumpt, isort and Yapf
Browse files Browse the repository at this point in the history
This commit fixes the style issues introduced in 989487f according to the output
from Autopep8, Black, Go fmt, Gofumpt, isort and Yapf.

Details: None
  • Loading branch information
deepsource-autofix[bot] authored Nov 17, 2023
1 parent 989487f commit bbb6b11
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 38 deletions.
47 changes: 24 additions & 23 deletions scripts/benchmark/benchmark_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


class BenchMarker:

TIMEOUT_MINUTES = 1
TIMEOUT_SECONDS = TIMEOUT_MINUTES * 60
AVERAGING_RUNS = 50
Expand All @@ -16,9 +15,13 @@ def __init__(self, start_range=0, end_range=10):
self.range = range(start_range, end_range)
self.plt = plt

def add_function(
self, name, f, color="r", marker="o", hard_limit=None, override=None
):
def add_function(self,
name,
f,
color="r",
marker="o",
hard_limit=None,
override=None):
"""Adds a function to the list of functions to benchmark.
@name - Human Readable name
@f - function
Expand All @@ -27,16 +30,14 @@ def add_function(
@hard_limit - don't execute benchmarks above this tolerance
@override - Use values from a provided array
"""
self.competitors.append(
{
"name": name,
"fn": f,
"color": color,
"marker": marker,
"hard_limit": hard_limit,
"override": override,
}
)
self.competitors.append({
"name": name,
"fn": f,
"color": color,
"marker": marker,
"hard_limit": hard_limit,
"override": override,
})

def benchmark(self, title):
self.title = title
Expand Down Expand Up @@ -80,9 +81,9 @@ def benchmark(self, title):
# ------ BENCHMARK ------
time1 = time.time()
try:
func_timeout.func_timeout(
self.TIMEOUT_SECONDS, roll_fn, args=[r]
)
func_timeout.func_timeout(self.TIMEOUT_SECONDS,
roll_fn,
args=[r])
except (Exception, func_timeout.FunctionTimedOut) as e:
print(f"Err: {c['name']}:{r}")
print("\t", e)
Expand All @@ -101,8 +102,10 @@ def benchmark(self, title):
y.append(tt * 1000)

if y:
plt.plot(shared_x[0: len(y)], y,
color=c["color"], marker=c["marker"])
plt.plot(shared_x[0:len(y)],
y,
color=c["color"],
marker=c["marker"])
print("Result:", y)

# Configuration and Output
Expand All @@ -114,11 +117,9 @@ def benchmark(self, title):
ax = plt.gca()

ax.get_yaxis().set_major_formatter(
matplotlib.ticker.FuncFormatter(lambda x, p: format(int(x), ","))
)
matplotlib.ticker.FuncFormatter(lambda x, p: format(int(x), ",")))
ax.get_xaxis().set_major_formatter(
matplotlib.ticker.FuncFormatter(lambda x, p: format(int(x), ","))
)
matplotlib.ticker.FuncFormatter(lambda x, p: format(int(x), ",")))

legend_labels = [c["name"] for c in self.competitors]
plt.legend(legend_labels)
Expand Down
1 change: 0 additions & 1 deletion scripts/demo/critical_highlights.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def main():
"""Format a Dice Roll"""
# Roll 1.
for _ in range(100):

format_roll("d20+d20")


Expand Down
4 changes: 2 additions & 2 deletions tests/python/test_filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
("10d10f>8", 19, Mock.RETURN_INCREMENTING, 1), # greater than
("10d10f!=1", 54, Mock.RETURN_INCREMENTING, 1), # is not
("10d10f==1", 1, Mock.RETURN_INCREMENTING, 1), # is equal
("10d10f>=8", 27, Mock.RETURN_INCREMENTING, 1), # equal or greater than
("10d10f>=8", 27, Mock.RETURN_INCREMENTING,
1), # equal or greater than
("10d10f<=3", 6, Mock.RETURN_INCREMENTING, 1), # equal or less than
("10d10fis_even", 30, Mock.RETURN_INCREMENTING, 1), # even
("10d10fis_odd", 25, Mock.RETURN_INCREMENTING, 1), # odd
# ("10d10fis_same", 0, Mock.RETURN_INCREMENTING, 1), # same
],
)
def test_filter(r, out, mock, mock_const):

# https://github.com/ianfhunter/GNOLL/issues/216
result, _ = roll(r, mock_mode=mock, mock_const=mock_const, verbose=True)
assert result == out
6 changes: 4 additions & 2 deletions tests/python/test_macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ def test_macro_storage(r, out, mock):
assert result == out


@pytest.mark.parametrize("r,out,mock", [("#MY_DIE=d{A};@MY_DIE", "A", Mock.NO_MOCK)])
@pytest.mark.parametrize("r,out,mock",
[("#MY_DIE=d{A};@MY_DIE", "A", Mock.NO_MOCK)])
def test_macro_usage(r, out, mock):
result, _ = roll(r, mock_mode=mock)
assert result == out


@pytest.mark.skip("Currently no support for rerolling operations like Addition")
@pytest.mark.skip(
"Currently no support for rerolling operations like Addition")
def test_d66():
r = "#DSIXTYSIX=(d6*10)+d6;@DSIXTYSIX"
result, _ = roll(r, mock_mode=Mock.RETURN_CONSTANT, mock_const=3)
Expand Down
5 changes: 2 additions & 3 deletions tests/python/test_simple_sided_dice.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,8 @@ def test_non_rolling_roll():
assert result == 0


@pytest.mark.parametrize(
"r", [("d"), ("d2d"), ("2d2d2"), ("2d2d2d"), ("1d"), ("d-1"), ("-1d-1")]
)
@pytest.mark.parametrize("r", [("d"), ("d2d"), ("2d2d2"), ("2d2d2d"), ("1d"),
("d-1"), ("-1d-1")])
def test_bad_simple_rolls(r):
try:
roll(r)
Expand Down
10 changes: 4 additions & 6 deletions tests/python/test_symbolic_dice.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ def test_symbolic_dice(r, out, mock):
assert result == out


@pytest.mark.parametrize(
"r,out,mock", [("2d{A,B,C,D}", ["D", "D"], Mock.RETURN_CONSTANT)]
)
@pytest.mark.parametrize("r,out,mock",
[("2d{A,B,C,D}", ["D", "D"], Mock.RETURN_CONSTANT)])
def test_multiple_symbolic_dice(r, out, mock):
result, _ = roll(r, mock_mode=mock)
assert result == out
Expand All @@ -41,9 +40,8 @@ def test_long_string(r, out, mock):
assert result == out


@pytest.mark.parametrize(
"r,out,mock", [("2d{2,2,2,2,3}", [2, 2], Mock.RETURN_CONSTANT)]
)
@pytest.mark.parametrize("r,out,mock",
[("2d{2,2,2,2,3}", [2, 2], Mock.RETURN_CONSTANT)])
def test_multiple_numeric_dice(r, out, mock):
result, _ = roll(r, mock_mode=mock)
assert result == out
1 change: 0 additions & 1 deletion tests/python/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def error_handled_by_gnoll(e):


def get_roll():

# We are explicitly using the local module here as we modify the yacc in order to mock our tests.
# This ugly logic is to bypass the fact that you might have the pip package installed
# and thus a name conflict
Expand Down

0 comments on commit bbb6b11

Please sign in to comment.