Skip to content

Commit 2133aff

Browse files
committed
Avoid warning for super() of NamedTuple
Also add stricter tests for SourceLocation
1 parent ca0f9e6 commit 2133aff

File tree

3 files changed

+43
-12
lines changed

3 files changed

+43
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ The current version 3.0.0b0 of GraphQL-core is up-to-date
1616
with GraphQL.js version 14.5.0.
1717

1818
All parts of the API are covered by an extensive test suite
19-
of currently 1983 unit tests.
19+
of currently 1987 unit tests.
2020

2121

2222
## Documentation

src/graphql/language/location.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ def formatted(self):
1818

1919
def __eq__(self, other):
2020
if isinstance(other, dict):
21-
return other == self.formatted
22-
return super().__eq__(other)
21+
return self.formatted == other
22+
return tuple(self) == other
2323

2424
def __ne__(self, other):
2525
return not self == other

tests/language/test_location.py

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,43 @@
11
from graphql import SourceLocation
22

33

4-
def describe_SourceLocation():
5-
def equals_with_itself():
6-
assert SourceLocation(1, 2) == SourceLocation(1, 2)
7-
assert (SourceLocation(1, 2) != SourceLocation(1, 2)) is False
8-
9-
def equals_with_formatted_form():
10-
sl = SourceLocation(1, 2)
11-
assert SourceLocation(1, 2) == sl.formatted
12-
assert (SourceLocation(1, 2) != sl.formatted) is False
4+
def describe_source_location():
5+
def can_be_formatted():
6+
location = SourceLocation(1, 2)
7+
assert location.formatted == {"line": 1, "column": 2}
8+
9+
def can_compare_with_other_source_location():
10+
location = SourceLocation(1, 2)
11+
same_location = SourceLocation(1, 2)
12+
assert location == same_location
13+
assert not location != same_location
14+
different_location = SourceLocation(1, 1)
15+
assert not location == different_location
16+
assert location != different_location
17+
different_location = SourceLocation(2, 2)
18+
assert not location == different_location
19+
assert location != different_location
20+
21+
def can_compare_with_location_tuple():
22+
location = SourceLocation(1, 2)
23+
same_location = (1, 2)
24+
assert location == same_location
25+
assert not location != same_location
26+
different_location = (1, 1)
27+
assert not location == different_location
28+
assert location != different_location
29+
different_location = (2, 2)
30+
assert not location == different_location
31+
assert location != different_location
32+
33+
def can_compare_with_formatted_location():
34+
location = SourceLocation(1, 2)
35+
same_location = location.formatted
36+
assert location == same_location
37+
assert not location != same_location
38+
different_location = SourceLocation(1, 1).formatted
39+
assert not location == different_location
40+
assert location != different_location
41+
different_location = SourceLocation(2, 2).formatted
42+
assert not location == different_location
43+
assert location != different_location

0 commit comments

Comments
 (0)