Chore: fix linting on tests

This commit is contained in:
olliemath 2021-07-27 23:48:50 +01:00
parent bec70d15db
commit a3b822899f
14 changed files with 26 additions and 32 deletions

View File

@ -59,7 +59,7 @@ class AliasFieldsTest(unittest.TestCase):
# Check that NO_VALUE can be assigned to a field # Check that NO_VALUE can be assigned to a field
instance.str_field = NO_VALUE instance.str_field = NO_VALUE
# Check that NO_VALUE can be assigned when creating a new instance # Check that NO_VALUE can be assigned when creating a new instance
instance2 = ModelWithAliasFields(**instance.to_dict()) ModelWithAliasFields(**instance.to_dict())
class ModelWithAliasFields(Model): class ModelWithAliasFields(Model):

View File

@ -1,6 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import unittest
from clickhouse_orm.engines import * from clickhouse_orm.engines import *
from clickhouse_orm.models import BufferModel from clickhouse_orm.models import BufferModel

View File

@ -44,7 +44,7 @@ class CompressedFieldsTestCase(unittest.TestCase):
) )
instance = CompressedModel(**kwargs) instance = CompressedModel(**kwargs)
self.database.insert([instance]) self.database.insert([instance])
for name, value in kwargs.items(): for name in kwargs:
self.assertEqual(kwargs[name], getattr(instance, name)) self.assertEqual(kwargs[name], getattr(instance, name))
def test_string_conversion(self): def test_string_conversion(self):
@ -106,8 +106,8 @@ class CompressedFieldsTestCase(unittest.TestCase):
) )
) )
lines = r.splitlines() lines = r.splitlines()
field_names = parse_tsv(lines[0]) parse_tsv(lines[0])
field_types = parse_tsv(lines[1]) parse_tsv(lines[1])
data = [tuple(parse_tsv(line)) for line in lines[2:]] data = [tuple(parse_tsv(line)) for line in lines[2:]]
self.assertListEqual( self.assertListEqual(
data, data,

View File

@ -26,14 +26,14 @@ class ConstraintsTest(unittest.TestCase):
[PersonWithConstraints(first_name="Mike", last_name="Caruzo", birthday="2100-01-01", height=1.66)] [PersonWithConstraints(first_name="Mike", last_name="Caruzo", birthday="2100-01-01", height=1.66)]
) )
self.assertEqual(e.code, 469) self.assertEqual(e.code, 469)
self.assertTrue("Constraint `birthday_in_the_past`" in e.message) self.assertTrue("Constraint `birthday_in_the_past`" in str(e))
with self.assertRaises(ServerError) as e: with self.assertRaises(ServerError) as e:
self.database.insert( self.database.insert(
[PersonWithConstraints(first_name="Mike", last_name="Caruzo", birthday="1970-01-01", height=3)] [PersonWithConstraints(first_name="Mike", last_name="Caruzo", birthday="1970-01-01", height=3)]
) )
self.assertEqual(e.code, 469) self.assertEqual(e.code, 469)
self.assertTrue("Constraint `max_height`" in e.message) self.assertTrue("Constraint `max_height`" in str(e))
class PersonWithConstraints(Person): class PersonWithConstraints(Person):

View File

@ -199,7 +199,7 @@ class DatabaseTestCase(TestCaseWithData):
self.assertEqual(exc.code, 81) self.assertEqual(exc.code, 81)
self.assertTrue(exc.message.startswith("Database db_not_here doesn't exist")) self.assertTrue(exc.message.startswith("Database db_not_here doesn't exist"))
# Create and delete the db twice, to ensure db_exists gets updated # Create and delete the db twice, to ensure db_exists gets updated
for i in range(2): for _ in range(2):
# Now create the database - should succeed # Now create the database - should succeed
db.create_database() db.create_database()
self.assertTrue(db.db_exists) self.assertTrue(db.db_exists)
@ -284,7 +284,7 @@ class DatabaseTestCase(TestCaseWithData):
try: try:
list(model.objects_in(self.database)[:10]) list(model.objects_in(self.database)[:10])
except ServerError as e: except ServerError as e:
if "Not enough privileges" in e.message: if "Not enough privileges" in str(e):
pass pass
else: else:
raise raise

View File

@ -15,7 +15,7 @@ class DecimalFieldsTest(unittest.TestCase):
self.database.create_table(DecimalModel) self.database.create_table(DecimalModel)
except ServerError as e: except ServerError as e:
# This ClickHouse version does not support decimals yet # This ClickHouse version does not support decimals yet
raise unittest.SkipTest(e.message) raise unittest.SkipTest(str(e))
def tearDown(self): def tearDown(self):
self.database.drop_database() self.database.drop_database()
@ -78,11 +78,11 @@ class DecimalFieldsTest(unittest.TestCase):
# Go over all valid combinations # Go over all valid combinations
for precision in range(1, 39): for precision in range(1, 39):
for scale in range(0, precision + 1): for scale in range(0, precision + 1):
f = DecimalField(precision, scale) DecimalField(precision, scale)
# Some invalid combinations # Some invalid combinations
for precision, scale in [(0, 0), (-1, 7), (7, -1), (39, 5), (20, 21)]: for precision, scale in [(0, 0), (-1, 7), (7, -1), (39, 5), (20, 21)]:
with self.assertRaises(AssertionError): with self.assertRaises(AssertionError):
f = DecimalField(precision, scale) DecimalField(precision, scale)
def test_min_max(self): def test_min_max(self):
# In range # In range

View File

@ -1,6 +1,6 @@
import logging import logging
import unittest import unittest
from datetime import date, datetime, timedelta, tzinfo from datetime import date, datetime, timedelta
from decimal import Decimal from decimal import Decimal
from ipaddress import IPv4Address, IPv6Address from ipaddress import IPv4Address, IPv6Address
@ -39,8 +39,8 @@ class FuncsTestCase(TestCaseWithData):
self.assertEqual(result[0].value, expected_value) self.assertEqual(result[0].value, expected_value)
return result[0].value if result else None return result[0].value if result else None
except ServerError as e: except ServerError as e:
if "Unknown function" in e.message: if "Unknown function" in str(e):
logging.warning(e.message) logging.warning(str(e))
return # ignore functions that don't exist in the used ClickHouse version return # ignore functions that don't exist in the used ClickHouse version
raise raise
@ -54,8 +54,8 @@ class FuncsTestCase(TestCaseWithData):
self.assertEqual(result[0].value, expected_value) self.assertEqual(result[0].value, expected_value)
return result[0].value if result else None return result[0].value if result else None
except ServerError as e: except ServerError as e:
if "Unknown function" in e.message: if "Unknown function" in str(e):
logging.warning(e.message) logging.warning(str(e))
return # ignore functions that don't exist in the used ClickHouse version return # ignore functions that don't exist in the used ClickHouse version
raise raise
@ -449,7 +449,7 @@ class FuncsTestCase(TestCaseWithData):
self._test_func(F.tryBase64Decode(":-)")) self._test_func(F.tryBase64Decode(":-)"))
except ServerError as e: except ServerError as e:
# ClickHouse version that doesn't support these functions # ClickHouse version that doesn't support these functions
raise unittest.SkipTest(e.message) raise unittest.SkipTest(str(e))
def test_replace_functions(self): def test_replace_functions(self):
haystack = "hello" haystack = "hello"

View File

@ -1,8 +1,5 @@
import datetime
import unittest import unittest
import pytz
from clickhouse_orm.database import Database from clickhouse_orm.database import Database
from clickhouse_orm.engines import * from clickhouse_orm.engines import *
from clickhouse_orm.fields import * from clickhouse_orm.fields import *

View File

@ -17,6 +17,7 @@ class IPFieldsTest(unittest.TestCase):
def test_ipv4_field(self): def test_ipv4_field(self):
if self.database.server_version < (19, 17): if self.database.server_version < (19, 17):
raise unittest.SkipTest("ClickHouse version too old") raise unittest.SkipTest("ClickHouse version too old")
# Create a model # Create a model
class TestModel(Model): class TestModel(Model):
i = Int16Field() i = Int16Field()
@ -39,6 +40,7 @@ class IPFieldsTest(unittest.TestCase):
def test_ipv6_field(self): def test_ipv6_field(self):
if self.database.server_version < (19, 17): if self.database.server_version < (19, 17):
raise unittest.SkipTest("ClickHouse version too old") raise unittest.SkipTest("ClickHouse version too old")
# Create a model # Create a model
class TestModel(Model): class TestModel(Model):
i = Int16Field() i = Int16Field()

View File

@ -1,6 +1,6 @@
import os
# Add tests to path so that migrations will be importable # Add tests to path so that migrations will be importable
import logging
import os
import sys import sys
import unittest import unittest
from enum import Enum from enum import Enum
@ -13,9 +13,6 @@ from clickhouse_orm.models import BufferModel, Constraint, Index, Model
sys.path.append(os.path.dirname(__file__)) sys.path.append(os.path.dirname(__file__))
import logging
logging.basicConfig(level=logging.DEBUG, format="%(message)s") logging.basicConfig(level=logging.DEBUG, format="%(message)s")
logging.getLogger("requests").setLevel(logging.WARNING) logging.getLogger("requests").setLevel(logging.WARNING)

View File

@ -30,7 +30,7 @@ class ModelTestCase(unittest.TestCase):
float_field=3.14, float_field=3.14,
) )
instance = SimpleModel(**kwargs) instance = SimpleModel(**kwargs)
for name, value in kwargs.items(): for name in kwargs:
self.assertEqual(kwargs[name], getattr(instance, name)) self.assertEqual(kwargs[name], getattr(instance, name))
def test_assignment_error(self): def test_assignment_error(self):

View File

@ -1,7 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import unittest import unittest
from datetime import date, datetime from datetime import date, datetime
from decimal import Decimal
from enum import Enum from enum import Enum
from logging import getLogger from logging import getLogger

View File

@ -25,9 +25,9 @@ class ReadonlyTestCase(TestCaseWithData):
self.database.drop_database() self.database.drop_database()
self._check_db_readonly_err(cm.exception, drop_table=True) self._check_db_readonly_err(cm.exception, drop_table=True)
except ServerError as e: except ServerError as e:
if e.code == 192 and e.message.startswith("Unknown user"): # ClickHouse version < 20.3 if e.code == 192 and str(e).startswith("Unknown user"): # ClickHouse version < 20.3
raise unittest.SkipTest('Database user "%s" is not defined' % username) raise unittest.SkipTest('Database user "%s" is not defined' % username)
elif e.code == 516 and e.message.startswith( elif e.code == 516 and str(e).startswith(
"readonly: Authentication failed" "readonly: Authentication failed"
): # ClickHouse version >= 20.3 ): # ClickHouse version >= 20.3
raise unittest.SkipTest('Database user "%s" is not defined' % username) raise unittest.SkipTest('Database user "%s" is not defined' % username)
@ -66,7 +66,7 @@ class ReadonlyTestCase(TestCaseWithData):
def test_nonexisting_readonly_database(self): def test_nonexisting_readonly_database(self):
with self.assertRaises(DatabaseException) as cm: with self.assertRaises(DatabaseException) as cm:
db = Database("dummy", readonly=True) Database("dummy", readonly=True)
self.assertEqual(str(cm.exception), "Database does not exist, and cannot be created under readonly connection") self.assertEqual(str(cm.exception), "Database does not exist, and cannot be created under readonly connection")

View File

@ -17,6 +17,7 @@ class UUIDFieldsTest(unittest.TestCase):
def test_uuid_field(self): def test_uuid_field(self):
if self.database.server_version < (18, 1): if self.database.server_version < (18, 1):
raise unittest.SkipTest("ClickHouse version too old") raise unittest.SkipTest("ClickHouse version too old")
# Create a model # Create a model
class TestModel(Model): class TestModel(Model):
i = Int16Field() i = Int16Field()