Skip to content

Commit

Permalink
Add Black as part of the linting process (#80)
Browse files Browse the repository at this point in the history
Black is ran by pre-commit hook, and therefore should be ran when
linting as well, otherwise it leads to inconsistencies — which are fixed
by this very CL.
  • Loading branch information
scorphus authored Sep 7, 2023
1 parent 7bc0dd4 commit ff0728f
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/unittest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
- name: Run Unit Tests
run: make unit
- name: Lint
run: make flake pylint
run: make lint
- name: Generate lcov
run: make coverage
- name: Coveralls
Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ coverage:
@coverage report -m --fail-under=52
@coverage lcov

black:
@black . --config pyproject.toml

flake:
@flake8 --config .flake8

pylint:
@pylint remotecv tests

lint: black flake pylint

ci-test:
@if [ "$$LINT_TEST" ]; then $(MAKE) flake; else $(MAKE) unit; fi

Expand Down
2 changes: 1 addition & 1 deletion remotecv/healthcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ def do_GET(self):
self.wfile.write(b"WORKING")

def log_message(self, format, *args): # pylint: disable=redefined-builtin
logging.info(format.replace('\"', ""), *args)
logging.info(format.replace('"', ""), *args)
3 changes: 2 additions & 1 deletion remotecv/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def redis_client():
)

context.metrics.timing(
"worker.redis_connection.time", get_interval(start_time, get_time()),
"worker.redis_connection.time",
get_interval(start_time, get_time()),
)

return client
Expand Down
5 changes: 4 additions & 1 deletion remotecv/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,10 @@ def import_modules():
def main(**params):
"""Runs RemoteCV"""

logging.basicConfig(level=getattr(logging, params["level"].upper()), format=params["format"])
logging.basicConfig(
level=getattr(logging, params["level"].upper()),
format=params["format"],
)

config.backend = params["backend"]
config.redis_host = params["host"]
Expand Down
12 changes: 9 additions & 3 deletions tests/test_face_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,27 @@ def test_should_run_on_images_with_alpha(self):
expect(detection_result[0][3]).to_be_numeric()

def test_should_run_on_images_with_mode_l(self):
detection_result = FaceDetector().detect(create_image("one_face-bw.png"))
detection_result = FaceDetector().detect(
create_image("one_face-bw.png")
)
expect(detection_result[0][0]).to_be_numeric()
expect(detection_result[0][1]).to_be_numeric()
expect(detection_result[0][2]).to_be_numeric()
expect(detection_result[0][3]).to_be_numeric()

def test_should_run_on_images_with_mode_1(self):
detection_result = FaceDetector().detect(create_image("one_face-bw-1.png"))
detection_result = FaceDetector().detect(
create_image("one_face-bw-1.png")
)
expect(detection_result[0][0]).to_be_numeric()
expect(detection_result[0][1]).to_be_numeric()
expect(detection_result[0][2]).to_be_numeric()
expect(detection_result[0][3]).to_be_numeric()

def test_should_run_on_images_with_mode_la(self):
detection_result = FaceDetector().detect(create_image("one_face-bw-la.png"))
detection_result = FaceDetector().detect(
create_image("one_face-bw-la.png")
)
expect(detection_result[0][0]).to_be_numeric()
expect(detection_result[0][1]).to_be_numeric()
expect(detection_result[0][2]).to_be_numeric()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_redis_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

from redis import RedisError

from thumbor.testing import TestCase
from tornado.testing import gen_test
from preggy import expect
from thumbor.testing import TestCase

import remotecv.storages.redis_storage

Expand Down
41 changes: 21 additions & 20 deletions tests/test_result_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@
import json
from unittest import mock

from thumbor.testing import TestCase
from tornado.testing import gen_test
from preggy import expect
from thumbor.testing import TestCase

from remotecv.result_store.redis_store import ResultStore
from remotecv.utils import context, config, redis_client


class RedisStorageTestCase(TestCase):

@gen_test
async def test_should_be_none_when_not_available(self):
config.redis_host = "localhost"
Expand All @@ -34,24 +33,26 @@ async def test_should_be_none_when_not_available(self):
result_store.store("key", points)

value = client.get("thumbor-detector-key")
points_serialized = json.dumps([
{
"x": 1.0,
"y": 2.5,
"height": 2,
"width": 3,
"origin": "",
"z": 6,
},
{
"x": 1.5,
"y": 4.0,
"height": 3,
"width": 4,
"origin": "",
"z": 12,
},
])
points_serialized = json.dumps(
[
{
"x": 1.0,
"y": 2.5,
"height": 2,
"width": 3,
"origin": "",
"z": 6,
},
{
"x": 1.5,
"y": 4.0,
"height": 3,
"width": 4,
"origin": "",
"z": 12,
},
]
)

expect(value).to_equal(points_serialized)

Expand Down

0 comments on commit ff0728f

Please sign in to comment.