diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f34156043449a76f26d1969f92e8975979bdc731..5051a8fbe0c8e2056018b126d3247e0a054f0162 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,7 +8,7 @@ repos: hooks: - id: isort - repo: https://github.com/ambv/black - rev: stable + rev: 20.8b1 hooks: - id: black - repo: https://gitlab.com/pycqa/flake8 diff --git a/arkindex_worker/__init__.py b/arkindex_worker/__init__.py index e7c17213f180456119e3c6725f23e0fd7723696f..b74e88890b314ce492612711659c84f01a5a3035 100644 --- a/arkindex_worker/__init__.py +++ b/arkindex_worker/__init__.py @@ -2,6 +2,7 @@ import logging logging.basicConfig( - level=logging.INFO, format="%(asctime)s %(levelname)s/%(name)s: %(message)s", + level=logging.INFO, + format="%(asctime)s %(levelname)s/%(name)s: %(message)s", ) logger = logging.getLogger(__name__) diff --git a/tests/test_elements_worker.py b/tests/test_elements_worker.py index 22d1aaf5a468bb97eb6b73a55b25215b4ac352ff..e66df0f4d93719fbbe56ec16866b2b4d511868c2 100644 --- a/tests/test_elements_worker.py +++ b/tests/test_elements_worker.py @@ -257,13 +257,19 @@ def test_create_sub_element_wrong_type(): with pytest.raises(AssertionError) as e: worker.create_sub_element( - element=elt, type=None, name="0", polygon=[[1, 1], [2, 2], [2, 1], [1, 2]], + element=elt, + type=None, + name="0", + polygon=[[1, 1], [2, 2], [2, 1], [1, 2]], ) assert str(e.value) == "type shouldn't be null and should be of type str" with pytest.raises(AssertionError) as e: worker.create_sub_element( - element=elt, type=1234, name="0", polygon=[[1, 1], [2, 2], [2, 1], [1, 2]], + element=elt, + type=1234, + name="0", + polygon=[[1, 1], [2, 2], [2, 1], [1, 2]], ) assert str(e.value) == "type shouldn't be null and should be of type str" @@ -297,19 +303,28 @@ def test_create_sub_element_wrong_polygon(): with pytest.raises(AssertionError) as e: worker.create_sub_element( - element=elt, type="something", name="0", polygon=None, + element=elt, + type="something", + name="0", + polygon=None, ) assert str(e.value) == "polygon shouldn't be null and should be of type list" with pytest.raises(AssertionError) as e: worker.create_sub_element( - element=elt, type="something", name="O", polygon="not a polygon", + element=elt, + type="something", + name="O", + polygon="not a polygon", ) assert str(e.value) == "polygon shouldn't be null and should be of type list" with pytest.raises(AssertionError) as e: worker.create_sub_element( - element=elt, type="something", name="O", polygon=[[1, 1], [2, 2]], + element=elt, + type="something", + name="O", + polygon=[[1, 1], [2, 2]], ) assert str(e.value) == "polygon should have at least three points" @@ -324,7 +339,10 @@ def test_create_sub_element_wrong_polygon(): with pytest.raises(AssertionError) as e: worker.create_sub_element( - element=elt, type="something", name="O", polygon=[[1], [2], [2], [1]], + element=elt, + type="something", + name="O", + polygon=[[1], [2], [2], [1]], ) assert str(e.value) == "polygon points should be lists of two items" @@ -414,7 +432,10 @@ def test_create_transcription_wrong_element(): worker = ElementsWorker() with pytest.raises(AssertionError) as e: worker.create_transcription( - element=None, text="i am a line", type=TranscriptionType.Line, score=0.42, + element=None, + text="i am a line", + type=TranscriptionType.Line, + score=0.42, ) assert str(e.value) == "element shouldn't be null and should be of type Element" @@ -434,7 +455,10 @@ def test_create_transcription_wrong_type(): with pytest.raises(AssertionError) as e: worker.create_transcription( - element=elt, text="i am a line", type=None, score=0.42, + element=elt, + text="i am a line", + type=None, + score=0.42, ) assert ( str(e.value) == "type shouldn't be null and should be of type TranscriptionType" @@ -442,7 +466,10 @@ def test_create_transcription_wrong_type(): with pytest.raises(AssertionError) as e: worker.create_transcription( - element=elt, text="i am a line", type=1234, score=0.42, + element=elt, + text="i am a line", + type=1234, + score=0.42, ) assert ( str(e.value) == "type shouldn't be null and should be of type TranscriptionType" @@ -466,13 +493,19 @@ def test_create_transcription_wrong_text(): with pytest.raises(AssertionError) as e: worker.create_transcription( - element=elt, text=None, type=TranscriptionType.Line, score=0.42, + element=elt, + text=None, + type=TranscriptionType.Line, + score=0.42, ) assert str(e.value) == "text shouldn't be null and should be of type str" with pytest.raises(AssertionError) as e: worker.create_transcription( - element=elt, text=1234, type=TranscriptionType.Line, score=0.42, + element=elt, + text=1234, + type=TranscriptionType.Line, + score=0.42, ) assert str(e.value) == "text shouldn't be null and should be of type str" @@ -483,7 +516,10 @@ def test_create_transcription_wrong_score(): with pytest.raises(AssertionError) as e: worker.create_transcription( - element=elt, text="i am a line", type=TranscriptionType.Line, score=None, + element=elt, + text="i am a line", + type=TranscriptionType.Line, + score=None, ) assert ( str(e.value) == "score shouldn't be null and should be a float in [0..1] range" @@ -502,7 +538,10 @@ def test_create_transcription_wrong_score(): with pytest.raises(AssertionError) as e: worker.create_transcription( - element=elt, text="i am a line", type=TranscriptionType.Line, score=0, + element=elt, + text="i am a line", + type=TranscriptionType.Line, + score=0, ) assert ( str(e.value) == "score shouldn't be null and should be a float in [0..1] range" @@ -510,7 +549,10 @@ def test_create_transcription_wrong_score(): with pytest.raises(AssertionError) as e: worker.create_transcription( - element=elt, text="i am a line", type=TranscriptionType.Line, score=2.00, + element=elt, + text="i am a line", + type=TranscriptionType.Line, + score=2.00, ) assert ( str(e.value) == "score shouldn't be null and should be a float in [0..1] range" @@ -529,7 +571,10 @@ def test_create_transcription_api_error(responses): with pytest.raises(ErrorResponse): worker.create_transcription( - element=elt, text="i am a line", type=TranscriptionType.Line, score=0.42, + element=elt, + text="i am a line", + type=TranscriptionType.Line, + score=0.42, ) assert len(responses.calls) == 1 @@ -550,7 +595,10 @@ def test_create_transcription(responses): ) worker.create_transcription( - element=elt, text="i am a line", type=TranscriptionType.Line, score=0.42, + element=elt, + text="i am a line", + type=TranscriptionType.Line, + score=0.42, ) assert len(responses.calls) == 1 @@ -570,7 +618,10 @@ def test_create_classification_wrong_element(): worker = ElementsWorker() with pytest.raises(AssertionError) as e: worker.create_classification( - element=None, ml_class="a_class", confidence=0.42, high_confidence=True, + element=None, + ml_class="a_class", + confidence=0.42, + high_confidence=True, ) assert str(e.value) == "element shouldn't be null and should be of type Element" @@ -590,13 +641,19 @@ def test_create_classification_wrong_ml_class(): with pytest.raises(AssertionError) as e: worker.create_classification( - element=elt, ml_class=None, confidence=0.42, high_confidence=True, + element=elt, + ml_class=None, + confidence=0.42, + high_confidence=True, ) assert str(e.value) == "ml_class shouldn't be null and should be of type str" with pytest.raises(AssertionError) as e: worker.create_classification( - element=elt, ml_class=1234, confidence=0.42, high_confidence=True, + element=elt, + ml_class=1234, + confidence=0.42, + high_confidence=True, ) assert str(e.value) == "ml_class shouldn't be null and should be of type str" @@ -607,7 +664,10 @@ def test_create_classification_wrong_confidence(): with pytest.raises(AssertionError) as e: worker.create_classification( - element=elt, ml_class="a_class", confidence=None, high_confidence=True, + element=elt, + ml_class="a_class", + confidence=None, + high_confidence=True, ) assert ( str(e.value) @@ -628,7 +688,10 @@ def test_create_classification_wrong_confidence(): with pytest.raises(AssertionError) as e: worker.create_classification( - element=elt, ml_class="a_class", confidence=0, high_confidence=True, + element=elt, + ml_class="a_class", + confidence=0, + high_confidence=True, ) assert ( str(e.value) @@ -637,7 +700,10 @@ def test_create_classification_wrong_confidence(): with pytest.raises(AssertionError) as e: worker.create_classification( - element=elt, ml_class="a_class", confidence=2.00, high_confidence=True, + element=elt, + ml_class="a_class", + confidence=2.00, + high_confidence=True, ) assert ( str(e.value) @@ -651,7 +717,10 @@ def test_create_classification_wrong_high_confidence(): with pytest.raises(AssertionError) as e: worker.create_classification( - element=elt, ml_class="a_class", confidence=0.42, high_confidence=None, + element=elt, + ml_class="a_class", + confidence=0.42, + high_confidence=None, ) assert ( str(e.value) == "high_confidence shouldn't be null and should be of type bool" @@ -681,7 +750,10 @@ def test_create_classification_api_error(responses): with pytest.raises(ErrorResponse): worker.create_classification( - element=elt, ml_class="a_class", confidence=0.42, high_confidence=True, + element=elt, + ml_class="a_class", + confidence=0.42, + high_confidence=True, ) assert len(responses.calls) == 1 @@ -702,7 +774,10 @@ def test_create_classification(responses): ) worker.create_classification( - element=elt, ml_class="a_class", confidence=0.42, high_confidence=True, + element=elt, + ml_class="a_class", + confidence=0.42, + high_confidence=True, ) assert len(responses.calls) == 1 @@ -801,13 +876,19 @@ def test_create_entity_wrong_corpus(): with pytest.raises(AssertionError) as e: worker.create_entity( - element=elt, name="Bob Bob", type=EntityType.Person, corpus=None, + element=elt, + name="Bob Bob", + type=EntityType.Person, + corpus=None, ) assert str(e.value) == "corpus shouldn't be null and should be of type str" with pytest.raises(AssertionError) as e: worker.create_entity( - element=elt, name="Bob Bob", type=EntityType.Person, corpus=1234, + element=elt, + name="Bob Bob", + type=EntityType.Person, + corpus=1234, ) assert str(e.value) == "corpus shouldn't be null and should be of type str" @@ -847,7 +928,9 @@ def test_create_entity_api_error(responses): worker.configure() elt = Element({"id": "12341234-1234-1234-1234-123412341234"}) responses.add( - responses.POST, "https://arkindex.teklia.com/api/v1/entity/", status=500, + responses.POST, + "https://arkindex.teklia.com/api/v1/entity/", + status=500, ) with pytest.raises(ErrorResponse): diff --git a/worker-{{cookiecutter.slug}}/.pre-commit-config.yaml b/worker-{{cookiecutter.slug}}/.pre-commit-config.yaml index 0d9aaca586e994f1957235e1c086950a46762f9f..f7b5071ddad617da28eb695ecb5618a6fc525459 100644 --- a/worker-{{cookiecutter.slug}}/.pre-commit-config.yaml +++ b/worker-{{cookiecutter.slug}}/.pre-commit-config.yaml @@ -8,7 +8,7 @@ repos: hooks: - id: isort - repo: https://github.com/ambv/black - rev: stable + rev: 20.8b1 hooks: - id: black - repo: https://gitlab.com/pycqa/flake8