From a3b822899f06f76e60a53bce00914e73cdc70fad Mon Sep 17 00:00:00 2001 From: olliemath Date: Tue, 27 Jul 2021 23:48:50 +0100 Subject: [PATCH] Chore: fix linting on tests --- tests/test_alias_fields.py | 2 +- tests/test_buffer.py | 2 -- tests/test_compressed_fields.py | 6 +++--- tests/test_constraints.py | 4 ++-- tests/test_database.py | 4 ++-- tests/test_decimal_fields.py | 6 +++--- tests/test_funcs.py | 12 ++++++------ tests/test_inheritance.py | 3 --- tests/test_ip_fields.py | 2 ++ tests/test_migrations.py | 7 ++----- tests/test_models.py | 2 +- tests/test_querysets.py | 1 - tests/test_readonly.py | 6 +++--- tests/test_uuid_fields.py | 1 + 14 files changed, 26 insertions(+), 32 deletions(-) diff --git a/tests/test_alias_fields.py b/tests/test_alias_fields.py index 710cddb..5b77513 100644 --- a/tests/test_alias_fields.py +++ b/tests/test_alias_fields.py @@ -59,7 +59,7 @@ class AliasFieldsTest(unittest.TestCase): # Check that NO_VALUE can be assigned to a field instance.str_field = NO_VALUE # Check that NO_VALUE can be assigned when creating a new instance - instance2 = ModelWithAliasFields(**instance.to_dict()) + ModelWithAliasFields(**instance.to_dict()) class ModelWithAliasFields(Model): diff --git a/tests/test_buffer.py b/tests/test_buffer.py index 98d5785..526e07d 100644 --- a/tests/test_buffer.py +++ b/tests/test_buffer.py @@ -1,6 +1,4 @@ # -*- coding: utf-8 -*- -import unittest - from clickhouse_orm.engines import * from clickhouse_orm.models import BufferModel diff --git a/tests/test_compressed_fields.py b/tests/test_compressed_fields.py index 8b26227..8387f28 100644 --- a/tests/test_compressed_fields.py +++ b/tests/test_compressed_fields.py @@ -44,7 +44,7 @@ class CompressedFieldsTestCase(unittest.TestCase): ) instance = CompressedModel(**kwargs) self.database.insert([instance]) - for name, value in kwargs.items(): + for name in kwargs: self.assertEqual(kwargs[name], getattr(instance, name)) def test_string_conversion(self): @@ -106,8 +106,8 @@ class CompressedFieldsTestCase(unittest.TestCase): ) ) lines = r.splitlines() - field_names = parse_tsv(lines[0]) - field_types = parse_tsv(lines[1]) + parse_tsv(lines[0]) + parse_tsv(lines[1]) data = [tuple(parse_tsv(line)) for line in lines[2:]] self.assertListEqual( data, diff --git a/tests/test_constraints.py b/tests/test_constraints.py index c2dfa0d..399a154 100644 --- a/tests/test_constraints.py +++ b/tests/test_constraints.py @@ -26,14 +26,14 @@ class ConstraintsTest(unittest.TestCase): [PersonWithConstraints(first_name="Mike", last_name="Caruzo", birthday="2100-01-01", height=1.66)] ) 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: self.database.insert( [PersonWithConstraints(first_name="Mike", last_name="Caruzo", birthday="1970-01-01", height=3)] ) self.assertEqual(e.code, 469) - self.assertTrue("Constraint `max_height`" in e.message) + self.assertTrue("Constraint `max_height`" in str(e)) class PersonWithConstraints(Person): diff --git a/tests/test_database.py b/tests/test_database.py index bb73327..9566a3c 100644 --- a/tests/test_database.py +++ b/tests/test_database.py @@ -199,7 +199,7 @@ class DatabaseTestCase(TestCaseWithData): self.assertEqual(exc.code, 81) self.assertTrue(exc.message.startswith("Database db_not_here doesn't exist")) # 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 db.create_database() self.assertTrue(db.db_exists) @@ -284,7 +284,7 @@ class DatabaseTestCase(TestCaseWithData): try: list(model.objects_in(self.database)[:10]) except ServerError as e: - if "Not enough privileges" in e.message: + if "Not enough privileges" in str(e): pass else: raise diff --git a/tests/test_decimal_fields.py b/tests/test_decimal_fields.py index 245360f..0480609 100644 --- a/tests/test_decimal_fields.py +++ b/tests/test_decimal_fields.py @@ -15,7 +15,7 @@ class DecimalFieldsTest(unittest.TestCase): self.database.create_table(DecimalModel) except ServerError as e: # This ClickHouse version does not support decimals yet - raise unittest.SkipTest(e.message) + raise unittest.SkipTest(str(e)) def tearDown(self): self.database.drop_database() @@ -78,11 +78,11 @@ class DecimalFieldsTest(unittest.TestCase): # Go over all valid combinations for precision in range(1, 39): for scale in range(0, precision + 1): - f = DecimalField(precision, scale) + DecimalField(precision, scale) # Some invalid combinations for precision, scale in [(0, 0), (-1, 7), (7, -1), (39, 5), (20, 21)]: with self.assertRaises(AssertionError): - f = DecimalField(precision, scale) + DecimalField(precision, scale) def test_min_max(self): # In range diff --git a/tests/test_funcs.py b/tests/test_funcs.py index 2d46550..3a1e07e 100644 --- a/tests/test_funcs.py +++ b/tests/test_funcs.py @@ -1,6 +1,6 @@ import logging import unittest -from datetime import date, datetime, timedelta, tzinfo +from datetime import date, datetime, timedelta from decimal import Decimal from ipaddress import IPv4Address, IPv6Address @@ -39,8 +39,8 @@ class FuncsTestCase(TestCaseWithData): self.assertEqual(result[0].value, expected_value) return result[0].value if result else None except ServerError as e: - if "Unknown function" in e.message: - logging.warning(e.message) + if "Unknown function" in str(e): + logging.warning(str(e)) return # ignore functions that don't exist in the used ClickHouse version raise @@ -54,8 +54,8 @@ class FuncsTestCase(TestCaseWithData): self.assertEqual(result[0].value, expected_value) return result[0].value if result else None except ServerError as e: - if "Unknown function" in e.message: - logging.warning(e.message) + if "Unknown function" in str(e): + logging.warning(str(e)) return # ignore functions that don't exist in the used ClickHouse version raise @@ -449,7 +449,7 @@ class FuncsTestCase(TestCaseWithData): self._test_func(F.tryBase64Decode(":-)")) except ServerError as e: # ClickHouse version that doesn't support these functions - raise unittest.SkipTest(e.message) + raise unittest.SkipTest(str(e)) def test_replace_functions(self): haystack = "hello" diff --git a/tests/test_inheritance.py b/tests/test_inheritance.py index 622167f..a326164 100644 --- a/tests/test_inheritance.py +++ b/tests/test_inheritance.py @@ -1,8 +1,5 @@ -import datetime import unittest -import pytz - from clickhouse_orm.database import Database from clickhouse_orm.engines import * from clickhouse_orm.fields import * diff --git a/tests/test_ip_fields.py b/tests/test_ip_fields.py index f5db64e..9b1c9cc 100644 --- a/tests/test_ip_fields.py +++ b/tests/test_ip_fields.py @@ -17,6 +17,7 @@ class IPFieldsTest(unittest.TestCase): def test_ipv4_field(self): if self.database.server_version < (19, 17): raise unittest.SkipTest("ClickHouse version too old") + # Create a model class TestModel(Model): i = Int16Field() @@ -39,6 +40,7 @@ class IPFieldsTest(unittest.TestCase): def test_ipv6_field(self): if self.database.server_version < (19, 17): raise unittest.SkipTest("ClickHouse version too old") + # Create a model class TestModel(Model): i = Int16Field() diff --git a/tests/test_migrations.py b/tests/test_migrations.py index fd226a1..547a803 100644 --- a/tests/test_migrations.py +++ b/tests/test_migrations.py @@ -1,6 +1,6 @@ -import os - # Add tests to path so that migrations will be importable +import logging +import os import sys import unittest from enum import Enum @@ -13,9 +13,6 @@ from clickhouse_orm.models import BufferModel, Constraint, Index, Model sys.path.append(os.path.dirname(__file__)) - -import logging - logging.basicConfig(level=logging.DEBUG, format="%(message)s") logging.getLogger("requests").setLevel(logging.WARNING) diff --git a/tests/test_models.py b/tests/test_models.py index a6a4917..ef78b96 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -30,7 +30,7 @@ class ModelTestCase(unittest.TestCase): float_field=3.14, ) instance = SimpleModel(**kwargs) - for name, value in kwargs.items(): + for name in kwargs: self.assertEqual(kwargs[name], getattr(instance, name)) def test_assignment_error(self): diff --git a/tests/test_querysets.py b/tests/test_querysets.py index d021029..9619b34 100644 --- a/tests/test_querysets.py +++ b/tests/test_querysets.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- import unittest from datetime import date, datetime -from decimal import Decimal from enum import Enum from logging import getLogger diff --git a/tests/test_readonly.py b/tests/test_readonly.py index 9d3174a..98d9c9e 100644 --- a/tests/test_readonly.py +++ b/tests/test_readonly.py @@ -25,9 +25,9 @@ class ReadonlyTestCase(TestCaseWithData): self.database.drop_database() self._check_db_readonly_err(cm.exception, drop_table=True) 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) - elif e.code == 516 and e.message.startswith( + elif e.code == 516 and str(e).startswith( "readonly: Authentication failed" ): # ClickHouse version >= 20.3 raise unittest.SkipTest('Database user "%s" is not defined' % username) @@ -66,7 +66,7 @@ class ReadonlyTestCase(TestCaseWithData): def test_nonexisting_readonly_database(self): 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") diff --git a/tests/test_uuid_fields.py b/tests/test_uuid_fields.py index af17738..9c5c11b 100644 --- a/tests/test_uuid_fields.py +++ b/tests/test_uuid_fields.py @@ -17,6 +17,7 @@ class UUIDFieldsTest(unittest.TestCase): def test_uuid_field(self): if self.database.server_version < (18, 1): raise unittest.SkipTest("ClickHouse version too old") + # Create a model class TestModel(Model): i = Int16Field()