Skip to content

Commit b80ddb6

Browse files
author
Dave Charness
committed
Add tests for enum comparisons
Besides the test changes themselves, - Update mysql-connector-python to 2.1.6 that's currently available from Oracle. - Suppress "not-callable" errors from pylint. - Fix flake8 indentation errors.
1 parent e6bf388 commit b80ddb6

File tree

7 files changed

+145
-13
lines changed

7 files changed

+145
-13
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
test: flake8 pylint pytest
44

55
pylint:
6-
pylint sqlalchemydiff -E
6+
pylint sqlalchemydiff -E --disable=E1102
77

88
flake8:
99
flake8 sqlalchemydiff test

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
"sqlalchemy-utils>=0.32.4",
2626
],
2727
dependency_links=[
28-
'https://cdn.mysql.com/Downloads/Connector-Python/mysql-connector-python-2.1.4.zip'
28+
'https://dev.mysql.com/get/Downloads/Connector-Python/mysql-connector-python-2.1.6.zip'
2929
],
3030
extras_require={
3131
'dev': [
3232
"mock==2.0.0",
33-
"mysql-connector-python==2.1.4",
33+
"mysql-connector-python==2.1.6",
3434
"pytest==3.0.3",
3535
"pylint==1.5.1",
3636
"flake8==3.0.4",

test/endtoend/models_left.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
# -*- coding: utf-8 -*-
2-
from sqlalchemy import Column, ForeignKey, Integer, String, Unicode
2+
import enum
3+
4+
from sqlalchemy import Column, Enum, ForeignKey, Integer, String, Unicode
35
from sqlalchemy.ext.declarative import declarative_base
46

57

68
Base = declarative_base()
79

810

11+
class Polarity(enum.Enum):
12+
NEGATIVE = 'NEGATIVE'
13+
POSITIVE = 'POSITIVE'
14+
15+
916
class Employee(Base):
1017
__tablename__ = "employees"
1118

@@ -14,6 +21,8 @@ class Employee(Base):
1421
age = Column(Integer, nullable=False, default=21)
1522
ssn = Column(Unicode(30), nullable=False)
1623
number_of_pets = Column(Integer, default=1, nullable=False)
24+
polarity = Column(Enum(Polarity, native_enum=True))
25+
spin = Column(Enum('spin_down', 'spin_up', native_enum=False))
1726

1827
company_id = Column(
1928
Integer,

test/endtoend/models_right.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
# -*- coding: utf-8 -*-
2-
from sqlalchemy import Column, ForeignKey, Integer, String, Unicode
2+
import enum
3+
4+
from sqlalchemy import Column, Enum, ForeignKey, Integer, String, Unicode
35
from sqlalchemy.ext.declarative import declarative_base
46

57

68
Base = declarative_base()
79

810

11+
class Polarity(enum.Enum):
12+
NEG = 'NEG'
13+
POS = 'POS'
14+
15+
916
class Employee(Base):
1017
__tablename__ = "employees"
1118

@@ -14,6 +21,8 @@ class Employee(Base):
1421
age = Column(Integer, nullable=False, default=21)
1522
ssn = Column(Unicode(30), nullable=False)
1623
number_of_pets = Column(Integer, default=1, nullable=False)
24+
polarity = Column(Enum(Polarity, native_enum=True))
25+
spin = Column(Enum('down', 'up', native_enum=False))
1726

1827
company_id = Column(
1928
Integer,

test/endtoend/test_example.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,39 @@ def test_errors_dict_catches_all_differences(uri_left, uri_right):
108108
}
109109
},
110110
'employees': {
111+
'columns': {
112+
'diff': [
113+
{
114+
'key': 'polarity',
115+
'left': {
116+
'default': None,
117+
'name': 'polarity',
118+
'nullable': True,
119+
'type': "ENUM('NEGATIVE','POSITIVE')"},
120+
'right': {
121+
'default': None,
122+
'name': 'polarity',
123+
'nullable': True,
124+
'type': "ENUM('NEG','POS')"
125+
}
126+
},
127+
{
128+
'key': 'spin',
129+
'left': {
130+
'default': None,
131+
'name': 'spin',
132+
'nullable': True,
133+
'type': 'VARCHAR(9)'
134+
},
135+
'right': {
136+
'default': None,
137+
'name': 'spin',
138+
'nullable': True,
139+
'type': 'VARCHAR(4)'
140+
}
141+
}
142+
]
143+
},
111144
'foreign_keys': {
112145
'left_only': [
113146
{
@@ -215,6 +248,8 @@ def test_errors_dict_catches_all_differences(uri_left, uri_right):
215248
}
216249
}
217250
},
251+
'enums': {
252+
},
218253
'uris': {
219254
'left': uri_left,
220255
'right': uri_right,
@@ -299,6 +334,8 @@ def test_ignores(uri_left, uri_right):
299334
'phone_numbers',
300335
'companies.col.name',
301336
'companies.idx.name',
337+
'employees.col.polarity',
338+
'employees.col.spin',
302339
'employees.fk.fk_employees_companies',
303340
'employees.fk.fk_emp_comp',
304341
'employees.idx.ix_employees_name',
@@ -330,6 +367,8 @@ def test_ignores_alternative_sep(uri_left, uri_right):
330367
'phone_numbers',
331368
'companies#col#name',
332369
'companies#idx#name',
370+
'employees#col#polarity',
371+
'employees#col#spin',
333372
'employees#fk#fk_employees_companies',
334373
'employees#fk#fk_emp_comp',
335374
'employees#idx#ix_employees_name',

test/unit/test_comparer.py

Lines changed: 77 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,15 @@ def _get_tables_info_mock(self):
9393
)
9494
yield m
9595

96+
@pytest.yield_fixture
97+
def _get_enums_data_mock(self):
98+
with patch('sqlalchemydiff.comparer._get_enums_data') as m:
99+
m.return_value = []
100+
yield m
101+
96102
def test_compare_calls_chain(
97103
self, _get_tables_info_mock, _get_tables_data_mock,
98-
_compile_errors_mock):
104+
_get_enums_data_mock, _compile_errors_mock):
99105
"""By inspecting `info` and `errors` at the end, we automatically
100106
check that the whole process works as expected. What this test
101107
leaves out is the verifications about inspectors.
@@ -134,6 +140,12 @@ def test_compare_calls_chain(
134140
'data': 'some-data-B',
135141
},
136142
},
143+
'enums': {
144+
'left_only': [],
145+
'right_only': [],
146+
'common': [],
147+
'diff': [],
148+
},
137149
}
138150

139151
expected_errors = expected_info.copy()
@@ -144,7 +156,8 @@ def test_compare_calls_chain(
144156

145157
def test__get_tables_info_called_with_correct_inspectors(
146158
self, _get_inspectors_mock, _get_tables_info_mock,
147-
_get_tables_data_mock, _compile_errors_mock):
159+
_get_tables_data_mock, _get_enums_data_mock,
160+
_compile_errors_mock):
148161
left_inspector, right_inspector = _get_inspectors_mock.return_value
149162

150163
compare("left_uri", "right_uri", ignores=['ignore_me'])
@@ -219,6 +232,11 @@ def _get_columns_info_mock(self):
219232
with patch('sqlalchemydiff.comparer._get_columns_info') as m:
220233
yield m
221234

235+
@pytest.yield_fixture
236+
def _get_constraints_info_mock(self):
237+
with patch('sqlalchemydiff.comparer._get_constraints_info') as m:
238+
yield m
239+
222240
# TESTS
223241

224242
def test__get_inspectors(self):
@@ -302,6 +320,7 @@ def test__get_info_dict(self):
302320
'common': ['C'],
303321
},
304322
'tables_data': {},
323+
'enums': {},
305324
}
306325

307326
assert expected_info == info
@@ -616,7 +635,8 @@ def test_process_type(self):
616635

617636
def test__get_table_data(
618637
self, _get_foreign_keys_info_mock, _get_primary_keys_info_mock,
619-
_get_indexes_info_mock, _get_columns_info_mock):
638+
_get_indexes_info_mock, _get_columns_info_mock,
639+
_get_constraints_info_mock):
620640
left_inspector, right_inspector = Mock(), Mock()
621641

622642
_get_foreign_keys_info_mock.return_value = {
@@ -631,6 +651,9 @@ def test__get_table_data(
631651
_get_columns_info_mock.return_value = {
632652
'left_only': 13, 'right_only': 14, 'common': 15, 'diff': 16
633653
}
654+
_get_constraints_info_mock.return_value = {
655+
'left_only': 17, 'right_only': 18, 'common': 19, 'diff': 20
656+
}
634657

635658
result = _get_table_data(
636659
left_inspector, right_inspector, 'table_A', Mock()
@@ -661,6 +684,12 @@ def test__get_table_data(
661684
'common': 15,
662685
'diff': 16,
663686
},
687+
'constraints': {
688+
'left_only': 17,
689+
'right_only': 18,
690+
'common': 19,
691+
'diff': 20,
692+
},
664693
}
665694

666695
assert expected_result == result
@@ -704,6 +733,12 @@ def test__compile_errors_with_errors(self):
704733
'right_only': 14,
705734
'common': 15,
706735
'diff': 16,
736+
},
737+
'constraints': {
738+
'left_only': 17,
739+
'right_only': 18,
740+
'common': 19,
741+
'diff': 20,
707742
}
708743
},
709744

@@ -731,8 +766,20 @@ def test__compile_errors_with_errors(self):
731766
'right_only': 14,
732767
'common': 15,
733768
'diff': 16,
769+
},
770+
'constraints': {
771+
'left_only': 17,
772+
'right_only': 18,
773+
'common': 19,
774+
'diff': 20,
734775
}
735776
}
777+
},
778+
'enums': {
779+
'left_only': 21,
780+
'right_only': 22,
781+
'common': 23,
782+
'diff': 24,
736783
}
737784
}
738785

@@ -766,6 +813,11 @@ def test__compile_errors_with_errors(self):
766813
'left_only': 13,
767814
'right_only': 14,
768815
'diff': 16,
816+
},
817+
'constraints': {
818+
'left_only': 17,
819+
'right_only': 18,
820+
'diff': 20,
769821
}
770822
},
771823

@@ -789,8 +841,18 @@ def test__compile_errors_with_errors(self):
789841
'left_only': 13,
790842
'right_only': 14,
791843
'diff': 16,
844+
},
845+
'constraints': {
846+
'left_only': 17,
847+
'right_only': 18,
848+
'diff': 20,
792849
}
793850
}
851+
},
852+
'enums': {
853+
'left_only': 21,
854+
'right_only': 22,
855+
'diff': 24,
794856
}
795857
}
796858

@@ -837,7 +899,19 @@ def test__compile_errors_without_errors(self):
837899
'common': 4,
838900
'diff': [],
839901
},
902+
'constraints': {
903+
'left_only': [],
904+
'right_only': [],
905+
'common': 5,
906+
'diff': [],
907+
},
840908
}
909+
},
910+
'enums': {
911+
'left_only': [],
912+
'right_only': [],
913+
'common': 6,
914+
'diff': [],
841915
}
842916
}
843917

test/unit/test_util.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,13 @@ def test_identifier_incorrect(self):
210210
IgnoreManager(ignore_data)
211211

212212
assert (
213-
"unknown is invalid. It must be in ['pk', 'fk', 'idx', 'col']",
213+
"unknown is invalid. It must be in "
214+
"['pk', 'fk', 'idx', 'col', 'cons', 'enum']",
214215
) == err.value.args
215216

216217
@pytest.mark.parametrize('clause', [
217-
'too.few',
218-
'too.many.definitely.for-sure',
218+
'too.few',
219+
'too.many.definitely.for-sure',
219220
])
220221
def test_incorrect_clause(self, clause):
221222
ignore_data = [clause]
@@ -229,8 +230,8 @@ def test_incorrect_clause(self, clause):
229230
) == err.value.args
230231

231232
@pytest.mark.parametrize('clause', [
232-
'.pk.b',
233-
'a.pk.',
233+
'.pk.b',
234+
'a.pk.',
234235
])
235236
def test_incorrect_empty_clause(self, clause):
236237
ignore_data = [clause]

0 commit comments

Comments
 (0)