Replace the deprecated assertEquals with assertEqual

This commit is contained in:
Itai Shirav 2018-08-19 18:22:22 +03:00
parent 44d3dcee34
commit 84fc270e0e
18 changed files with 170 additions and 170 deletions

View File

@ -23,9 +23,9 @@ class TestCaseWithData(unittest.TestCase):
def _insert_and_check(self, data, count, batch_size=1000): def _insert_and_check(self, data, count, batch_size=1000):
self.database.insert(data, batch_size=batch_size) self.database.insert(data, batch_size=batch_size)
self.assertEquals(count, self.database.count(Person)) self.assertEqual(count, self.database.count(Person))
for instance in data: for instance in data:
self.assertEquals(self.database, instance.get_database()) self.assertEqual(self.database, instance.get_database())
def _sample_data(self): def _sample_data(self):
for entry in data: for entry in data:

View File

@ -29,13 +29,13 @@ class MaterializedFieldsTest(unittest.TestCase):
' FROM $db.%s ORDER BY alias_date' % ModelWithAliasFields.table_name() ' FROM $db.%s ORDER BY alias_date' % ModelWithAliasFields.table_name()
for model_cls in (ModelWithAliasFields, None): for model_cls in (ModelWithAliasFields, None):
results = list(self.database.select(query, model_cls)) results = list(self.database.select(query, model_cls))
self.assertEquals(len(results), 1) self.assertEqual(len(results), 1)
self.assertEquals(results[0].date_field, instance.date_field) self.assertEqual(results[0].date_field, instance.date_field)
self.assertEquals(results[0].int_field, instance.int_field) self.assertEqual(results[0].int_field, instance.int_field)
self.assertEquals(results[0].str_field, instance.str_field) self.assertEqual(results[0].str_field, instance.str_field)
self.assertEquals(results[0].alias_int, instance.int_field) self.assertEqual(results[0].alias_int, instance.int_field)
self.assertEquals(results[0].alias_str, instance.str_field) self.assertEqual(results[0].alias_str, instance.str_field)
self.assertEquals(results[0].alias_date, instance.date_field) self.assertEqual(results[0].alias_date, instance.date_field)
def test_assignment_error(self): def test_assignment_error(self):
# I can't prevent assigning at all, in case db.select statements with model provided sets model fields. # I can't prevent assigning at all, in case db.select statements with model provided sets model fields.

View File

@ -27,19 +27,19 @@ class ArrayFieldsTest(unittest.TestCase):
query = 'SELECT * from $db.modelwitharrays ORDER BY date_field' query = 'SELECT * from $db.modelwitharrays ORDER BY date_field'
for model_cls in (ModelWithArrays, None): for model_cls in (ModelWithArrays, None):
results = list(self.database.select(query, model_cls)) results = list(self.database.select(query, model_cls))
self.assertEquals(len(results), 1) self.assertEqual(len(results), 1)
self.assertEquals(results[0].arr_str, instance.arr_str) self.assertEqual(results[0].arr_str, instance.arr_str)
self.assertEquals(results[0].arr_int, instance.arr_int) self.assertEqual(results[0].arr_int, instance.arr_int)
self.assertEquals(results[0].arr_date, instance.arr_date) self.assertEqual(results[0].arr_date, instance.arr_date)
def test_conversion(self): def test_conversion(self):
instance = ModelWithArrays( instance = ModelWithArrays(
arr_int=('1', '2', '3'), arr_int=('1', '2', '3'),
arr_date=['2010-01-01'] arr_date=['2010-01-01']
) )
self.assertEquals(instance.arr_str, []) self.assertEqual(instance.arr_str, [])
self.assertEquals(instance.arr_int, [1, 2, 3]) self.assertEqual(instance.arr_int, [1, 2, 3])
self.assertEquals(instance.arr_date, [date(2010, 1, 1)]) self.assertEqual(instance.arr_date, [date(2010, 1, 1)])
def test_assignment_error(self): def test_assignment_error(self):
instance = ModelWithArrays() instance = ModelWithArrays()
@ -49,10 +49,10 @@ class ArrayFieldsTest(unittest.TestCase):
def test_parse_array(self): def test_parse_array(self):
from infi.clickhouse_orm.utils import parse_array, unescape from infi.clickhouse_orm.utils import parse_array, unescape
self.assertEquals(parse_array("[]"), []) self.assertEqual(parse_array("[]"), [])
self.assertEquals(parse_array("[1, 2, 395, -44]"), ["1", "2", "395", "-44"]) self.assertEqual(parse_array("[1, 2, 395, -44]"), ["1", "2", "395", "-44"])
self.assertEquals(parse_array("['big','mouse','','!']"), ["big", "mouse", "", "!"]) self.assertEqual(parse_array("['big','mouse','','!']"), ["big", "mouse", "", "!"])
self.assertEquals(parse_array(unescape("['\\r\\n\\0\\t\\b']")), ["\r\n\0\t\b"]) self.assertEqual(parse_array(unescape("['\\r\\n\\0\\t\\b']")), ["\r\n\0\t\b"])
for s in ("", for s in ("",
"[", "[",
"]", "]",

View File

@ -11,7 +11,7 @@ class BufferTestCase(TestCaseWithData):
def _insert_and_check_buffer(self, data, count): def _insert_and_check_buffer(self, data, count):
self.database.insert(data) self.database.insert(data)
self.assertEquals(count, self.database.count(PersonBuffer)) self.assertEqual(count, self.database.count(PersonBuffer))
def _sample_buffer_data(self): def _sample_buffer_data(self):
for entry in data: for entry in data:

View File

@ -28,7 +28,7 @@ class CustomFieldsTest(unittest.TestCase):
for index, value in enumerate([1, '1', True, 0, '0', False]): for index, value in enumerate([1, '1', True, 0, '0', False]):
rec = TestModel(i=index, f=value) rec = TestModel(i=index, f=value)
self.database.insert([rec]) self.database.insert([rec])
self.assertEquals([rec.f for rec in TestModel.objects_in(self.database).order_by('i')], self.assertEqual([rec.f for rec in TestModel.objects_in(self.database).order_by('i')],
[True, True, True, False, False, False]) [True, True, True, False, False, False])
# Check invalid values # Check invalid values
for value in [None, 'zzz', -5, 7]: for value in [None, 'zzz', -5, 7]:
@ -55,12 +55,12 @@ class CustomFieldsTest(unittest.TestCase):
rec = TestModel(i=index, f=value) rec = TestModel(i=index, f=value)
self.database.insert([rec]) self.database.insert([rec])
for rec in TestModel.objects_in(self.database): for rec in TestModel.objects_in(self.database):
self.assertEquals(rec.f, UUID(values[0])) self.assertEqual(rec.f, UUID(values[0]))
# Check that ClickHouse encoding functions are supported # Check that ClickHouse encoding functions are supported
for rec in self.database.select("SELECT i, UUIDNumToString(f) AS f FROM testmodel", TestModel): for rec in self.database.select("SELECT i, UUIDNumToString(f) AS f FROM testmodel", TestModel):
self.assertEquals(rec.f, UUID(values[0])) self.assertEqual(rec.f, UUID(values[0]))
for rec in self.database.select("SELECT 1 as i, UUIDStringToNum('12345678-1234-5678-1234-567812345678') AS f", TestModel): for rec in self.database.select("SELECT 1 as i, UUIDStringToNum('12345678-1234-5678-1234-567812345678') AS f", TestModel):
self.assertEquals(rec.f, UUID(values[0])) self.assertEqual(rec.f, UUID(values[0]))
# Check invalid values # Check invalid values
for value in [None, 'zzz', -1, '123']: for value in [None, 'zzz', -1, '123']:
with self.assertRaises(ValueError): with self.assertRaises(ValueError):

View File

@ -28,20 +28,20 @@ class DatabaseTestCase(TestCaseWithData):
def test_count(self): def test_count(self):
self.database.insert(self._sample_data()) self.database.insert(self._sample_data())
self.assertEquals(self.database.count(Person), 100) self.assertEqual(self.database.count(Person), 100)
self.assertEquals(self.database.count(Person, "first_name = 'Courtney'"), 2) self.assertEqual(self.database.count(Person, "first_name = 'Courtney'"), 2)
self.assertEquals(self.database.count(Person, "birthday > '2000-01-01'"), 22) self.assertEqual(self.database.count(Person, "birthday > '2000-01-01'"), 22)
self.assertEquals(self.database.count(Person, "birthday < '1970-03-01'"), 0) self.assertEqual(self.database.count(Person, "birthday < '1970-03-01'"), 0)
def test_select(self): def test_select(self):
self._insert_and_check(self._sample_data(), len(data)) self._insert_and_check(self._sample_data(), len(data))
query = "SELECT * FROM `test-db`.person WHERE first_name = 'Whitney' ORDER BY last_name" query = "SELECT * FROM `test-db`.person WHERE first_name = 'Whitney' ORDER BY last_name"
results = list(self.database.select(query, Person)) results = list(self.database.select(query, Person))
self.assertEquals(len(results), 2) self.assertEqual(len(results), 2)
self.assertEquals(results[0].last_name, 'Durham') self.assertEqual(results[0].last_name, 'Durham')
self.assertEquals(results[0].height, 1.72) self.assertEqual(results[0].height, 1.72)
self.assertEquals(results[1].last_name, 'Scott') self.assertEqual(results[1].last_name, 'Scott')
self.assertEquals(results[1].height, 1.70) self.assertEqual(results[1].height, 1.70)
self.assertEqual(results[0].get_database(), self.database) self.assertEqual(results[0].get_database(), self.database)
self.assertEqual(results[1].get_database(), self.database) self.assertEqual(results[1].get_database(), self.database)
@ -53,11 +53,11 @@ class DatabaseTestCase(TestCaseWithData):
self._insert_and_check(self._sample_data(), len(data)) self._insert_and_check(self._sample_data(), len(data))
query = "SELECT first_name, last_name FROM `test-db`.person WHERE first_name = 'Whitney' ORDER BY last_name" query = "SELECT first_name, last_name FROM `test-db`.person WHERE first_name = 'Whitney' ORDER BY last_name"
results = list(self.database.select(query, Person)) results = list(self.database.select(query, Person))
self.assertEquals(len(results), 2) self.assertEqual(len(results), 2)
self.assertEquals(results[0].last_name, 'Durham') self.assertEqual(results[0].last_name, 'Durham')
self.assertEquals(results[0].height, 0) # default value self.assertEqual(results[0].height, 0) # default value
self.assertEquals(results[1].last_name, 'Scott') self.assertEqual(results[1].last_name, 'Scott')
self.assertEquals(results[1].height, 0) # default value self.assertEqual(results[1].height, 0) # default value
self.assertEqual(results[0].get_database(), self.database) self.assertEqual(results[0].get_database(), self.database)
self.assertEqual(results[1].get_database(), self.database) self.assertEqual(results[1].get_database(), self.database)
@ -65,12 +65,12 @@ class DatabaseTestCase(TestCaseWithData):
self._insert_and_check(self._sample_data(), len(data)) self._insert_and_check(self._sample_data(), len(data))
query = "SELECT * FROM `test-db`.person WHERE first_name = 'Whitney' ORDER BY last_name" query = "SELECT * FROM `test-db`.person WHERE first_name = 'Whitney' ORDER BY last_name"
results = list(self.database.select(query)) results = list(self.database.select(query))
self.assertEquals(len(results), 2) self.assertEqual(len(results), 2)
self.assertEquals(results[0].__class__.__name__, 'AdHocModel') self.assertEqual(results[0].__class__.__name__, 'AdHocModel')
self.assertEquals(results[0].last_name, 'Durham') self.assertEqual(results[0].last_name, 'Durham')
self.assertEquals(results[0].height, 1.72) self.assertEqual(results[0].height, 1.72)
self.assertEquals(results[1].last_name, 'Scott') self.assertEqual(results[1].last_name, 'Scott')
self.assertEquals(results[1].height, 1.70) self.assertEqual(results[1].height, 1.70)
self.assertEqual(results[0].get_database(), self.database) self.assertEqual(results[0].get_database(), self.database)
self.assertEqual(results[1].get_database(), self.database) self.assertEqual(results[1].get_database(), self.database)
@ -81,7 +81,7 @@ class DatabaseTestCase(TestCaseWithData):
total = sum(r.height for r in results[:-1]) total = sum(r.height for r in results[:-1])
# Last line has an empty last name, and total of all heights # Last line has an empty last name, and total of all heights
self.assertFalse(results[-1].last_name) self.assertFalse(results[-1].last_name)
self.assertEquals(total, results[-1].height) self.assertEqual(total, results[-1].height)
def test_pagination(self): def test_pagination(self):
self._insert_and_check(self._sample_data(), len(data)) self._insert_and_check(self._sample_data(), len(data))
@ -92,14 +92,14 @@ class DatabaseTestCase(TestCaseWithData):
instances = set() instances = set()
while True: while True:
page = self.database.paginate(Person, 'first_name, last_name', page_num, page_size) page = self.database.paginate(Person, 'first_name, last_name', page_num, page_size)
self.assertEquals(page.number_of_objects, len(data)) self.assertEqual(page.number_of_objects, len(data))
self.assertGreater(page.pages_total, 0) self.assertGreater(page.pages_total, 0)
[instances.add(obj.to_tsv()) for obj in page.objects] [instances.add(obj.to_tsv()) for obj in page.objects]
if page.pages_total == page_num: if page.pages_total == page_num:
break break
page_num += 1 page_num += 1
# Verify that all instances were returned # Verify that all instances were returned
self.assertEquals(len(instances), len(data)) self.assertEqual(len(instances), len(data))
def test_pagination_last_page(self): def test_pagination_last_page(self):
self._insert_and_check(self._sample_data(), len(data)) self._insert_and_check(self._sample_data(), len(data))
@ -108,8 +108,8 @@ class DatabaseTestCase(TestCaseWithData):
# Ask for the last page in two different ways and verify equality # Ask for the last page in two different ways and verify equality
page_a = self.database.paginate(Person, 'first_name, last_name', -1, page_size) page_a = self.database.paginate(Person, 'first_name, last_name', -1, page_size)
page_b = self.database.paginate(Person, 'first_name, last_name', page_a.pages_total, page_size) page_b = self.database.paginate(Person, 'first_name, last_name', page_a.pages_total, page_size)
self.assertEquals(page_a[1:], page_b[1:]) self.assertEqual(page_a[1:], page_b[1:])
self.assertEquals([obj.to_tsv() for obj in page_a.objects], self.assertEqual([obj.to_tsv() for obj in page_a.objects],
[obj.to_tsv() for obj in page_b.objects]) [obj.to_tsv() for obj in page_b.objects])
def test_pagination_invalid_page(self): def test_pagination_invalid_page(self):
@ -121,14 +121,14 @@ class DatabaseTestCase(TestCaseWithData):
def test_pagination_with_conditions(self): def test_pagination_with_conditions(self):
self._insert_and_check(self._sample_data(), len(data)) self._insert_and_check(self._sample_data(), len(data))
page = self.database.paginate(Person, 'first_name, last_name', 1, 100, conditions="first_name < 'Ava'") page = self.database.paginate(Person, 'first_name, last_name', 1, 100, conditions="first_name < 'Ava'")
self.assertEquals(page.number_of_objects, 10) self.assertEqual(page.number_of_objects, 10)
def test_special_chars(self): def test_special_chars(self):
s = u'אבגד \\\'"`,.;éåäöšž\n\t\0\b\r' s = u'אבגד \\\'"`,.;éåäöšž\n\t\0\b\r'
p = Person(first_name=s) p = Person(first_name=s)
self.database.insert([p]) self.database.insert([p])
p = list(self.database.select("SELECT * from $table", Person))[0] p = list(self.database.select("SELECT * from $table", Person))[0]
self.assertEquals(p.first_name, s) self.assertEqual(p.first_name, s)
def test_raw(self): def test_raw(self):
self._insert_and_check(self._sample_data(), len(data)) self._insert_and_check(self._sample_data(), len(data))
@ -173,11 +173,11 @@ class DatabaseTestCase(TestCaseWithData):
readonly = StringField() readonly = StringField()
engine = Memory() engine = Memory()
instance = Model1(system='s', readonly='r') instance = Model1(system='s', readonly='r')
self.assertEquals(instance.to_dict(), dict(system='s', readonly='r')) self.assertEqual(instance.to_dict(), dict(system='s', readonly='r'))
self.database.create_table(Model1) self.database.create_table(Model1)
self.database.insert([instance]) self.database.insert([instance])
instance = Model1.objects_in(self.database)[0] instance = Model1.objects_in(self.database)[0]
self.assertEquals(instance.to_dict(), dict(system='s', readonly='r')) self.assertEqual(instance.to_dict(), dict(system='s', readonly='r'))
def test_does_table_exist(self): def test_does_table_exist(self):
class Person2(Person): class Person2(Person):

View File

@ -25,13 +25,13 @@ class DateFieldsTest(unittest.TestCase):
# toStartOfHour returns DateTime('Asia/Yekaterinburg') in my case, so I test it here to # toStartOfHour returns DateTime('Asia/Yekaterinburg') in my case, so I test it here to
query = 'SELECT toStartOfHour(datetime_field) as hour_start, * from $db.modelwithdate ORDER BY date_field' query = 'SELECT toStartOfHour(datetime_field) as hour_start, * from $db.modelwithdate ORDER BY date_field'
results = list(self.database.select(query)) results = list(self.database.select(query))
self.assertEquals(len(results), 2) self.assertEqual(len(results), 2)
self.assertEquals(results[0].date_field, datetime.date(2016, 8, 30)) self.assertEqual(results[0].date_field, datetime.date(2016, 8, 30))
self.assertEquals(results[0].datetime_field, datetime.datetime(2016, 8, 30, 3, 50, 0, tzinfo=pytz.UTC)) self.assertEqual(results[0].datetime_field, datetime.datetime(2016, 8, 30, 3, 50, 0, tzinfo=pytz.UTC))
self.assertEquals(results[0].hour_start, datetime.datetime(2016, 8, 30, 3, 0, 0, tzinfo=pytz.UTC)) self.assertEqual(results[0].hour_start, datetime.datetime(2016, 8, 30, 3, 0, 0, tzinfo=pytz.UTC))
self.assertEquals(results[1].date_field, datetime.date(2016, 8, 31)) self.assertEqual(results[1].date_field, datetime.date(2016, 8, 31))
self.assertEquals(results[1].datetime_field, datetime.datetime(2016, 8, 31, 1, 30, 0, tzinfo=pytz.UTC)) self.assertEqual(results[1].datetime_field, datetime.datetime(2016, 8, 31, 1, 30, 0, tzinfo=pytz.UTC))
self.assertEquals(results[1].hour_start, datetime.datetime(2016, 8, 31, 1, 0, 0, tzinfo=pytz.UTC)) self.assertEqual(results[1].hour_start, datetime.datetime(2016, 8, 31, 1, 0, 0, tzinfo=pytz.UTC))
class ModelWithDate(Model): class ModelWithDate(Model):

View File

@ -49,7 +49,7 @@ class EnginesTestCase(_EnginesHelperTestCase):
expected = "ReplicatedMergeTree('/clickhouse/tables/{layer}-{shard}/hits', '{replica}') PARTITION BY (toYYYYMM(`date`)) ORDER BY (date, event_id, event_group) SETTINGS index_granularity=8192" expected = "ReplicatedMergeTree('/clickhouse/tables/{layer}-{shard}/hits', '{replica}') PARTITION BY (toYYYYMM(`date`)) ORDER BY (date, event_id, event_group) SETTINGS index_granularity=8192"
else: else:
expected = "ReplicatedMergeTree('/clickhouse/tables/{layer}-{shard}/hits', '{replica}', date, (date, event_id, event_group), 8192)" expected = "ReplicatedMergeTree('/clickhouse/tables/{layer}-{shard}/hits', '{replica}', date, (date, event_id, event_group), 8192)"
self.assertEquals(engine.create_table_sql(self.database), expected) self.assertEqual(engine.create_table_sql(self.database), expected)
def test_replicated_merge_tree_incomplete(self): def test_replicated_merge_tree_incomplete(self):
with self.assertRaises(AssertionError): with self.assertRaises(AssertionError):

View File

@ -29,9 +29,9 @@ class EnumFieldsTest(unittest.TestCase):
]) ])
query = 'SELECT * from $table ORDER BY date_field' query = 'SELECT * from $table ORDER BY date_field'
results = list(self.database.select(query, ModelWithEnum)) results = list(self.database.select(query, ModelWithEnum))
self.assertEquals(len(results), 2) self.assertEqual(len(results), 2)
self.assertEquals(results[0].enum_field, Fruit.apple) self.assertEqual(results[0].enum_field, Fruit.apple)
self.assertEquals(results[1].enum_field, Fruit.orange) self.assertEqual(results[1].enum_field, Fruit.orange)
def test_ad_hoc_model(self): def test_ad_hoc_model(self):
self.database.insert([ self.database.insert([
@ -40,16 +40,16 @@ class EnumFieldsTest(unittest.TestCase):
]) ])
query = 'SELECT * from $db.modelwithenum ORDER BY date_field' query = 'SELECT * from $db.modelwithenum ORDER BY date_field'
results = list(self.database.select(query)) results = list(self.database.select(query))
self.assertEquals(len(results), 2) self.assertEqual(len(results), 2)
self.assertEquals(results[0].enum_field.name, Fruit.apple.name) self.assertEqual(results[0].enum_field.name, Fruit.apple.name)
self.assertEquals(results[0].enum_field.value, Fruit.apple.value) self.assertEqual(results[0].enum_field.value, Fruit.apple.value)
self.assertEquals(results[1].enum_field.name, Fruit.orange.name) self.assertEqual(results[1].enum_field.name, Fruit.orange.name)
self.assertEquals(results[1].enum_field.value, Fruit.orange.value) self.assertEqual(results[1].enum_field.value, Fruit.orange.value)
def test_conversion(self): def test_conversion(self):
self.assertEquals(ModelWithEnum(enum_field=3).enum_field, Fruit.orange) self.assertEqual(ModelWithEnum(enum_field=3).enum_field, Fruit.orange)
self.assertEquals(ModelWithEnum(enum_field='apple').enum_field, Fruit.apple) self.assertEqual(ModelWithEnum(enum_field='apple').enum_field, Fruit.apple)
self.assertEquals(ModelWithEnum(enum_field=Fruit.banana).enum_field, Fruit.banana) self.assertEqual(ModelWithEnum(enum_field=Fruit.banana).enum_field, Fruit.banana)
def test_assignment_error(self): def test_assignment_error(self):
for value in (0, 17, 'pear', '', None, 99.9): for value in (0, 17, 'pear', '', None, 99.9):
@ -58,15 +58,15 @@ class EnumFieldsTest(unittest.TestCase):
def test_default_value(self): def test_default_value(self):
instance = ModelWithEnum() instance = ModelWithEnum()
self.assertEquals(instance.enum_field, Fruit.apple) self.assertEqual(instance.enum_field, Fruit.apple)
def test_enum_array(self): def test_enum_array(self):
instance = ModelWithEnumArray(date_field='2016-08-30', enum_array=[Fruit.apple, Fruit.apple, Fruit.orange]) instance = ModelWithEnumArray(date_field='2016-08-30', enum_array=[Fruit.apple, Fruit.apple, Fruit.orange])
self.database.insert([instance]) self.database.insert([instance])
query = 'SELECT * from $table ORDER BY date_field' query = 'SELECT * from $table ORDER BY date_field'
results = list(self.database.select(query, ModelWithEnumArray)) results = list(self.database.select(query, ModelWithEnumArray))
self.assertEquals(len(results), 1) self.assertEqual(len(results), 1)
self.assertEquals(results[0].enum_array, instance.enum_array) self.assertEqual(results[0].enum_array, instance.enum_array)
Fruit = Enum('Fruit', u'apple banana orange') Fruit = Enum('Fruit', u'apple banana orange')

View File

@ -26,11 +26,11 @@ class FixedStringFieldsTest(unittest.TestCase):
]) ])
def _assert_sample_data(self, results): def _assert_sample_data(self, results):
self.assertEquals(len(results), 4) self.assertEqual(len(results), 4)
self.assertEquals(results[0].fstr_field, '') self.assertEqual(results[0].fstr_field, '')
self.assertEquals(results[1].fstr_field, 'ABCDEFGHIJK') self.assertEqual(results[1].fstr_field, 'ABCDEFGHIJK')
self.assertEquals(results[2].fstr_field, 'foo') self.assertEqual(results[2].fstr_field, 'foo')
self.assertEquals(results[3].fstr_field, u'לילה') self.assertEqual(results[3].fstr_field, u'לילה')
def test_insert_and_select(self): def test_insert_and_select(self):
self._insert_sample_data() self._insert_sample_data()

View File

@ -12,7 +12,7 @@ from infi.clickhouse_orm.engines import *
class InheritanceTestCase(unittest.TestCase): class InheritanceTestCase(unittest.TestCase):
def assertFieldNames(self, model_class, names): def assertFieldNames(self, model_class, names):
self.assertEquals(names, list(model_class.fields())) self.assertEqual(names, list(model_class.fields()))
def test_field_inheritance(self): def test_field_inheritance(self):
self.assertFieldNames(ParentModel, ['date_field', 'int_field']) self.assertFieldNames(ParentModel, ['date_field', 'int_field'])

View File

@ -29,13 +29,13 @@ class MaterializedFieldsTest(unittest.TestCase):
' FROM $db.%s ORDER BY mat_date' % ModelWithMaterializedFields.table_name() ' FROM $db.%s ORDER BY mat_date' % ModelWithMaterializedFields.table_name()
for model_cls in (ModelWithMaterializedFields, None): for model_cls in (ModelWithMaterializedFields, None):
results = list(self.database.select(query, model_cls)) results = list(self.database.select(query, model_cls))
self.assertEquals(len(results), 1) self.assertEqual(len(results), 1)
self.assertEquals(results[0].date_time_field, instance.date_time_field) self.assertEqual(results[0].date_time_field, instance.date_time_field)
self.assertEquals(results[0].int_field, instance.int_field) self.assertEqual(results[0].int_field, instance.int_field)
self.assertEquals(results[0].str_field, instance.str_field) self.assertEqual(results[0].str_field, instance.str_field)
self.assertEquals(results[0].mat_int, abs(instance.int_field)) self.assertEqual(results[0].mat_int, abs(instance.int_field))
self.assertEquals(results[0].mat_str, instance.str_field.lower()) self.assertEqual(results[0].mat_str, instance.str_field.lower())
self.assertEquals(results[0].mat_date, instance.date_time_field.date()) self.assertEqual(results[0].mat_date, instance.date_time_field.date())
def test_assignment_error(self): def test_assignment_error(self):
# I can't prevent assigning at all, in case db.select statements with model provided sets model fields. # I can't prevent assigning at all, in case db.select statements with model provided sets model fields.

View File

@ -47,38 +47,38 @@ class MigrationsTestCase(unittest.TestCase):
self.database.migrate('tests.sample_migrations', 3) self.database.migrate('tests.sample_migrations', 3)
self.assertTrue(self.tableExists(Model1)) self.assertTrue(self.tableExists(Model1))
# Adding, removing and altering simple fields # Adding, removing and altering simple fields
self.assertEquals(self.getTableFields(Model1), [('date', 'Date'), ('f1', 'Int32'), ('f2', 'String')]) self.assertEqual(self.getTableFields(Model1), [('date', 'Date'), ('f1', 'Int32'), ('f2', 'String')])
self.database.migrate('tests.sample_migrations', 4) self.database.migrate('tests.sample_migrations', 4)
self.assertEquals(self.getTableFields(Model2), [('date', 'Date'), ('f1', 'Int32'), ('f3', 'Float32'), ('f2', 'String'), ('f4', 'String'), ('f5', 'Array(UInt64)')]) self.assertEqual(self.getTableFields(Model2), [('date', 'Date'), ('f1', 'Int32'), ('f3', 'Float32'), ('f2', 'String'), ('f4', 'String'), ('f5', 'Array(UInt64)')])
self.database.migrate('tests.sample_migrations', 5) self.database.migrate('tests.sample_migrations', 5)
self.assertEquals(self.getTableFields(Model3), [('date', 'Date'), ('f1', 'Int64'), ('f3', 'Float64'), ('f4', 'String')]) self.assertEqual(self.getTableFields(Model3), [('date', 'Date'), ('f1', 'Int64'), ('f3', 'Float64'), ('f4', 'String')])
# Altering enum fields # Altering enum fields
self.database.migrate('tests.sample_migrations', 6) self.database.migrate('tests.sample_migrations', 6)
self.assertTrue(self.tableExists(EnumModel1)) self.assertTrue(self.tableExists(EnumModel1))
self.assertEquals(self.getTableFields(EnumModel1), self.assertEqual(self.getTableFields(EnumModel1),
[('date', 'Date'), ('f1', "Enum8('dog' = 1, 'cat' = 2, 'cow' = 3)")]) [('date', 'Date'), ('f1', "Enum8('dog' = 1, 'cat' = 2, 'cow' = 3)")])
self.database.migrate('tests.sample_migrations', 7) self.database.migrate('tests.sample_migrations', 7)
self.assertTrue(self.tableExists(EnumModel1)) self.assertTrue(self.tableExists(EnumModel1))
self.assertEquals(self.getTableFields(EnumModel2), self.assertEqual(self.getTableFields(EnumModel2),
[('date', 'Date'), ('f1', "Enum16('dog' = 1, 'cat' = 2, 'horse' = 3, 'pig' = 4)")]) [('date', 'Date'), ('f1', "Enum16('dog' = 1, 'cat' = 2, 'horse' = 3, 'pig' = 4)")])
# Materialized fields and alias fields # Materialized fields and alias fields
self.database.migrate('tests.sample_migrations', 8) self.database.migrate('tests.sample_migrations', 8)
self.assertTrue(self.tableExists(MaterializedModel)) self.assertTrue(self.tableExists(MaterializedModel))
self.assertEquals(self.getTableFields(MaterializedModel), self.assertEqual(self.getTableFields(MaterializedModel),
[('date_time', "DateTime"), ('date', 'Date')]) [('date_time', "DateTime"), ('date', 'Date')])
self.database.migrate('tests.sample_migrations', 9) self.database.migrate('tests.sample_migrations', 9)
self.assertTrue(self.tableExists(AliasModel)) self.assertTrue(self.tableExists(AliasModel))
self.assertEquals(self.getTableFields(AliasModel), self.assertEqual(self.getTableFields(AliasModel),
[('date', 'Date'), ('date_alias', "Date")]) [('date', 'Date'), ('date_alias', "Date")])
# Buffer models creation and alteration # Buffer models creation and alteration
self.database.migrate('tests.sample_migrations', 10) self.database.migrate('tests.sample_migrations', 10)
self.assertTrue(self.tableExists(Model4)) self.assertTrue(self.tableExists(Model4))
self.assertTrue(self.tableExists(Model4Buffer)) self.assertTrue(self.tableExists(Model4Buffer))
self.assertEquals(self.getTableFields(Model4), [('date', 'Date'), ('f1', 'Int32'), ('f2', 'String')]) self.assertEqual(self.getTableFields(Model4), [('date', 'Date'), ('f1', 'Int32'), ('f2', 'String')])
self.assertEquals(self.getTableFields(Model4Buffer), [('date', 'Date'), ('f1', 'Int32'), ('f2', 'String')]) self.assertEqual(self.getTableFields(Model4Buffer), [('date', 'Date'), ('f1', 'Int32'), ('f2', 'String')])
self.database.migrate('tests.sample_migrations', 11) self.database.migrate('tests.sample_migrations', 11)
self.assertEquals(self.getTableFields(Model4), [('date', 'Date'), ('f3', 'DateTime'), ('f2', 'String')]) self.assertEqual(self.getTableFields(Model4), [('date', 'Date'), ('f3', 'DateTime'), ('f2', 'String')])
self.assertEquals(self.getTableFields(Model4Buffer), [('date', 'Date'), ('f3', 'DateTime'), ('f2', 'String')]) self.assertEqual(self.getTableFields(Model4Buffer), [('date', 'Date'), ('f3', 'DateTime'), ('f2', 'String')])
self.database.migrate('tests.sample_migrations', 12) self.database.migrate('tests.sample_migrations', 12)
self.assertEqual(self.database.count(Model3), 3) self.assertEqual(self.database.count(Model3), 3)
@ -92,10 +92,10 @@ class MigrationsTestCase(unittest.TestCase):
self.database.migrate('tests.sample_migrations', 14) self.database.migrate('tests.sample_migrations', 14)
self.assertTrue(self.tableExists(MaterializedModel1)) self.assertTrue(self.tableExists(MaterializedModel1))
self.assertEquals(self.getTableFields(MaterializedModel1), self.assertEqual(self.getTableFields(MaterializedModel1),
[('date_time', "DateTime"), ('int_field', 'Int8'), ('date', 'Date')]) [('date_time', "DateTime"), ('int_field', 'Int8'), ('date', 'Date')])
self.assertTrue(self.tableExists(AliasModel1)) self.assertTrue(self.tableExists(AliasModel1))
self.assertEquals(self.getTableFields(AliasModel1), self.assertEqual(self.getTableFields(AliasModel1),
[('date', 'Date'), ('int_field', 'Int8'), ('date_alias', "Date")]) [('date', 'Date'), ('int_field', 'Int8'), ('date_alias', "Date")])

View File

@ -13,11 +13,11 @@ class ModelTestCase(unittest.TestCase):
def test_defaults(self): def test_defaults(self):
# Check that all fields have their explicit or implicit defaults # Check that all fields have their explicit or implicit defaults
instance = SimpleModel() instance = SimpleModel()
self.assertEquals(instance.date_field, datetime.date(1970, 1, 1)) self.assertEqual(instance.date_field, datetime.date(1970, 1, 1))
self.assertEquals(instance.datetime_field, datetime.datetime(1970, 1, 1, tzinfo=pytz.utc)) self.assertEqual(instance.datetime_field, datetime.datetime(1970, 1, 1, tzinfo=pytz.utc))
self.assertEquals(instance.str_field, 'dozo') self.assertEqual(instance.str_field, 'dozo')
self.assertEquals(instance.int_field, 17) self.assertEqual(instance.int_field, 17)
self.assertEquals(instance.float_field, 0) self.assertEqual(instance.float_field, 0)
def test_assignment(self): def test_assignment(self):
# Check that all fields are assigned during construction # Check that all fields are assigned during construction
@ -30,7 +30,7 @@ class ModelTestCase(unittest.TestCase):
) )
instance = SimpleModel(**kwargs) instance = SimpleModel(**kwargs)
for name, value in kwargs.items(): for name, value in kwargs.items():
self.assertEquals(kwargs[name], getattr(instance, name)) self.assertEqual(kwargs[name], getattr(instance, name))
def test_assignment_error(self): def test_assignment_error(self):
# Check non-existing field during construction # Check non-existing field during construction
@ -49,12 +49,12 @@ class ModelTestCase(unittest.TestCase):
def test_string_conversion(self): def test_string_conversion(self):
# Check field conversion from string during construction # Check field conversion from string during construction
instance = SimpleModel(date_field='1973-12-06', int_field='100', float_field='7') instance = SimpleModel(date_field='1973-12-06', int_field='100', float_field='7')
self.assertEquals(instance.date_field, datetime.date(1973, 12, 6)) self.assertEqual(instance.date_field, datetime.date(1973, 12, 6))
self.assertEquals(instance.int_field, 100) self.assertEqual(instance.int_field, 100)
self.assertEquals(instance.float_field, 7) self.assertEqual(instance.float_field, 7)
# Check field conversion from string during assignment # Check field conversion from string during assignment
instance.int_field = '99' instance.int_field = '99'
self.assertEquals(instance.int_field, 99) self.assertEqual(instance.int_field, 99)
def test_to_dict(self): def test_to_dict(self):
instance = SimpleModel(date_field='1973-12-06', int_field='100', float_field='7') instance = SimpleModel(date_field='1973-12-06', int_field='100', float_field='7')

View File

@ -37,10 +37,10 @@ class NullableFieldsTest(unittest.TestCase):
if value == '\\N': if value == '\\N':
self.assertIsNone(dt) self.assertIsNone(dt)
else: else:
self.assertEquals(dt.tzinfo, pytz.utc) self.assertEqual(dt.tzinfo, pytz.utc)
# Verify that conversion to and from db string does not change value # Verify that conversion to and from db string does not change value
dt2 = f.to_python(f.to_db_string(dt, quote=False), pytz.utc) dt2 = f.to_python(f.to_db_string(dt, quote=False), pytz.utc)
self.assertEquals(dt, dt2) self.assertEqual(dt, dt2)
# Invalid values # Invalid values
for value in ('nope', '21/7/1999', 0.5): for value in ('nope', '21/7/1999', 0.5):
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
@ -55,7 +55,7 @@ class NullableFieldsTest(unittest.TestCase):
self.assertIsNone(python_value) self.assertIsNone(python_value)
self.assertEqual(value, f.to_db_string(python_value)) self.assertEqual(value, f.to_db_string(python_value))
else: else:
self.assertEquals(python_value, 17) self.assertEqual(python_value, 17)
# Invalid values # Invalid values
for value in ('nope', date.today()): for value in ('nope', date.today()):
@ -71,7 +71,7 @@ class NullableFieldsTest(unittest.TestCase):
self.assertIsNone(python_value) self.assertIsNone(python_value)
self.assertEqual(value, f.to_db_string(python_value)) self.assertEqual(value, f.to_db_string(python_value))
else: else:
self.assertEquals(python_value, value) self.assertEqual(python_value, value)
def test_isinstance(self): def test_isinstance(self):
for field in (StringField, UInt8Field, Float32Field, DateTimeField): for field in (StringField, UInt8Field, Float32Field, DateTimeField):
@ -100,16 +100,16 @@ class NullableFieldsTest(unittest.TestCase):
def _assert_sample_data(self, results): def _assert_sample_data(self, results):
dt = date(1970, 1, 1) dt = date(1970, 1, 1)
self.assertEquals(len(results), 4) self.assertEqual(len(results), 4)
self.assertIsNone(results[0].null_str) self.assertIsNone(results[0].null_str)
self.assertEquals(results[0].null_int, 42) self.assertEqual(results[0].null_int, 42)
self.assertEquals(results[0].null_date, dt) self.assertEqual(results[0].null_date, dt)
self.assertIsNone(results[1].null_date) self.assertIsNone(results[1].null_date)
self.assertEquals(results[1].null_str, 'nothing') self.assertEqual(results[1].null_str, 'nothing')
self.assertIsNone(results[1].null_date) self.assertIsNone(results[1].null_date)
self.assertIsNone(results[2].null_str) self.assertIsNone(results[2].null_str)
self.assertEquals(results[2].null_date, dt) self.assertEqual(results[2].null_date, dt)
self.assertEquals(results[2].null_int, 42) self.assertEqual(results[2].null_int, 42)
self.assertIsNone(results[3].null_int) self.assertIsNone(results[3].null_int)
self.assertIsNone(results[3].null_str) self.assertIsNone(results[3].null_str)
self.assertIsNone(results[3].null_date) self.assertIsNone(results[3].null_date)

View File

@ -26,8 +26,8 @@ class QuerySetTestCase(TestCaseWithData):
for instance in qs: for instance in qs:
count += 1 count += 1
logging.info('\t[%d]\t%s' % (count, instance.to_dict())) logging.info('\t[%d]\t%s' % (count, instance.to_dict()))
self.assertEquals(count, expected_count) self.assertEqual(count, expected_count)
self.assertEquals(qs.count(), expected_count) self.assertEqual(qs.count(), expected_count)
def test_no_filtering(self): def test_no_filtering(self):
qs = Person.objects_in(self.database) qs = Person.objects_in(self.database)
@ -99,20 +99,20 @@ class QuerySetTestCase(TestCaseWithData):
self.assertTrue(person.first_name) self.assertTrue(person.first_name)
self.assertTrue(person.last_name) self.assertTrue(person.last_name)
self.assertFalse(person.height) self.assertFalse(person.height)
self.assertEquals(person.birthday, date(1970, 1, 1)) self.assertEqual(person.birthday, date(1970, 1, 1))
def test_order_by(self): def test_order_by(self):
qs = Person.objects_in(self.database) qs = Person.objects_in(self.database)
self.assertFalse('ORDER BY' in qs.as_sql()) self.assertFalse('ORDER BY' in qs.as_sql())
self.assertFalse(qs.order_by_as_sql()) self.assertFalse(qs.order_by_as_sql())
person = list(qs.order_by('first_name', 'last_name'))[0] person = list(qs.order_by('first_name', 'last_name'))[0]
self.assertEquals(person.first_name, 'Abdul') self.assertEqual(person.first_name, 'Abdul')
person = list(qs.order_by('-first_name', '-last_name'))[0] person = list(qs.order_by('-first_name', '-last_name'))[0]
self.assertEquals(person.first_name, 'Yolanda') self.assertEqual(person.first_name, 'Yolanda')
person = list(qs.order_by('height'))[0] person = list(qs.order_by('height'))[0]
self.assertEquals(person.height, 1.59) self.assertEqual(person.height, 1.59)
person = list(qs.order_by('-height'))[0] person = list(qs.order_by('-height'))[0]
self.assertEquals(person.height, 1.8) self.assertEqual(person.height, 1.8)
def test_in_subquery(self): def test_in_subquery(self):
qs = Person.objects_in(self.database) qs = Person.objects_in(self.database)
@ -155,13 +155,13 @@ class QuerySetTestCase(TestCaseWithData):
db = Database('system') db = Database('system')
numbers = list(range(100)) numbers = list(range(100))
qs = Numbers.objects_in(db) qs = Numbers.objects_in(db)
self.assertEquals(qs[0].number, numbers[0]) self.assertEqual(qs[0].number, numbers[0])
self.assertEquals(qs[5].number, numbers[5]) self.assertEqual(qs[5].number, numbers[5])
self.assertEquals([row.number for row in qs[:1]], numbers[:1]) self.assertEqual([row.number for row in qs[:1]], numbers[:1])
self.assertEquals([row.number for row in qs[:10]], numbers[:10]) self.assertEqual([row.number for row in qs[:10]], numbers[:10])
self.assertEquals([row.number for row in qs[3:10]], numbers[3:10]) self.assertEqual([row.number for row in qs[3:10]], numbers[3:10])
self.assertEquals([row.number for row in qs[9:10]], numbers[9:10]) self.assertEqual([row.number for row in qs[9:10]], numbers[9:10])
self.assertEquals([row.number for row in qs[10:10]], numbers[10:10]) self.assertEqual([row.number for row in qs[10:10]], numbers[10:10])
def test_invalid_slicing(self): def test_invalid_slicing(self):
db = Database('system') db = Database('system')
@ -184,14 +184,14 @@ class QuerySetTestCase(TestCaseWithData):
instances = set() instances = set()
while True: while True:
page = qs.paginate(page_num, page_size) page = qs.paginate(page_num, page_size)
self.assertEquals(page.number_of_objects, len(data)) self.assertEqual(page.number_of_objects, len(data))
self.assertGreater(page.pages_total, 0) self.assertGreater(page.pages_total, 0)
[instances.add(obj.to_tsv()) for obj in page.objects] [instances.add(obj.to_tsv()) for obj in page.objects]
if page.pages_total == page_num: if page.pages_total == page_num:
break break
page_num += 1 page_num += 1
# Verify that all instances were returned # Verify that all instances were returned
self.assertEquals(len(instances), len(data)) self.assertEqual(len(instances), len(data))
def test_pagination_last_page(self): def test_pagination_last_page(self):
qs = Person.objects_in(self.database).order_by('first_name', 'last_name') qs = Person.objects_in(self.database).order_by('first_name', 'last_name')
@ -200,8 +200,8 @@ class QuerySetTestCase(TestCaseWithData):
# Ask for the last page in two different ways and verify equality # Ask for the last page in two different ways and verify equality
page_a = qs.paginate(-1, page_size) page_a = qs.paginate(-1, page_size)
page_b = qs.paginate(page_a.pages_total, page_size) page_b = qs.paginate(page_a.pages_total, page_size)
self.assertEquals(page_a[1:], page_b[1:]) self.assertEqual(page_a[1:], page_b[1:])
self.assertEquals([obj.to_tsv() for obj in page_a.objects], self.assertEqual([obj.to_tsv() for obj in page_a.objects],
[obj.to_tsv() for obj in page_b.objects]) [obj.to_tsv() for obj in page_b.objects])
def test_pagination_invalid_page(self): def test_pagination_invalid_page(self):
@ -213,7 +213,7 @@ class QuerySetTestCase(TestCaseWithData):
def test_pagination_with_conditions(self): def test_pagination_with_conditions(self):
qs = Person.objects_in(self.database).order_by('first_name', 'last_name').filter(first_name__lt='Ava') qs = Person.objects_in(self.database).order_by('first_name', 'last_name').filter(first_name__lt='Ava')
page = qs.paginate(1, 100) page = qs.paginate(1, 100)
self.assertEquals(page.number_of_objects, 10) self.assertEqual(page.number_of_objects, 10)
def test_distinct(self): def test_distinct(self):
qs = Person.objects_in(self.database).distinct() qs = Person.objects_in(self.database).distinct()
@ -242,63 +242,63 @@ class AggregateTestCase(TestCaseWithData):
def test_aggregate_no_grouping(self): def test_aggregate_no_grouping(self):
qs = Person.objects_in(self.database).aggregate(average_height='avg(height)', count='count()') qs = Person.objects_in(self.database).aggregate(average_height='avg(height)', count='count()')
print(qs.as_sql()) print(qs.as_sql())
self.assertEquals(qs.count(), 1) self.assertEqual(qs.count(), 1)
for row in qs: for row in qs:
self.assertAlmostEqual(row.average_height, 1.6923, places=4) self.assertAlmostEqual(row.average_height, 1.6923, places=4)
self.assertEquals(row.count, 100) self.assertEqual(row.count, 100)
def test_aggregate_with_filter(self): def test_aggregate_with_filter(self):
# When filter comes before aggregate # When filter comes before aggregate
qs = Person.objects_in(self.database).filter(first_name='Warren').aggregate(average_height='avg(height)', count='count()') qs = Person.objects_in(self.database).filter(first_name='Warren').aggregate(average_height='avg(height)', count='count()')
print(qs.as_sql()) print(qs.as_sql())
self.assertEquals(qs.count(), 1) self.assertEqual(qs.count(), 1)
for row in qs: for row in qs:
self.assertAlmostEqual(row.average_height, 1.675, places=4) self.assertAlmostEqual(row.average_height, 1.675, places=4)
self.assertEquals(row.count, 2) self.assertEqual(row.count, 2)
# When filter comes after aggregate # When filter comes after aggregate
qs = Person.objects_in(self.database).aggregate(average_height='avg(height)', count='count()').filter(first_name='Warren') qs = Person.objects_in(self.database).aggregate(average_height='avg(height)', count='count()').filter(first_name='Warren')
print(qs.as_sql()) print(qs.as_sql())
self.assertEquals(qs.count(), 1) self.assertEqual(qs.count(), 1)
for row in qs: for row in qs:
self.assertAlmostEqual(row.average_height, 1.675, places=4) self.assertAlmostEqual(row.average_height, 1.675, places=4)
self.assertEquals(row.count, 2) self.assertEqual(row.count, 2)
def test_aggregate_with_implicit_grouping(self): def test_aggregate_with_implicit_grouping(self):
qs = Person.objects_in(self.database).aggregate('first_name', average_height='avg(height)', count='count()') qs = Person.objects_in(self.database).aggregate('first_name', average_height='avg(height)', count='count()')
print(qs.as_sql()) print(qs.as_sql())
self.assertEquals(qs.count(), 94) self.assertEqual(qs.count(), 94)
total = 0 total = 0
for row in qs: for row in qs:
self.assertTrue(1.5 < row.average_height < 2) self.assertTrue(1.5 < row.average_height < 2)
self.assertTrue(0 < row.count < 3) self.assertTrue(0 < row.count < 3)
total += row.count total += row.count
self.assertEquals(total, 100) self.assertEqual(total, 100)
def test_aggregate_with_explicit_grouping(self): def test_aggregate_with_explicit_grouping(self):
qs = Person.objects_in(self.database).aggregate(weekday='toDayOfWeek(birthday)', count='count()').group_by('weekday') qs = Person.objects_in(self.database).aggregate(weekday='toDayOfWeek(birthday)', count='count()').group_by('weekday')
print(qs.as_sql()) print(qs.as_sql())
self.assertEquals(qs.count(), 7) self.assertEqual(qs.count(), 7)
total = 0 total = 0
for row in qs: for row in qs:
total += row.count total += row.count
self.assertEquals(total, 100) self.assertEqual(total, 100)
def test_aggregate_with_order_by(self): def test_aggregate_with_order_by(self):
qs = Person.objects_in(self.database).aggregate(weekday='toDayOfWeek(birthday)', count='count()').group_by('weekday') qs = Person.objects_in(self.database).aggregate(weekday='toDayOfWeek(birthday)', count='count()').group_by('weekday')
days = [row.weekday for row in qs.order_by('weekday')] days = [row.weekday for row in qs.order_by('weekday')]
self.assertEquals(days, list(range(1, 8))) self.assertEqual(days, list(range(1, 8)))
def test_aggregate_with_indexing(self): def test_aggregate_with_indexing(self):
qs = Person.objects_in(self.database).aggregate(weekday='toDayOfWeek(birthday)', count='count()').group_by('weekday') qs = Person.objects_in(self.database).aggregate(weekday='toDayOfWeek(birthday)', count='count()').group_by('weekday')
total = 0 total = 0
for i in range(7): for i in range(7):
total += qs[i].count total += qs[i].count
self.assertEquals(total, 100) self.assertEqual(total, 100)
def test_aggregate_with_slicing(self): def test_aggregate_with_slicing(self):
qs = Person.objects_in(self.database).aggregate(weekday='toDayOfWeek(birthday)', count='count()').group_by('weekday') qs = Person.objects_in(self.database).aggregate(weekday='toDayOfWeek(birthday)', count='count()').group_by('weekday')
total = sum(row.count for row in qs[:3]) + sum(row.count for row in qs[3:]) total = sum(row.count for row in qs[:3]) + sum(row.count for row in qs[3:])
self.assertEquals(total, 100) self.assertEqual(total, 100)
def test_aggregate_with_pagination(self): def test_aggregate_with_pagination(self):
qs = Person.objects_in(self.database).aggregate(weekday='toDayOfWeek(birthday)', count='count()').group_by('weekday') qs = Person.objects_in(self.database).aggregate(weekday='toDayOfWeek(birthday)', count='count()').group_by('weekday')
@ -306,12 +306,12 @@ class AggregateTestCase(TestCaseWithData):
page_num = 1 page_num = 1
while True: while True:
page = qs.paginate(page_num, page_size=3) page = qs.paginate(page_num, page_size=3)
self.assertEquals(page.number_of_objects, 7) self.assertEqual(page.number_of_objects, 7)
total += sum(row.count for row in page.objects) total += sum(row.count for row in page.objects)
if page.pages_total == page_num: if page.pages_total == page_num:
break break
page_num += 1 page_num += 1
self.assertEquals(total, 100) self.assertEqual(total, 100)
def test_aggregate_with_wrong_grouping(self): def test_aggregate_with_wrong_grouping(self):
with self.assertRaises(AssertionError): with self.assertRaises(AssertionError):
@ -338,13 +338,13 @@ class AggregateTestCase(TestCaseWithData):
with self.assertRaises(AttributeError): with self.assertRaises(AttributeError):
qs = Person.objects_in(self.database).aggregate(weekday='toDayOfWeek(birthday)', count='count()').group_by('weekday') qs = Person.objects_in(self.database).aggregate(weekday='toDayOfWeek(birthday)', count='count()').group_by('weekday')
qs = qs.filter(weekday=1) qs = qs.filter(weekday=1)
self.assertEquals(qs.count(), 1) self.assertEqual(qs.count(), 1)
def test_aggregate_with_distinct(self): def test_aggregate_with_distinct(self):
# In this case distinct has no effect # In this case distinct has no effect
qs = Person.objects_in(self.database).aggregate(average_height='avg(height)').distinct() qs = Person.objects_in(self.database).aggregate(average_height='avg(height)').distinct()
print(qs.as_sql()) print(qs.as_sql())
self.assertEquals(qs.count(), 1) self.assertEqual(qs.count(), 1)
def test_double_underscore_field(self): def test_double_underscore_field(self):
class Mdl(Model): class Mdl(Model):
@ -352,13 +352,13 @@ class AggregateTestCase(TestCaseWithData):
the__next__number = Int32Field() the__next__number = Int32Field()
engine = Memory() engine = Memory()
qs = Mdl.objects_in(self.database).filter(the__number=1) qs = Mdl.objects_in(self.database).filter(the__number=1)
self.assertEquals(qs.conditions_as_sql(), 'the__number = 1') self.assertEqual(qs.conditions_as_sql(), 'the__number = 1')
qs = Mdl.objects_in(self.database).filter(the__number__gt=1) qs = Mdl.objects_in(self.database).filter(the__number__gt=1)
self.assertEquals(qs.conditions_as_sql(), 'the__number > 1') self.assertEqual(qs.conditions_as_sql(), 'the__number > 1')
qs = Mdl.objects_in(self.database).filter(the__next__number=1) qs = Mdl.objects_in(self.database).filter(the__next__number=1)
self.assertEquals(qs.conditions_as_sql(), 'the__next__number = 1') self.assertEqual(qs.conditions_as_sql(), 'the__next__number = 1')
qs = Mdl.objects_in(self.database).filter(the__next__number__gt=1) qs = Mdl.objects_in(self.database).filter(the__next__number__gt=1)
self.assertEquals(qs.conditions_as_sql(), 'the__next__number > 1') self.assertEqual(qs.conditions_as_sql(), 'the__next__number > 1')
Color = Enum('Color', u'red blue green yellow brown white black') Color = Enum('Color', u'red blue green yellow brown white black')

View File

@ -16,7 +16,7 @@ class ReadonlyTestCase(TestCaseWithData):
self._insert_and_check(self._sample_data(), len(data)) self._insert_and_check(self._sample_data(), len(data))
self._check_db_readonly_err(cm.exception) self._check_db_readonly_err(cm.exception)
self.assertEquals(self.database.count(Person), 100) self.assertEqual(self.database.count(Person), 100)
list(self.database.select('SELECT * from $table', Person)) list(self.database.select('SELECT * from $table', Person))
with self.assertRaises(ServerError) as cm: with self.assertRaises(ServerError) as cm:
self.database.drop_table(Person) self.database.drop_table(Person)

View File

@ -17,10 +17,10 @@ class SimpleFieldsTest(unittest.TestCase):
'2017-07-26T08:31:05', '2017-07-26T08:31:05Z', '2017-07-26 08:31', '2017-07-26T08:31:05', '2017-07-26T08:31:05Z', '2017-07-26 08:31',
'2017-07-26T13:31:05+05', '2017-07-26 13:31:05+0500'): '2017-07-26T13:31:05+05', '2017-07-26 13:31:05+0500'):
dt = f.to_python(value, pytz.utc) dt = f.to_python(value, pytz.utc)
self.assertEquals(dt.tzinfo, pytz.utc) self.assertEqual(dt.tzinfo, pytz.utc)
# Verify that conversion to and from db string does not change value # Verify that conversion to and from db string does not change value
dt2 = f.to_python(f.to_db_string(dt, quote=False), pytz.utc) dt2 = f.to_python(f.to_db_string(dt, quote=False), pytz.utc)
self.assertEquals(dt, dt2) self.assertEqual(dt, dt2)
# Invalid values # Invalid values
for value in ('nope', '21/7/1999', 0.5, for value in ('nope', '21/7/1999', 0.5,
'2017-01 15:06:00', '2017-01-01X15:06:00', '2017-13-01T15:06:00'): '2017-01 15:06:00', '2017-01-01X15:06:00', '2017-13-01T15:06:00'):
@ -33,10 +33,10 @@ class SimpleFieldsTest(unittest.TestCase):
# Valid values # Valid values
for value in (datetime(1970, 1, 1), epoch, '1970-01-01', '0000-00-00', 0): for value in (datetime(1970, 1, 1), epoch, '1970-01-01', '0000-00-00', 0):
d = f.to_python(value, pytz.utc) d = f.to_python(value, pytz.utc)
self.assertEquals(d, epoch) self.assertEqual(d, epoch)
# Verify that conversion to and from db string does not change value # Verify that conversion to and from db string does not change value
d2 = f.to_python(f.to_db_string(d, quote=False), pytz.utc) d2 = f.to_python(f.to_db_string(d, quote=False), pytz.utc)
self.assertEquals(d, d2) self.assertEqual(d, d2)
# Invalid values # Invalid values
for value in ('nope', '21/7/1999', 0.5): for value in ('nope', '21/7/1999', 0.5):
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
@ -50,7 +50,7 @@ class SimpleFieldsTest(unittest.TestCase):
# Verify that conversion of timezone-aware datetime is correct # Verify that conversion of timezone-aware datetime is correct
f = DateField() f = DateField()
dt = datetime(2017, 10, 5, tzinfo=pytz.timezone('Asia/Jerusalem')) dt = datetime(2017, 10, 5, tzinfo=pytz.timezone('Asia/Jerusalem'))
self.assertEquals(f.to_python(dt, pytz.utc), date(2017, 10, 4)) self.assertEqual(f.to_python(dt, pytz.utc), date(2017, 10, 4))
def test_datetime_field_timezone(self): def test_datetime_field_timezone(self):
# Verify that conversion of timezone-aware datetime is correct # Verify that conversion of timezone-aware datetime is correct
@ -63,13 +63,13 @@ class SimpleFieldsTest(unittest.TestCase):
'2017-07-26 11:31:05+0300', '2017-07-26 11:31:05+0300',
'2017-07-26T03:31:05-0500', '2017-07-26T03:31:05-0500',
): ):
self.assertEquals(f.to_python(value, pytz.utc), utc_value) self.assertEqual(f.to_python(value, pytz.utc), utc_value)
def test_uint8_field(self): def test_uint8_field(self):
f = UInt8Field() f = UInt8Field()
# Valid values # Valid values
for value in (17, '17', 17.0): for value in (17, '17', 17.0):
self.assertEquals(f.to_python(value, pytz.utc), 17) self.assertEqual(f.to_python(value, pytz.utc), 17)
# Invalid values # Invalid values
for value in ('nope', date.today()): for value in ('nope', date.today()):
with self.assertRaises(ValueError): with self.assertRaises(ValueError):