Travis CI: Identify our ten slowest pytests (#2350)

* Travis CI: Identify our ten slowest tests

https://howchoo.com/g/mtblodnjzjc/how-to-measure-unit-test-execution-times-in-pytest helps us to find the individual tests that are slowing down our Travis CI checks.

* fixup! Format Python code with psf/black push

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
Christian Clauss 2020-08-25 15:47:06 +02:00 committed by GitHub
parent 402ba7f49a
commit e77600638d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 20 deletions

View File

@ -15,6 +15,6 @@ before_script:
- pip install -r requirements.txt # fast fail on black, flake8, validate_filenames
script:
- mypy --ignore-missing-imports .
- pytest --doctest-modules --cov-report=term-missing:skip-covered --cov=. .
- pytest --doctest-modules --durations=10 --cov-report=term-missing:skip-covered --cov=. .
after_success:
- scripts/build_directory_md.py 2>&1 | tee DIRECTORY.md

View File

@ -27,9 +27,11 @@ def subtract(matrix_a: List[list], matrix_b: List[list]) -> List[list]:
>>> subtract([[1,2.5],[3,4]],[[2,3],[4,5.5]])
[[-1, -0.5], [-1, -1.5]]
"""
if _check_not_integer(matrix_a)\
and _check_not_integer(matrix_b)\
and _verify_matrix_sizes(matrix_a, matrix_b):
if (
_check_not_integer(matrix_a)
and _check_not_integer(matrix_b)
and _verify_matrix_sizes(matrix_a, matrix_b)
):
return [[i - j for i, j in zip(*m)] for m in zip(matrix_a, matrix_b)]
@ -60,8 +62,9 @@ def multiply(matrix_a: List[list], matrix_b: List[list]) -> List[list]:
f"Cannot multiply matrix of dimensions ({rows[0]},{cols[0]}) "
f"and ({rows[1]},{cols[1]})"
)
return [[sum(m * n for m, n in zip(i, j)) for j in zip(*matrix_b)]
for i in matrix_a]
return [
[sum(m * n for m, n in zip(i, j)) for j in zip(*matrix_b)] for i in matrix_a
]
def identity(n: int) -> List[list]:
@ -95,8 +98,8 @@ def minor(matrix: List[list], row: int, column: int) -> List[list]:
>>> minor([[1, 2], [3, 4]], 1, 1)
[[1]]
"""
minor = matrix[: row] + matrix[row + 1:]
return [row[:column] + row[column + 1:] for row in minor]
minor = matrix[:row] + matrix[row + 1 :]
return [row[:column] + row[column + 1 :] for row in minor]
def determinant(matrix: List[list]) -> int:
@ -109,8 +112,10 @@ def determinant(matrix: List[list]) -> int:
if len(matrix) == 1:
return matrix[0][0]
return sum(x * determinant(minor(matrix, 0, i)) * (-1) ** i
for i, x in enumerate(matrix[0]))
return sum(
x * determinant(minor(matrix, 0, i)) * (-1) ** i
for i, x in enumerate(matrix[0])
)
def inverse(matrix: List[list]) -> List[list]:
@ -124,9 +129,10 @@ def inverse(matrix: List[list]) -> List[list]:
if det == 0:
return None
matrix_minor = [[determinant(minor(matrix, i, j))
for j in range(len(matrix))]
for i in range(len(matrix))]
matrix_minor = [
[determinant(minor(matrix, i, j)) for j in range(len(matrix))]
for i in range(len(matrix))
]
cofactors = [
[x * (-1) ** (row + col) for col, x in enumerate(matrix_minor[row])]
@ -159,14 +165,10 @@ def _verify_matrix_sizes(matrix_a: List[list], matrix_b: List[list]) -> Tuple[li
def main():
matrix_a = [[12, 10], [3, 9]]
matrix_b = [[3, 4], [7, 4]]
matrix_c = [[11, 12, 13, 14], [21, 22, 23, 24],
[31, 32, 33, 34], [41, 42, 43, 44]]
matrix_c = [[11, 12, 13, 14], [21, 22, 23, 24], [31, 32, 33, 34], [41, 42, 43, 44]]
matrix_d = [[3, 0, 2], [2, 0, -2], [0, 1, 1]]
print(
f"Add Operation, {add(matrix_a, matrix_b) = } \n")
print(
f"Multiply Operation, {multiply(matrix_a, matrix_b) = } \n",
)
print(f"Add Operation, {add(matrix_a, matrix_b) = } \n")
print(f"Multiply Operation, {multiply(matrix_a, matrix_b) = } \n",)
print(f"Identity: {identity(5)}\n")
print(f"Minor of {matrix_c} = {minor(matrix_c, 1, 2)} \n")
print(f"Determinant of {matrix_b} = {determinant(matrix_b)} \n")