tests: fix some pylint warnings & errors

This commit is contained in:
Benjamin Renard 2021-11-03 17:06:37 +01:00
parent 9d611284ef
commit 439a1e9b33
2 changed files with 12 additions and 10 deletions

View file

@ -1,3 +1,4 @@
# pylint: disable=missing-function-docstring
""" Tests on opening hours helpers """
import datetime

View file

@ -1,3 +1,4 @@
# pylint: disable=redefined-outer-name,missing-function-docstring,protected-access
""" Tests on opening hours helpers """
import pytest
@ -5,6 +6,7 @@ import pytest
from mylib.pgsql import PgDB
class FakePsycopg2Cursor:
""" Fake Psycopg2 cursor """
def __init__(self, expected_sql, expected_params, expected_return, expected_just_try, expected_exception):
self.expected_sql = expected_sql
@ -33,6 +35,7 @@ class FakePsycopg2Cursor:
class FakePsycopg2:
""" Fake Psycopg2 connection """
expected_sql = None
expected_params = None
@ -55,7 +58,7 @@ class FakePsycopg2:
self._check_just_try()
assert len(arg) == 1 and isinstance(arg[0], str)
if self.expected_exception:
raise Exception("set_client_encoding(%s): Expected exception", arg[0])
raise Exception("set_client_encoding(%s): Expected exception" % arg[0])
return self.expected_return
def cursor(self):
@ -75,7 +78,7 @@ class FakePsycopg2:
def _check_just_try(self):
if self.just_try:
assert false, "May not be executed in just try mode"
assert False, "May not be executed in just try mode"
def fake_psycopg2_connect(**kwargs):
return FakePsycopg2(**kwargs)
@ -87,7 +90,7 @@ def fake_psycopg2_connect_just_try(**kwargs):
@pytest.fixture
def test_pgdb():
return PgDB('127.0.0.1', 'user', 'password', 'dbname')
return PgDB('127.0.0.1', 'user', 'password', 'dbname')
@pytest.fixture
def fake_pgdb(mocker):
@ -109,18 +112,18 @@ def fake_connected_just_try_pgdb(fake_just_try_pgdb):
fake_just_try_pgdb.connect()
return fake_just_try_pgdb
def generate_mock_args(expected_args=(), expected_kwargs=dict(), expected_return=True):
def generate_mock_args(expected_args=(), expected_kwargs=dict(), expected_return=True): # pylint: disable=dangerous-default-value
def mock_args(*args, **kwargs):
assert args == expected_args, "Invalid call args:\n %s\nMay be:\n %s" % (args, expected_args)
assert kwargs == expected_kwargs, "Invalid call kwargs:\n %s\nMay be:\n %s" % (kwargs, expected_kwargs)
return expected_return
return mock_args
def mock_doSQL_just_try(self, sql, params=None):
def mock_doSQL_just_try(self, sql, params=None): # pylint: disable=unused-argument
assert False, "doSQL() may not be executed in just try mode"
def generate_mock_doSQL(expected_sql, expected_params=dict(), expected_return=True):
def mock_doSQL(self, sql, params=None):
def generate_mock_doSQL(expected_sql, expected_params=dict(), expected_return=True): # pylint: disable=dangerous-default-value
def mock_doSQL(self, sql, params=None): # pylint: disable=unused-argument
assert sql == expected_sql, "Invalid generated SQL query:\n '%s'\nMay be:\n '%s'" % (sql, expected_sql)
assert params == expected_params, "Invalid generated params:\n %s\nMay be:\n %s" % (params, expected_params)
return expected_return
@ -325,9 +328,7 @@ def test_connect(mocker, test_pgdb):
host=test_pgdb.host,
password=test_pgdb.pwd
)
def mock_psycopg2_connect(**kwargs):
assert expected_kwargs == kwargs
mocker.patch(
'psycopg2.connect',
generate_mock_args(