from directions import load_directions, turn, follow_directions


def test_load_directions():
    with open("directions.txt") as f:
        directions = [direction.strip(',')
                      for direction
                      in f.readline().strip().split()]
    assert load_directions("directions.txt") == directions, \
        "Failed to load directions from directions.txt."


def test_turn():
    assert turn('N', 'R') == 'E'
    assert turn('N', 'L') == 'W'
    assert turn('E', 'R') == 'S'
    assert turn('E', 'L') == 'N'
    assert turn('S', 'R') == 'W'
    assert turn('S', 'L') == 'E'
    assert turn('W', 'R') == 'N'
    assert turn('W', 'L') == 'S'


def test_follow_directions():
    starting_point = (0, 0)
    starting_orientation = 'N'
    directions = ['R2', 'L3', 'R1']
    ending_point = (3, 3)
    ending_orientation = 'E'
    assert (follow_directions(starting_point, starting_orientation, *directions)
            == (ending_point, ending_orientation))


test_load_directions()
test_turn()
test_follow_directions()
print("All tests passed.")

from directions import load_directions, turn, follow_directions, expand_path
import unittest

class TestDirections(unittest.TestCase):
    def test_load_directions(self):
        with open("directions.txt") as f:
            directions = [direction.strip(',')
                          for direction
                          in f.readline().strip().split()]
        assert load_directions("directions.txt") == directions, \
            "Failed to load directions from directions.txt."


    def test_turn(self):
        assert turn('N', 'R') == 'E'
        assert turn('N', 'L') == 'W'
        assert turn('E', 'R') == 'S'
        assert turn('E', 'L') == 'N'
        assert turn('S', 'R') == 'W'
        assert turn('S', 'L') == 'E'
        assert turn('W', 'R') == 'N'
        assert turn('W', 'L') == 'S'


    def test_follow_directions(self):
        starting_point = (0, 0)
        starting_orientation = 'N'
        directions = ['R2', 'L3', 'R1']
        ending_point = (3, 3)
        ending_orientation = 'E'
        assert (follow_directions(starting_point, starting_orientation, *directions)
                == (ending_point, ending_orientation))


    def test_expand_path(self):
        assert expand_path((0, 0), (0, 3)) == [(0, 0), (0, 1), (0, 2), (0, 3)]
        assert expand_path((0, 0), (3, 0)) == [(0, 0), (1, 0), (2, 0), (3, 0)]
        with self.assertRaises(ValueError):
            expand_path((0, 0), (1, 1))


Convert to unittest and add test for expand_path.
Convert to unittest and add test for expand_path.

- from directions import load_directions, turn, follow_directions
+ from directions import load_directions, turn, follow_directions, expand_path
+ import unittest
+ 
+ class TestDirections(unittest.TestCase):
+     def test_load_directions(self):
+         with open("directions.txt") as f:
+             directions = [direction.strip(',')
+                           for direction
+                           in f.readline().strip().split()]
+         assert load_directions("directions.txt") == directions, \
+             "Failed to load directions from directions.txt."
  
  
- def test_load_directions():
-     with open("directions.txt") as f:
-         directions = [direction.strip(',')
-                       for direction
-                       in f.readline().strip().split()]
-     assert load_directions("directions.txt") == directions, \
-         "Failed to load directions from directions.txt."
+     def test_turn(self):
+         assert turn('N', 'R') == 'E'
+         assert turn('N', 'L') == 'W'
+         assert turn('E', 'R') == 'S'
+         assert turn('E', 'L') == 'N'
+         assert turn('S', 'R') == 'W'
+         assert turn('S', 'L') == 'E'
+         assert turn('W', 'R') == 'N'
+         assert turn('W', 'L') == 'S'
  
  
+     def test_follow_directions(self):
+         starting_point = (0, 0)
+         starting_orientation = 'N'
+         directions = ['R2', 'L3', 'R1']
+         ending_point = (3, 3)
+         ending_orientation = 'E'
+         assert (follow_directions(starting_point, starting_orientation, *directions)
+                 == (ending_point, ending_orientation))
- def test_turn():
-     assert turn('N', 'R') == 'E'
-     assert turn('N', 'L') == 'W'
-     assert turn('E', 'R') == 'S'
-     assert turn('E', 'L') == 'N'
-     assert turn('S', 'R') == 'W'
-     assert turn('S', 'L') == 'E'
-     assert turn('W', 'R') == 'N'
-     assert turn('W', 'L') == 'S'
  
  
+     def test_expand_path(self):
+         assert expand_path((0, 0), (0, 3)) == [(0, 0), (0, 1), (0, 2), (0, 3)]
+         assert expand_path((0, 0), (3, 0)) == [(0, 0), (1, 0), (2, 0), (3, 0)]
+         with self.assertRaises(ValueError):
+             expand_path((0, 0), (1, 1))
- def test_follow_directions():
-     starting_point = (0, 0)
-     starting_orientation = 'N'
-     directions = ['R2', 'L3', 'R1']
-     ending_point = (3, 3)
-     ending_orientation = 'E'
-     assert (follow_directions(starting_point, starting_orientation, *directions)
-             == (ending_point, ending_orientation))
  
  
- test_load_directions()
- test_turn()
- test_follow_directions()
- print("All tests passed.")
- 
Convert to unittest and add test for expand_path.
## Code Before:
from directions import load_directions, turn, follow_directions


def test_load_directions():
    with open("directions.txt") as f:
        directions = [direction.strip(',')
                      for direction
                      in f.readline().strip().split()]
    assert load_directions("directions.txt") == directions, \
        "Failed to load directions from directions.txt."


def test_turn():
    assert turn('N', 'R') == 'E'
    assert turn('N', 'L') == 'W'
    assert turn('E', 'R') == 'S'
    assert turn('E', 'L') == 'N'
    assert turn('S', 'R') == 'W'
    assert turn('S', 'L') == 'E'
    assert turn('W', 'R') == 'N'
    assert turn('W', 'L') == 'S'


def test_follow_directions():
    starting_point = (0, 0)
    starting_orientation = 'N'
    directions = ['R2', 'L3', 'R1']
    ending_point = (3, 3)
    ending_orientation = 'E'
    assert (follow_directions(starting_point, starting_orientation, *directions)
            == (ending_point, ending_orientation))


test_load_directions()
test_turn()
test_follow_directions()
print("All tests passed.")

## Instruction:
Convert to unittest and add test for expand_path.
## Code After:
from directions import load_directions, turn, follow_directions, expand_path
import unittest

class TestDirections(unittest.TestCase):
    def test_load_directions(self):
        with open("directions.txt") as f:
            directions = [direction.strip(',')
                          for direction
                          in f.readline().strip().split()]
        assert load_directions("directions.txt") == directions, \
            "Failed to load directions from directions.txt."


    def test_turn(self):
        assert turn('N', 'R') == 'E'
        assert turn('N', 'L') == 'W'
        assert turn('E', 'R') == 'S'
        assert turn('E', 'L') == 'N'
        assert turn('S', 'R') == 'W'
        assert turn('S', 'L') == 'E'
        assert turn('W', 'R') == 'N'
        assert turn('W', 'L') == 'S'


    def test_follow_directions(self):
        starting_point = (0, 0)
        starting_orientation = 'N'
        directions = ['R2', 'L3', 'R1']
        ending_point = (3, 3)
        ending_orientation = 'E'
        assert (follow_directions(starting_point, starting_orientation, *directions)
                == (ending_point, ending_orientation))


    def test_expand_path(self):
        assert expand_path((0, 0), (0, 3)) == [(0, 0), (0, 1), (0, 2), (0, 3)]
        assert expand_path((0, 0), (3, 0)) == [(0, 0), (1, 0), (2, 0), (3, 0)]
        with self.assertRaises(ValueError):
            expand_path((0, 0), (1, 1))

