from graphql.pyutils import Path


def describe_path():
    def add_path():
        path = Path(None, 0, None)
        assert path.prev is None
        assert path.key == 0
        prev, path = path, Path(path, 1, None)
        assert path.prev is prev
        assert path.key == 1
        prev, path = path, Path(path, "two", None)
        assert path.prev is prev
        assert path.key == "two"

    def add_key():
        prev = Path(None, 0, None)
        path = prev.add_key("one")
        assert path.prev is prev
        assert path.key == "one"

    def as_list():
        path = Path(None, 1, None)
        assert path.as_list() == [1]
        path = path.add_key("two")
        assert path.as_list() == [1, "two"]
        path = path.add_key(3)
        assert path.as_list() == [1, "two", 3]

from graphql.pyutils import Path


def describe_path():
    def can_create_a_path():
        first = Path(None, 1, "First")
        assert first.prev is None
        assert first.key == 1
        assert first.typename == "First"

    def can_add_a_new_key_to_an_existing_path():
        first = Path(None, 1, "First")
        second = first.add_key("two", "Second")
        assert second.prev is first
        assert second.key == "two"
        assert second.typename == "Second"

    def can_convert_a_path_to_a_list_of_its_keys():
        root = Path(None, 0, "Root")
        assert root.as_list() == [0]
        first = root.add_key("one", "First")
        assert first.as_list() == [0, "one"]
        second = first.add_key(2, "Second")
        assert second.as_list() == [0, "one", 2]

Improve tests for Path methods
Improve tests for Path methods

Replicates graphql/graphql-js@f42cee922d13576b1452bb5bf6c7b155bf0e2ecd

  from graphql.pyutils import Path
  
  
  def describe_path():
-     def add_path():
-         path = Path(None, 0, None)
+     def can_create_a_path():
+         first = Path(None, 1, "First")
-         assert path.prev is None
+         assert first.prev is None
-         assert path.key == 0
-         prev, path = path, Path(path, 1, None)
-         assert path.prev is prev
-         assert path.key == 1
+         assert first.key == 1
+         assert first.typename == "First"
-         prev, path = path, Path(path, "two", None)
-         assert path.prev is prev
-         assert path.key == "two"
  
-     def add_key():
-         prev = Path(None, 0, None)
-         path = prev.add_key("one")
-         assert path.prev is prev
+     def can_add_a_new_key_to_an_existing_path():
+         first = Path(None, 1, "First")
+         second = first.add_key("two", "Second")
+         assert second.prev is first
-         assert path.key == "one"
+         assert second.key == "two"
+         assert second.typename == "Second"
  
-     def as_list():
+     def can_convert_a_path_to_a_list_of_its_keys():
-         path = Path(None, 1, None)
+         root = Path(None, 0, "Root")
-         assert path.as_list() == [1]
+         assert root.as_list() == [0]
-         path = path.add_key("two")
+         first = root.add_key("one", "First")
-         assert path.as_list() == [1, "two"]
+         assert first.as_list() == [0, "one"]
-         path = path.add_key(3)
+         second = first.add_key(2, "Second")
-         assert path.as_list() == [1, "two", 3]
+         assert second.as_list() == [0, "one", 2]
  
Improve tests for Path methods
## Code Before:
from graphql.pyutils import Path


def describe_path():
    def add_path():
        path = Path(None, 0, None)
        assert path.prev is None
        assert path.key == 0
        prev, path = path, Path(path, 1, None)
        assert path.prev is prev
        assert path.key == 1
        prev, path = path, Path(path, "two", None)
        assert path.prev is prev
        assert path.key == "two"

    def add_key():
        prev = Path(None, 0, None)
        path = prev.add_key("one")
        assert path.prev is prev
        assert path.key == "one"

    def as_list():
        path = Path(None, 1, None)
        assert path.as_list() == [1]
        path = path.add_key("two")
        assert path.as_list() == [1, "two"]
        path = path.add_key(3)
        assert path.as_list() == [1, "two", 3]

## Instruction:
Improve tests for Path methods
## Code After:
from graphql.pyutils import Path


def describe_path():
    def can_create_a_path():
        first = Path(None, 1, "First")
        assert first.prev is None
        assert first.key == 1
        assert first.typename == "First"

    def can_add_a_new_key_to_an_existing_path():
        first = Path(None, 1, "First")
        second = first.add_key("two", "Second")
        assert second.prev is first
        assert second.key == "two"
        assert second.typename == "Second"

    def can_convert_a_path_to_a_list_of_its_keys():
        root = Path(None, 0, "Root")
        assert root.as_list() == [0]
        first = root.add_key("one", "First")
        assert first.as_list() == [0, "one"]
        second = first.add_key(2, "Second")
        assert second.as_list() == [0, "one", 2]
