Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: Run flake8 (plus various plugins) during tests #111

Merged
merged 9 commits into from
Mar 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'ppb-vector', 'ppb-vector Documentation',
[author], 1)
[author], 1),
]


Expand Down
5 changes: 5 additions & 0 deletions lint-requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
flake8
flake8-bugbear
flake8-commas
flake8-import-order
mypy>=0.670
pep8-naming
4 changes: 4 additions & 0 deletions lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ if [[ "${PYTHON-x}" =~ pypy-* ]]; then
exit 0
fi

run flake8 --version
run flake8 --ignore F403,F405 tests
run flake8 --exclude tests/

run ${PY} -m mypy ppb_vector tests
2 changes: 1 addition & 1 deletion ppb_vector/vector2.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ def truncate(self: Vector, max_length: typing.SupportsFloat) -> Vector:

Note that :py:meth:`vector.scale(max_length) <scale>` is equivalent to
:py:meth:`vector.truncate(max_length) <truncate>` when
:py:meth:`max_length \< vector.length <length>`.
:py:meth:`max_length vector.length <length>`.

>>> Vector2(3, 4).scale(4)
Vector2(2.4, 3.2)
Expand Down
7 changes: 7 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[flake8]
select = C,E,F,I,W,B,B9
ignore = E704
max-line-length = 100

application-import-names = ppb_vector,utils
import-order-style = smarkets
3 changes: 1 addition & 2 deletions tests/test_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ def __init__(self, x, y):


@pytest.mark.skipif(sys.implementation.name != 'cpython',
reason="PyPy optimises __slots__ automatically.",
)
reason="PyPy optimises __slots__ automatically.")
@given(x=floats(), y=floats())
def test_object_size(x, y):
"""Check that Vector2 is 2 times smaller than a naïve version."""
Expand Down
40 changes: 21 additions & 19 deletions tests/test_vector2_rotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,52 +16,51 @@
(Vector2(1, 1), 180, Vector2(-1, -1)),
]


@pytest.mark.parametrize("input, angle, expected", data_exact,
ids=[str(angle) for _, angle, _ in data_exact],
)
ids=[str(angle) for _, angle, _ in data_exact])
def test_exact_rotations(input, angle, expected):
assert input.rotate(angle) == expected
assert input.angle(expected) == angle


# angle (in degrees) -> (sin, cos)
## values from 0 to 45°
## lifted from https://en.wikibooks.org/wiki/Trigonometry/Selected_Angles_Reference
# values from 0 to 45°
# lifted from https://en.wikibooks.org/wiki/Trigonometry/Selected_Angles_Reference
remarkable_angles = {
15: ((sqrt(6) - sqrt(2))/4, (sqrt(6) + sqrt(2))/4),
22.5: (sqrt(2 - sqrt(2))/2, sqrt(2 + sqrt(2))/2),
30: (0.5, sqrt(3)/2),
45: (sqrt(2)/2, sqrt(2)/2),
15: ((sqrt(6) - sqrt(2)) / 4, (sqrt(6) + sqrt(2)) / 4),
22.5: (sqrt(2 - sqrt(2)) / 2, sqrt(2 + sqrt(2)) / 2),
30: (0.5, sqrt(3) / 2),
45: (sqrt(2) / 2, sqrt(2) / 2),
}

## extend up to 90°
# extend up to 90°
remarkable_angles.update({
90 - angle: (cos_t, sin_t)
for angle, (sin_t, cos_t) in remarkable_angles.items()
})

## extend up to 180°
# extend up to 180°
remarkable_angles.update({
angle + 90: (cos_t, -sin_t)
for angle, (sin_t, cos_t) in remarkable_angles.items()
})

## extend up to 360°
# extend up to 360°
remarkable_angles.update({
angle + 180: (-sin_t, -cos_t)
for angle, (sin_t, cos_t) in remarkable_angles.items()
})

## extend to negative angles
# extend to negative angles
remarkable_angles.update({
-angle: (-sin_t, cos_t)
for angle, (sin_t, cos_t) in remarkable_angles.items()
})


@pytest.mark.parametrize("angle, trig", remarkable_angles.items(),
ids=[str(x) for x in remarkable_angles]
)
ids=[str(x) for x in remarkable_angles])
def test_remarkable_angles(angle, trig):
_angle = math.radians(angle)
sin_t, cos_t = trig
Expand All @@ -79,11 +78,14 @@ def test_remarkable_angles(angle, trig):
for (angle, (sin_t, cos_t)) in remarkable_angles.items()
]

data_close_ids = [
f"(1,0).rotate({x})" for x in remarkable_angles
] + [
f"(1,1).rotate({x})" for x in remarkable_angles
]


@pytest.mark.parametrize("input, angle, expected", data_close,
ids=[f"(1,0).rotate({x})" for x in remarkable_angles] +
[f"(1,1).rotate({x})" for x in remarkable_angles],
)
@pytest.mark.parametrize("input, angle, expected", data_close, ids=data_close_ids)
def test_close_rotations(input, angle, expected):
assert input.rotate(angle).isclose(expected)
assert angle_isclose(input.angle(expected), angle)
Expand Down Expand Up @@ -111,7 +113,7 @@ def test_trig_stability(angle):
def test_trig_invariance(angle: float, n: int):
"""Test that cos(θ), sin(θ) ≃ cos(θ + n*360°), sin(θ + n*360°)"""
r_cos, r_sin = Vector2._trig(angle)
n_cos, n_sin = Vector2._trig(angle + 360*n)
n_cos, n_sin = Vector2._trig(angle + 360 * n)

note(f"δcos: {r_cos - n_cos}")
assert isclose(r_cos, n_cos, rel_to=[n / 1e9])
Expand Down
1 change: 1 addition & 0 deletions tests/test_vector2_scalar_multiplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def test_scalar_division(x: Vector2, scalar: float):
assume(abs(scalar) > 1e-100)
assert (x / scalar).isclose((1 / scalar) * x)


@given(x=vectors(), scalar=floats())
def test_scalar_inverse(x: Vector2, scalar: float):
"""Test that (λ * x / λ) ≃ x"""
Expand Down