From 301e9d59076112106bcfe9c1eba37863ead6865c Mon Sep 17 00:00:00 2001 From: Vincent Texier <vit@free.fr> Date: Fri, 20 Nov 2020 11:36:11 +0100 Subject: [PATCH] [fix] #59 fix pylint, mypy, format and tests --- duniterpy/api/client.py | 2 +- duniterpy/api/endpoint.py | 10 ++--- duniterpy/constants.py | 6 ++- tests/api/test_endpoints.py | 79 +++++++++++++++++++++++-------------- 4 files changed, 59 insertions(+), 38 deletions(-) diff --git a/duniterpy/api/client.py b/duniterpy/api/client.py index f527548a..d3864f9a 100644 --- a/duniterpy/api/client.py +++ b/duniterpy/api/client.py @@ -515,7 +515,7 @@ class Client: try: result = await response.json() except aiohttp.client_exceptions.ContentTypeError as exception: - logging.error("Response is not a json format") + logging.error("Response is not a json format: %s", exception) # return response to debug... return result diff --git a/duniterpy/api/endpoint.py b/duniterpy/api/endpoint.py index 2afe91d7..34e8139b 100644 --- a/duniterpy/api/endpoint.py +++ b/duniterpy/api/endpoint.py @@ -658,7 +658,7 @@ class GVAEndpoint(Endpoint): def __init__( self, - flags: Optional[str], + flags: str, server: str, ipv4: str, ipv6: str, @@ -690,9 +690,9 @@ class GVAEndpoint(Endpoint): :param inline: Endpoint string :return: """ - m = GVAEndpoint.re_inline.match(inline) + m = cls.re_inline.match(inline) if m is None: - raise MalformedDocumentError(GVAEndpoint.API) + raise MalformedDocumentError(cls.API) flags = m.group(1) server = m.group(2) ipv4 = m.group(3) @@ -723,7 +723,7 @@ class GVAEndpoint(Endpoint): ) if info ] - return GVAEndpoint.API + " " + " ".join(inlined) + return self.API + " " + " ".join(inlined) def conn_handler( self, session: ClientSession, proxy: str = None @@ -769,7 +769,7 @@ class GVAEndpoint(Endpoint): return self.inline() def __eq__(self, other: Any) -> bool: - if not isinstance(other, BMAEndpoint): + if not isinstance(other, self.__class__): return NotImplemented return ( self.server == other.server diff --git a/duniterpy/constants.py b/duniterpy/constants.py index 842900ab..31f458a4 100644 --- a/duniterpy/constants.py +++ b/duniterpy/constants.py @@ -25,8 +25,10 @@ BLOCK_ID_REGEX = "[0-9]+" BLOCK_UID_REGEX = "{block_id_regex}-{block_hash_regex}".format( block_id_regex=BLOCK_ID_REGEX, block_hash_regex=BLOCK_HASH_REGEX ) -CONDITIONS_REGEX = "(&&|\\|\\|| |[()]|(SIG\\({pubkey_regex}\\)|(XHX\\({hash_regex}\\))))*".format( - pubkey_regex=PUBKEY_REGEX, hash_regex=HASH_REGEX +CONDITIONS_REGEX = ( + "(&&|\\|\\|| |[()]|(SIG\\({pubkey_regex}\\)|(XHX\\({hash_regex}\\))))*".format( + pubkey_regex=PUBKEY_REGEX, hash_regex=HASH_REGEX + ) ) IPV4_REGEX = ( "(?:(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][" diff --git a/tests/api/test_endpoints.py b/tests/api/test_endpoints.py index 56813a10..8fc88cf3 100644 --- a/tests/api/test_endpoints.py +++ b/tests/api/test_endpoints.py @@ -1,3 +1,20 @@ +""" +Copyright 2014-2020 Vincent Texier <vit@free.fr> + +DuniterPy is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +DuniterPy is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +""" + import unittest import duniterpy.api.endpoint as endpoint @@ -9,51 +26,53 @@ class TestEndpoint(unittest.TestCase): gva_endpoint = endpoint.GVAEndpoint.from_inline(endpoint_str) - assert gva_endpoint.flags == "" - assert gva_endpoint.server == "test.domain.com" - assert gva_endpoint.ipv4 == "127.0.0.1" - assert gva_endpoint.ipv6 == "2001:0db8:0000:85a3:0000:0000:ac1f:8001" - assert gva_endpoint.port == 10902 - assert gva_endpoint.path == "gva" + self.assertEqual(gva_endpoint.flags, "") + self.assertEqual(gva_endpoint.server, "test.domain.com") + self.assertEqual(gva_endpoint.ipv4, "127.0.0.1") + self.assertEqual(gva_endpoint.ipv6, "2001:0db8:0000:85a3:0000:0000:ac1f:8001") + self.assertEqual(gva_endpoint.port, 10902) + self.assertEqual(gva_endpoint.path, "gva") - assert gva_endpoint.inline() == endpoint_str + self.assertEqual(gva_endpoint.inline(), endpoint_str) endpoint_str = "GVA S test.domain.com 10902 gva" gva_endpoint = endpoint.GVAEndpoint.from_inline(endpoint_str) - assert gva_endpoint.flags == "S" - assert gva_endpoint.server == "test.domain.com" - assert gva_endpoint.ipv4 is None - assert gva_endpoint.ipv6 is None - assert gva_endpoint.port == 10902 - assert gva_endpoint.path == "gva" + self.assertEqual(gva_endpoint.flags, "S") + self.assertEqual(gva_endpoint.server, "test.domain.com") + self.assertEqual(gva_endpoint.ipv4, None) + self.assertEqual(gva_endpoint.ipv6, None) + self.assertEqual(gva_endpoint.port, 10902) + self.assertEqual(gva_endpoint.path, "gva") - assert gva_endpoint.inline() == endpoint_str + self.assertEqual(gva_endpoint.inline(), endpoint_str) def test_gva_subscription(self): endpoint_str = "GVASUB test.domain.com 127.0.0.1 2001:0db8:0000:85a3:0000:0000:ac1f:8001 10902 gva" - gva_endpoint = endpoint.GVAEndpoint.from_inline(endpoint_str) + gvasub_endpoint = endpoint.GVASUBEndpoint.from_inline(endpoint_str) - assert gva_endpoint.flags == "" - assert gva_endpoint.server == "test.domain.com" - assert gva_endpoint.ipv4 == "127.0.0.1" - assert gva_endpoint.ipv6 == "2001:0db8:0000:85a3:0000:0000:ac1f:8001" - assert gva_endpoint.port == 10902 - assert gva_endpoint.path == "gva" + self.assertEqual(gvasub_endpoint.flags, "") + self.assertEqual(gvasub_endpoint.server, "test.domain.com") + self.assertEqual(gvasub_endpoint.ipv4, "127.0.0.1") + self.assertEqual( + gvasub_endpoint.ipv6, "2001:0db8:0000:85a3:0000:0000:ac1f:8001" + ) + self.assertEqual(gvasub_endpoint.port, 10902) + self.assertEqual(gvasub_endpoint.path, "gva") - assert gva_endpoint.inline() == endpoint_str + self.assertEqual(gvasub_endpoint.inline(), endpoint_str) endpoint_str = "GVASUB S test.domain.com 10902 gva" - gva_endpoint = endpoint.GVAEndpoint.from_inline(endpoint_str) + gvasub_endpoint = endpoint.GVASUBEndpoint.from_inline(endpoint_str) - assert gva_endpoint.flags == "S" - assert gva_endpoint.server == "test.domain.com" - assert gva_endpoint.ipv4 is None - assert gva_endpoint.ipv6 is None - assert gva_endpoint.port == 10902 - assert gva_endpoint.path == "gva" + self.assertEqual(gvasub_endpoint.flags, "S") + self.assertEqual(gvasub_endpoint.server, "test.domain.com") + self.assertEqual(gvasub_endpoint.ipv4, None) + self.assertEqual(gvasub_endpoint.ipv6, None) + self.assertEqual(gvasub_endpoint.port, 10902) + self.assertEqual(gvasub_endpoint.path, "gva") - assert gva_endpoint.inline() == endpoint_str + assert gvasub_endpoint.inline(), endpoint_str -- GitLab