Skip to content
This repository was archived by the owner on Feb 6, 2025. It is now read-only.

Commit ca96b61

Browse files
authored
Annotate simple test methods to return None. (#907)
* Annotate simple test methods to return None. * Tighten mypy.ini.
1 parent b8de750 commit ca96b61

File tree

8 files changed

+49
-55
lines changed

8 files changed

+49
-55
lines changed

graphql_compiler/tests/schema_generation_tests/test_orientdb_schema_generation.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,15 @@
160160

161161

162162
class GraphqlSchemaGenerationTests(unittest.TestCase):
163-
def test_parsed_vertex(self):
163+
def test_parsed_vertex(self) -> None:
164164
schema_data = [
165165
BASE_VERTEX,
166166
ENTITY,
167167
]
168168
schema_graph = get_orientdb_schema_graph(schema_data, [])
169169
self.assertTrue(schema_graph.get_element_by_class_name("Entity").is_vertex)
170170

171-
def test_parsed_edge(self):
171+
def test_parsed_edge(self) -> None:
172172
schema_data = [
173173
BASE_EDGE,
174174
BASE_VERTEX,
@@ -180,20 +180,20 @@ def test_parsed_edge(self):
180180
schema_graph = get_orientdb_schema_graph(schema_data, [])
181181
self.assertTrue(schema_graph.get_element_by_class_name("Person_LivesIn").is_edge)
182182

183-
def test_parsed_non_graph_class(self):
183+
def test_parsed_non_graph_class(self) -> None:
184184
schema_data = [EXTERNAL_SOURCE]
185185
schema_graph = get_orientdb_schema_graph(schema_data, [])
186186
self.assertTrue(schema_graph.get_element_by_class_name("ExternalSource").is_non_graph)
187187

188-
def test_no_superclass(self):
188+
def test_no_superclass(self) -> None:
189189
schema_data = [BASE_VERTEX]
190190
schema_graph = get_orientdb_schema_graph(schema_data, [])
191191
self.assertEqual(
192192
{ORIENTDB_BASE_VERTEX_CLASS_NAME},
193193
schema_graph.get_superclass_set(ORIENTDB_BASE_VERTEX_CLASS_NAME),
194194
)
195195

196-
def test_parsed_superclass_field(self):
196+
def test_parsed_superclass_field(self) -> None:
197197
schema_data = [
198198
BASE_EDGE,
199199
BASE_VERTEX,
@@ -208,7 +208,7 @@ def test_parsed_superclass_field(self):
208208
schema_graph.get_superclass_set("Person_LivesIn"),
209209
)
210210

211-
def test_parsed_superclasses_field(self):
211+
def test_parsed_superclasses_field(self) -> None:
212212
schema_data = [
213213
BASE_VERTEX,
214214
ENTITY,
@@ -218,7 +218,7 @@ def test_parsed_superclasses_field(self):
218218
{"Entity", ORIENTDB_BASE_VERTEX_CLASS_NAME}, schema_graph.get_superclass_set("Entity")
219219
)
220220

221-
def test_parsed_property(self):
221+
def test_parsed_property(self) -> None:
222222
schema_data = [
223223
BASE_VERTEX,
224224
ENTITY,
@@ -227,7 +227,7 @@ def test_parsed_property(self):
227227
name_property = schema_graph.get_element_by_class_name("Entity").properties["name"]
228228
self.assertTrue(is_same_type(name_property.type, GraphQLString))
229229

230-
def test_native_orientdb_collection_property(self):
230+
def test_native_orientdb_collection_property(self) -> None:
231231
schema_data = [
232232
BASE_VERTEX,
233233
ENTITY,
@@ -238,7 +238,7 @@ def test_native_orientdb_collection_property(self):
238238
self.assertTrue(is_same_type(alias_property.type, GraphQLList(GraphQLString)))
239239
self.assertEqual(alias_property.default, set())
240240

241-
def test_class_collection_property(self):
241+
def test_class_collection_property(self) -> None:
242242
schema_data = [
243243
BASE_VERTEX,
244244
DATA_POINT,
@@ -255,7 +255,7 @@ def test_class_collection_property(self):
255255
)
256256
self.assertEqual(friends_property.default, list())
257257

258-
def test_link_parsing(self):
258+
def test_link_parsing(self) -> None:
259259
schema_data = [
260260
BASE_EDGE,
261261
BASE_VERTEX,
@@ -269,7 +269,7 @@ def test_link_parsing(self):
269269
self.assertEqual(person_lives_in_edge.base_in_connection, "Person")
270270
self.assertEqual(person_lives_in_edge.base_out_connection, "Location")
271271

272-
def test_parsed_class_fields(self):
272+
def test_parsed_class_fields(self) -> None:
273273
schema_data = [
274274
BASE_EDGE,
275275
BASE_VERTEX,
@@ -282,7 +282,7 @@ def test_parsed_class_fields(self):
282282
person_lives_in_edge = schema_graph.get_element_by_class_name("Person_LivesIn")
283283
self.assertEqual(PERSON_LIVES_IN_EDGE["customFields"], person_lives_in_edge.class_fields)
284284

285-
def test_type_equivalence_dicts(self):
285+
def test_type_equivalence_dicts(self) -> None:
286286
schema_data = [
287287
BASE_EDGE,
288288
BASE_VERTEX,
@@ -322,7 +322,7 @@ def test_type_equivalence_dicts(self):
322322
self.assertTrue(is_same_type(baby.fields["out_Person_LivesIn"].type, location_list_type))
323323
self.assertTrue(is_same_type(location.fields["in_Person_LivesIn"].type, union_list_type))
324324

325-
def test_filter_type_equivalences_with_no_edges(self):
325+
def test_filter_type_equivalences_with_no_edges(self) -> None:
326326
schema_data = [
327327
BASE_VERTEX,
328328
BABY,
@@ -338,7 +338,7 @@ def test_filter_type_equivalences_with_no_edges(self):
338338
person_subclass_set = schema_graph.get_subclass_set("Person")
339339
self.assertIsNone(schema.get_type(_get_union_type_name(person_subclass_set)))
340340

341-
def test_edge_inheritance(self):
341+
def test_edge_inheritance(self) -> None:
342342
schema_data = [
343343
BASE_EDGE,
344344
BABY_LIVES_IN_EDGE,
@@ -354,7 +354,7 @@ def test_edge_inheritance(self):
354354
baby_lives_in_edge = schema_graph.get_element_by_class_name("Baby_LivesIn")
355355
self.assertEqual("Baby", baby_lives_in_edge.base_in_connection)
356356

357-
def test_ignore_properties_with_invalid_name_warning(self):
357+
def test_ignore_properties_with_invalid_name_warning(self) -> None:
358358
schema_data = [
359359
BASE_VERTEX,
360360
CLASS_WITH_INVALID_PROPERTY_NAME,
@@ -363,7 +363,7 @@ def test_ignore_properties_with_invalid_name_warning(self):
363363
with pytest.warns(UserWarning):
364364
get_graphql_schema_from_orientdb_schema_data(schema_data)
365365

366-
def test_include_non_graph_classes_in_graphql_schema(self):
366+
def test_include_non_graph_classes_in_graphql_schema(self) -> None:
367367
non_graph_classes_to_include = [
368368
ABSTRACT_NON_GRAPH_CLASS_WITH_ONLY_VERTEX_CONCRETE_SUBCLASSES,
369369
]

graphql_compiler/tests/schema_generation_tests/test_sqlalchemy_schema_generation.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -97,47 +97,47 @@ def setUp(self):
9797
graphql_schema, type_equivalence_hints, dialect, vertex_name_to_table, join_descriptors
9898
)
9999

100-
def test_table_vertex_representation(self):
100+
def test_table_vertex_representation(self) -> None:
101101
self.assertIsInstance(self.schema_info.schema.get_type("Table1"), GraphQLObjectType)
102102

103-
def test_table_vertex_representation_with_non_default_name(self):
103+
def test_table_vertex_representation_with_non_default_name(self) -> None:
104104
self.assertIsInstance(
105105
self.schema_info.schema.get_type("ArbitraryObjectName"), GraphQLObjectType
106106
)
107107

108-
def test_represent_supported_fields(self):
108+
def test_represent_supported_fields(self) -> None:
109109
table1_graphql_object = self.schema_info.schema.get_type("Table1")
110110
self.assertEqual(
111111
table1_graphql_object.fields["column_with_supported_type"].type, GraphQLString
112112
)
113113

114-
def test_ignored_fields_not_supported(self):
114+
def test_ignored_fields_not_supported(self) -> None:
115115
table1_graphql_object = self.schema_info.schema.get_type("Table1")
116116
self.assertTrue("column_with_non_supported_type" not in table1_graphql_object.fields)
117117

118-
def test_warn_when_type_is_not_supported(self):
118+
def test_warn_when_type_is_not_supported(self) -> None:
119119
with pytest.warns(Warning):
120120
try_get_graphql_scalar_type("binary", LargeBinary())
121121

122-
def test_support_sql_tz_naive_datetime_types(self):
122+
def test_support_sql_tz_naive_datetime_types(self) -> None:
123123
column_name = "tz_naive_datetime"
124124
tz_naive_types = (DateTime(timezone=False), TIMESTAMP(timezone=False))
125125
for sql_type in tz_naive_types:
126126
self.assertEqual(GraphQLDateTime, try_get_graphql_scalar_type(column_name, sql_type))
127127

128-
def test_do_not_support_sql_tz_aware_datetime_types(self):
128+
def test_do_not_support_sql_tz_aware_datetime_types(self) -> None:
129129
column_name = "tz_aware_datetime"
130130
tz_aware_types = (DateTime(timezone=True), TIMESTAMP(timezone=True))
131131
for sql_type in tz_aware_types:
132132
with self.assertWarns(Warning):
133133
graphql_type = try_get_graphql_scalar_type(column_name, sql_type)
134134
self.assertIsNone(graphql_type)
135135

136-
def test_mssql_scalar_type_representation(self):
136+
def test_mssql_scalar_type_representation(self) -> None:
137137
table1_graphql_object = self.schema_info.schema.get_type("Table1")
138138
self.assertEqual(table1_graphql_object.fields["column_with_mssql_type"].type, GraphQLInt)
139139

140-
def test_direct_sql_edge_representation(self):
140+
def test_direct_sql_edge_representation(self) -> None:
141141
table1_graphql_object = self.schema_info.schema.get_type("Table1")
142142
arbitrarily_named_graphql_object = self.schema_info.schema.get_type("ArbitraryObjectName")
143143
self.assertEqual(
@@ -147,7 +147,7 @@ def test_direct_sql_edge_representation(self):
147147
arbitrarily_named_graphql_object.fields["in_test_edge"].type.of_type.name, "Table1"
148148
)
149149

150-
def test_get_join_descriptors(self):
150+
def test_get_join_descriptors(self) -> None:
151151
expected_join_descriptors = {
152152
"Table1": {
153153
"out_test_edge": DirectJoinDescriptor("source_column", "destination_column")
@@ -158,7 +158,7 @@ def test_get_join_descriptors(self):
158158
}
159159
self.assertEqual(expected_join_descriptors, self.schema_info.join_descriptors)
160160

161-
def test_basic_index_generation_from_primary_key(self):
161+
def test_basic_index_generation_from_primary_key(self) -> None:
162162
indexes = self.schema_graph.get_all_indexes_for_class("Table1")
163163
self.assertIn(
164164
IndexDefinition(
@@ -172,7 +172,7 @@ def test_basic_index_generation_from_primary_key(self):
172172
indexes,
173173
)
174174

175-
def test_index_generation_from_multi_column_primary_key(self):
175+
def test_index_generation_from_multi_column_primary_key(self) -> None:
176176
indexes = self.schema_graph.get_all_indexes_for_class("TableWithMultiplePrimaryKeyColumns")
177177
self.assertEqual(
178178
{
@@ -188,11 +188,11 @@ def test_index_generation_from_multi_column_primary_key(self):
188188
indexes,
189189
)
190190

191-
def test_index_generation_from_primary_key_with_an_unsupported_column_type(self):
191+
def test_index_generation_from_primary_key_with_an_unsupported_column_type(self) -> None:
192192
indexes = self.schema_graph.get_all_indexes_for_class("TableWithNonSupportedPrimaryKeyType")
193193
self.assertEqual(frozenset(), indexes)
194194

195-
def test_index_generation_from_unique_constraint(self):
195+
def test_index_generation_from_unique_constraint(self) -> None:
196196
indexes = self.schema_graph.get_all_indexes_for_class("Table1")
197197
self.assertIn(
198198
IndexDefinition(
@@ -209,7 +209,7 @@ def test_index_generation_from_unique_constraint(self):
209209

210210
@pytest.mark.filterwarnings("ignore: Ignored .* edges implied by composite foreign keys.*")
211211
class SQLAlchemyForeignKeyEdgeGenerationTests(unittest.TestCase):
212-
def test_edge_generation_from_foreign_keys(self):
212+
def test_edge_generation_from_foreign_keys(self) -> None:
213213
metadata = MetaData()
214214

215215
table1 = Table(
@@ -242,7 +242,7 @@ def test_edge_generation_from_foreign_keys(self):
242242
},
243243
)
244244

245-
def test_warning_for_ignored_foreign_keys(self):
245+
def test_warning_for_ignored_foreign_keys(self) -> None:
246246
metadata = MetaData()
247247

248248
table1 = Table(
@@ -281,7 +281,7 @@ class SQLAlchemySchemaInfoGenerationErrorTests(unittest.TestCase):
281281
def setUp(self):
282282
self.vertex_name_to_table = _get_test_vertex_name_to_table()
283283

284-
def test_reference_to_non_existent_source_vertex(self):
284+
def test_reference_to_non_existent_source_vertex(self) -> None:
285285
direct_edges = {
286286
"invalid_source_vertex": DirectEdgeDescriptor(
287287
"InvalidVertexName", "source_column", "ArbitraryObjectName", "destination_column"
@@ -290,7 +290,7 @@ def test_reference_to_non_existent_source_vertex(self):
290290
with self.assertRaises(InvalidSQLEdgeError):
291291
get_sqlalchemy_schema_info(self.vertex_name_to_table, direct_edges, dialect())
292292

293-
def test_reference_to_non_existent_destination_vertex(self):
293+
def test_reference_to_non_existent_destination_vertex(self) -> None:
294294
direct_edges = {
295295
"invalid_source_vertex": DirectEdgeDescriptor(
296296
"Table1", "source_column", "InvalidVertexName", "destination_column"
@@ -299,7 +299,7 @@ def test_reference_to_non_existent_destination_vertex(self):
299299
with self.assertRaises(InvalidSQLEdgeError):
300300
get_sqlalchemy_schema_info(self.vertex_name_to_table, direct_edges, dialect())
301301

302-
def test_reference_to_non_existent_source_column(self):
302+
def test_reference_to_non_existent_source_column(self) -> None:
303303
direct_edges = {
304304
"invalid_source_vertex": DirectEdgeDescriptor(
305305
"Table1", "invalid_column_name", "ArbitraryObjectName", "destination_column"
@@ -308,7 +308,7 @@ def test_reference_to_non_existent_source_column(self):
308308
with self.assertRaises(InvalidSQLEdgeError):
309309
get_sqlalchemy_schema_info(self.vertex_name_to_table, direct_edges, dialect())
310310

311-
def test_reference_to_non_existent_destination_column(self):
311+
def test_reference_to_non_existent_destination_column(self) -> None:
312312
direct_edges = {
313313
"invalid_destination_column": DirectEdgeDescriptor(
314314
"Table1", "source_column", "ArbitraryObjectName", "invalid_column_name"
@@ -317,15 +317,15 @@ def test_reference_to_non_existent_destination_column(self):
317317
with self.assertRaises(InvalidSQLEdgeError):
318318
get_sqlalchemy_schema_info(self.vertex_name_to_table, direct_edges, dialect())
319319

320-
def test_missing_primary_key(self):
320+
def test_missing_primary_key(self) -> None:
321321
table_without_primary_key = Table(
322322
"TableWithoutPrimaryKey", MetaData(), Column("arbitrary_column", String()),
323323
)
324324
faulty_vertex_name_to_table = {table_without_primary_key.name: table_without_primary_key}
325325
with self.assertRaises(MissingPrimaryKeyError):
326326
get_sqlalchemy_schema_info(faulty_vertex_name_to_table, {}, dialect())
327327

328-
def test_missing_multiple_primary_keys(self):
328+
def test_missing_multiple_primary_keys(self) -> None:
329329
metadata: MetaData = MetaData()
330330
table_without_primary_key: Table = Table(
331331
"TableWithoutPrimaryKey", metadata, Column("arbitrary_column", String()),

graphql_compiler/tests/test_end_to_end.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ def test_invalid_directive_comparison(self) -> None:
366366
)
367367
self.assertEqual(datetime.datetime(2014, 2, 5, 3, 20, 55), value)
368368

369-
def test_deserialize_lists(self):
369+
def test_deserialize_lists(self) -> None:
370370
# Non-collection
371371
with self.assertRaises(GraphQLInvalidArgumentError):
372372
deserialize_argument("numbers", GraphQLList(GraphQLInt), 1)

graphql_compiler/tests/test_global_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
class GlobalUtilTests(unittest.TestCase):
8-
def test_assert_equality(self):
8+
def test_assert_equality(self) -> None:
99
# Matching sets
1010
assert_set_equality({"a", "b"}, {"a", "b"})
1111

graphql_compiler/tests/test_sqlalchemy_extensions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def setUp(self):
1414
self.maxDiff = None
1515
self.sql_schema_info = get_sqlalchemy_schema_info()
1616

17-
def test_print_query_mssql_basic(self):
17+
def test_print_query_mssql_basic(self) -> None:
1818
query = sqlalchemy.select([self.sql_schema_info.vertex_name_to_table["Animal"].c.name])
1919
text = print_sqlalchemy_query_string(query, mssql.dialect())
2020
expected_text = """
@@ -23,7 +23,7 @@ def test_print_query_mssql_basic(self):
2323
"""
2424
compare_sql(self, expected_text, text)
2525

26-
def test_print_query_mssql_string_argument(self):
26+
def test_print_query_mssql_string_argument(self) -> None:
2727
animal = self.sql_schema_info.vertex_name_to_table["Animal"].alias()
2828
query = sqlalchemy.select([animal.c.name]).where(
2929
animal.c.name == sqlalchemy.bindparam("name", expanding=False)
@@ -36,7 +36,7 @@ def test_print_query_mssql_string_argument(self):
3636
"""
3737
compare_sql(self, expected_text, text)
3838

39-
def test_print_query_mssql_list_argument(self):
39+
def test_print_query_mssql_list_argument(self) -> None:
4040
animal = self.sql_schema_info.vertex_name_to_table["Animal"].alias()
4141
query = sqlalchemy.select([animal.c.name]).where(
4242
animal.c.name.in_(sqlalchemy.bindparam("names", expanding=True))

graphql_compiler/tests/test_subclass.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def setUp(self):
1212
"""Initialize the test schema once for all tests."""
1313
self.schema = get_schema()
1414

15-
def test_compute_subclass_sets(self):
15+
def test_compute_subclass_sets(self) -> None:
1616
type_equivalence_hints = {
1717
self.schema.get_type("Event"): self.schema.get_type(
1818
"Union__BirthEvent__Event__FeedingEvent"

graphql_compiler/tests/test_testing_invariants.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def setUp(self):
2121
if input_name not in IGNORED_FUNCTIONS
2222
}
2323

24-
def test_ir_generation_test_invariants(self):
24+
def test_ir_generation_test_invariants(self) -> None:
2525
# Importing IrGenerationTests globally would expose them to py.test a second time.
2626
# We import them here so that these tests are not run again.
2727
from .test_ir_generation import IrGenerationTests
@@ -35,7 +35,7 @@ def test_ir_generation_test_invariants(self):
3535
)
3636
)
3737

38-
def test_compiler_test_invariants(self):
38+
def test_compiler_test_invariants(self) -> None:
3939
# Importing CompilerTests globally would expose them to py.test a second time.
4040
# We import them here so that these tests are not run again.
4141
from .test_compiler import CompilerTests

0 commit comments

Comments
 (0)