Skip to content

Commit 4aecd32

Browse files
authored
Merge pull request #178 from dan98765/daniellg_add_precommit
Add pre-commit tool to repository, and run on all files.
2 parents aae1d69 + ffa86a8 commit 4aecd32

22 files changed

+67
-34
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ htmlcov/
4646
nosetests.xml
4747
coverage.xml
4848
*,cover
49+
.pytest_cache/
4950

5051
# Translations
5152
*.mo

.pre-commit-config.yaml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
- repo: git://github.com/pre-commit/pre-commit-hooks
2+
sha: v0.8.0
3+
hooks:
4+
- id: autopep8-wrapper
5+
args:
6+
- -i
7+
- --ignore=E128,E309,E501
8+
exclude: ^docs/.*$
9+
- id: check-json
10+
- id: check-yaml
11+
- id: debug-statements
12+
- id: end-of-file-fixer
13+
exclude: ^docs/.*$
14+
- id: trailing-whitespace
15+
- id: pretty-format-json
16+
args:
17+
- --autofix
18+
- --indent=4

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ For questions, ask [Stack Overflow](http://stackoverflow.com/questions/tagged/gr
1717

1818
## Getting Started
1919

20-
An overview of the GraphQL language is available in the
20+
An overview of the GraphQL language is available in the
2121
[README](https://github.com/facebook/graphql/blob/master/README.md) for the
22-
[Specification for GraphQL](https://github.com/facebook/graphql).
22+
[Specification for GraphQL](https://github.com/facebook/graphql).
2323

2424
The overview describes a simple set of GraphQL examples that exist as [tests](https://github.com/graphql-python/graphql-core/tree/master/tests/)
2525
in this repository. A good way to get started is to walk through that README and the corresponding tests
26-
in parallel.
26+
in parallel.
2727

2828
### Using graphql-core
2929

graphql/error/tests/test_base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def resolver(context, *_):
3939
formatted_tb = [row[2:] for row in extracted]
4040
if formatted_tb[2][0] == 'reraise':
4141
formatted_tb[2:] = formatted_tb[3:]
42-
42+
4343
assert formatted_tb == [
4444
('test_reraise', 'result.errors[0].reraise()'),
4545
('reraise', 'six.reraise(type(self), self, self.stack)'),

graphql/execution/executor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def resolve_field(exe_context, parent_type, source, field_asts, parent_info):
256256
operation=exe_context.operation,
257257
variable_values=exe_context.variable_values,
258258
context=context,
259-
path=parent_info.path+[field_name] if parent_info else [field_name]
259+
path=parent_info.path + [field_name] if parent_info else [field_name]
260260
)
261261

262262
executor = exe_context.executor

graphql/execution/tests/test_abstract.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def __init__(self, name):
2525
self.name = name
2626

2727

28-
is_type_of = lambda type: lambda obj, info: isinstance(obj, type)
28+
def is_type_of(type): return lambda obj, info: isinstance(obj, type)
2929

3030

3131
def make_type_resolver(types):

graphql/execution/tests/test_dataloader.py

+11-14
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ def test_batches_correctly(executor):
2828

2929
schema = GraphQLSchema(query=Query)
3030

31-
3231
doc = '''
3332
{
3433
business1: getBusiness(id: "1") {
@@ -41,9 +40,8 @@ def test_batches_correctly(executor):
4140
'''
4241
doc_ast = parse(doc)
4342

44-
4543
load_calls = []
46-
44+
4745
class BusinessDataLoader(DataLoader):
4846
def batch_load_fn(self, keys):
4947
load_calls.append(keys)
@@ -52,7 +50,6 @@ def batch_load_fn(self, keys):
5250
class Context(object):
5351
business_data_loader = BusinessDataLoader()
5452

55-
5653
result = execute(schema, doc_ast, None, context_value=Context(), executor=executor)
5754
assert not result.errors
5855
assert result.data == {
@@ -63,7 +60,7 @@ class Context(object):
6360
'id': '2'
6461
},
6562
}
66-
assert load_calls == [['1','2']]
63+
assert load_calls == [['1', '2']]
6764

6865

6966
@pytest.mark.parametrize("executor", [
@@ -78,8 +75,11 @@ def test_batches_multiple_together(executor):
7875

7976
Business = GraphQLObjectType('Business', lambda: {
8077
'id': GraphQLField(GraphQLID, resolver=lambda root, info, **args: root),
81-
'location': GraphQLField(Location,
82-
resolver=lambda root, info, **args: info.context.location_data_loader.load('location-{}'.format(root))
78+
'location': GraphQLField(
79+
Location,
80+
resolver=lambda root, info, **args: info.context.location_data_loader.load(
81+
'location-{}'.format(root)
82+
)
8383
),
8484
})
8585

@@ -94,7 +94,6 @@ def test_batches_multiple_together(executor):
9494

9595
schema = GraphQLSchema(query=Query)
9696

97-
9897
doc = '''
9998
{
10099
business1: getBusiness(id: "1") {
@@ -113,16 +112,15 @@ def test_batches_multiple_together(executor):
113112
'''
114113
doc_ast = parse(doc)
115114

116-
117115
business_load_calls = []
118-
116+
119117
class BusinessDataLoader(DataLoader):
120118
def batch_load_fn(self, keys):
121119
business_load_calls.append(keys)
122120
return Promise.resolve(keys)
123121

124122
location_load_calls = []
125-
123+
126124
class LocationDataLoader(DataLoader):
127125
def batch_load_fn(self, keys):
128126
location_load_calls.append(keys)
@@ -132,7 +130,6 @@ class Context(object):
132130
business_data_loader = BusinessDataLoader()
133131
location_data_loader = LocationDataLoader()
134132

135-
136133
result = execute(schema, doc_ast, None, context_value=Context(), executor=executor)
137134
assert not result.errors
138135
assert result.data == {
@@ -149,5 +146,5 @@ class Context(object):
149146
}
150147
},
151148
}
152-
assert business_load_calls == [['1','2']]
153-
assert location_load_calls == [['location-1','location-2']]
149+
assert business_load_calls == [['1', '2']]
150+
assert location_load_calls == [['location-1', 'location-2']]

graphql/execution/tests/test_executor.py

-1
Original file line numberDiff line numberDiff line change
@@ -812,4 +812,3 @@ def resolve(self, _next, root, info, *args, **kwargs):
812812
['feed', 1, 'author', 'id'],
813813
['feed', 1, 'author', 'name']
814814
]
815-

graphql/execution/tests/test_located_error.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ def resolver(context, *_):
2020
})
2121

2222
result = execute(GraphQLSchema(Type), ast)
23-
assert isinstance(result.errors[0], GraphQLLocatedError)
23+
assert isinstance(result.errors[0], GraphQLLocatedError)

graphql/execution/tests/test_resolve.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
GraphQLObjectType, GraphQLSchema, GraphQLString)
99
from promise import Promise
1010

11+
1112
class CustomPromise(Promise):
1213
@classmethod
1314
def fulfilled(cls, x):
@@ -150,7 +151,6 @@ def test_maps_argument_out_names_well_with_input():
150151
def resolver(source, info, **args):
151152
return json.dumps([source, args], separators=(',', ':'))
152153

153-
154154
TestInputObject = GraphQLInputObjectType('TestInputObject', lambda: OrderedDict([
155155
('inputOne', GraphQLInputObjectField(GraphQLString, out_name="input_one")),
156156
('inputRecursive', GraphQLInputObjectField(TestInputObject, out_name="input_recursive")),

graphql/execution/tests/test_variables.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ class my_special_dict(dict):
3535
('a', GraphQLInputObjectField(GraphQLString)),
3636
]), container_type=my_special_dict)
3737

38-
stringify = lambda obj: json.dumps(obj, sort_keys=True)
38+
39+
def stringify(obj): return json.dumps(obj, sort_keys=True)
3940

4041

4142
def input_to_json(obj, info, **args):

graphql/language/printer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def leave_SchemaDefinition(self, node, *args):
116116
'schema',
117117
join(node.directives, ' '),
118118
block(node.operation_types),
119-
], ' ')
119+
], ' ')
120120

121121
def leave_OperationTypeDefinition(self, node, *args):
122122
return '{}: {}'.format(node.operation, node.type)

graphql/type/definition.py

+2
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ class GraphQLObjectType(GraphQLType):
161161
'bestFriend': GraphQLField(PersonType)
162162
})
163163
"""
164+
164165
def __init__(self, name, fields, interfaces=None, is_type_of=None, description=None):
165166
assert name, 'Type must be named.'
166167
assert_valid_name(name)
@@ -513,6 +514,7 @@ class GeoPoint(GraphQLInputObjectType):
513514
default_value=0)
514515
}
515516
"""
517+
516518
def __init__(self, name, fields, description=None, container_type=None):
517519
assert name, 'Type must be named.'
518520
self.name = name

graphql/type/tests/test_schema.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
'field_name': GraphQLField(
1010
type=GraphQLString,
1111
resolver=lambda *_: implementing_type
12-
)
12+
)
1313
}
1414
)
1515

@@ -31,6 +31,7 @@
3131
)
3232
)
3333

34+
3435
def test_throws_human_readable_error_if_schematypes_not_defined():
3536
with raises(AssertionError) as exci:
3637
schema.is_possible_type(interface_type, implementing_type)

graphql/type/typemap.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def is_possible_type(self, abstract_type, possible_type):
4141
'Could not find possible implementing types for ${} in ' +
4242
'schema. Check that schema.types is defined and is an array of' +
4343
'all possible types in the schema.'
44-
).format(abstract_type)
44+
).format(abstract_type)
4545

4646
if not self._possible_type_map[abstract_type.name]:
4747
self._possible_type_map[abstract_type.name].update([p.name for p in possible_types])

graphql/utils/tests/test_ast_to_code.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ def test_ast_to_code_using_kitchen_sink():
1010
doc = parse(fixtures.KITCHEN_SINK)
1111
code_ast = ast_to_code(doc)
1212
source = Source(fixtures.KITCHEN_SINK)
13-
loc = lambda start, end: Loc(start, end, source)
13+
14+
def loc(start, end): return Loc(start, end, source)
1415

1516
parsed_code_ast = eval(code_ast, {}, {'ast': ast, 'loc': loc})
1617
assert doc == parsed_code_ast

graphql/utils/tests/test_build_client_schema.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ def test_succeds_on_smaller_equals_than_7_deep_lists():
619619
GraphQLNonNull(GraphQLList(GraphQLNonNull(
620620
GraphQLList(GraphQLNonNull(GraphQLString))
621621
))
622-
)))
622+
)))
623623
)
624624
}
625625
)

graphql/utils/tests/test_quoted_or_list.py

+4
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,18 @@ def test_does_not_accept_an_empty_list():
77
with raises(StopIteration):
88
quoted_or_list([])
99

10+
1011
def test_returns_single_quoted_item():
1112
assert quoted_or_list(['A']) == '"A"'
1213

14+
1315
def test_returns_two_item_list():
1416
assert quoted_or_list(['A', 'B']) == '"A" or "B"'
1517

18+
1619
def test_returns_comma_separated_many_item_list():
1720
assert quoted_or_list(['A', 'B', 'C']) == '"A", "B" or "C"'
1821

22+
1923
def test_limits_to_five_items():
2024
assert quoted_or_list(['A', 'B', 'C', 'D', 'E', 'F']) == '"A", "B", "C", "D" or "E"'

graphql/validation/rules/overlapping_fields_can_be_merged.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def _find_conflicts_within_selection_set(context, cached_fields_and_fragment_nam
161161
# selection set to collect conflicts within fragments spread together.
162162
# This compares each item in the list of fragment names to every other item
163163
# in that same list (except for itself).
164-
for other_fragment_name in fragment_names[i+1:]:
164+
for other_fragment_name in fragment_names[i + 1:]:
165165
_collect_conflicts_between_fragments(
166166
context,
167167
conflicts,
@@ -304,7 +304,7 @@ def _collect_conflicts_within(context, conflicts, cached_fields_and_fragment_nam
304304
# (except to itself). If the list only has one item, nothing needs to
305305
# be compared.
306306
for i, field in enumerate(fields):
307-
for other_field in fields[i+1:]:
307+
for other_field in fields[i + 1:]:
308308
# within one collection is never mutually exclusive
309309
conflict = _find_conflict(context, cached_fields_and_fragment_names, compared_fragments, False,
310310
response_name, field, other_field)

scripts/casing.py

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# LICENSE file in the root directory of this source tree. An additional grant
66
# of patent rights can be found in the PATENTS file in the same directory.
77

8+
89
def title(s):
910
'''Capitalize the first character of s.'''
1011
return s[0].capitalize() + s[1:]

scripts/generate_ast.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
'ArrayValue': 'ListValue',
2121
}
2222

23+
2324
def remap_type(typename):
2425
return REMAP_TYPES.get(typename, typename)
2526

@@ -101,7 +102,7 @@ def _print_copy(self, typename):
101102
[field for field in self._fields if not field[2]] +
102103
[field for field in self._fields if field[2]])
103104
args = '\n'.join(''' self.{},'''.format(snake(name)) for (type, name, nullable, plural) in fields)
104-
print ('''
105+
print('''
105106
def __copy__(self):
106107
return type(self)(
107108
{}
@@ -139,4 +140,3 @@ def union_option(self, option):
139140

140141
def end_union(self, name):
141142
self._current_union = None
142-

tox.ini

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = flake8,isort,py27,py33,py34,py35,pypy,docs
2+
envlist = flake8,isort,py27,py33,py34,py35,pre-commit,pypy,docs
33

44
[testenv]
55
deps =
@@ -13,6 +13,14 @@ commands =
1313
py{27,33,34,py}: py.test graphql tests {posargs}
1414
py35: py.test graphql tests tests_py35 {posargs}
1515

16+
[testenv:pre-commit]
17+
basepython=python3.6
18+
deps =
19+
pre-commit>0.12.0
20+
setenv =
21+
LC_CTYPE=en_US.UTF-8
22+
commands =
23+
pre-commit {posargs:run --all-files}
1624

1725
[testenv:flake8]
1826
deps = flake8

0 commit comments

Comments
 (0)