import subprocess
import pytest


def test_basic(string="This is a test."):
    """Test function to test echo server and client with inputted string."""
    process = subprocess.Popen(['./echo_client.py', string],
                               stdout=subprocess.PIPE)
    assert string == process.stdout.readline().rstrip()


def test_exact32():
    """Test echo server and client with string length 32, the buffer size."""
    test_basic("12345678901234567890123456789012")


def test_unicode():
    """Test that server and client handle decoding and encoding of unicode."""
    with pytest.raises(AssertionError):
        inp = 'Testing «ταБЬℓσ»: 1<2 & 4+1>3, now 20 off!'
        inp = inp.decode('utf-8')
        process = subprocess.Popen(['./echo_client.py', inp],
                                   stdout=subprocess.PIPE)
        assert inp == process.stdout.readline().rstrip()


def test_long():
    """Test server and client can handle long messages."""
    test_basic("Running the server script in one terminal should allow you to \
        run the client script in a separate terminal. The client script should\
         take an argument which is the message to send.  Upon completing, the \
         response from the server should be printed to stdout.")

import subprocess


def test_basic(string=u"This is a test."):
    """Test function to test echo server and client with inputted string."""
    process = subprocess.Popen(['./echo_client.py', string],
                               stdout=subprocess.PIPE)
    assert string == process.stdout.readline().rstrip()


def test_exact32():
    """Test echo server and client with string length 32, the buffer size."""
    test_basic(u"12345678901234567890123456789012")


def test_unicode():
    """Test that server and client handle encoding and decoding of unicode."""
    inp = u'Testing «ταБЬℓσ»: 1<2 & 4+1>3, now 20 off!'
    process = subprocess.Popen(['./echo_client.py', inp],
                               stdout=subprocess.PIPE)
    assert inp == process.stdout.readline().rstrip().decode('utf-8')


def test_long():
    """Test server and client can handle long messages."""
    test_basic(u"Running the server script in one terminal should allow you to \
        run the client script in a separate terminal. The client script should\
         take an argument which is the message to send.  Upon completing, the \
         response from the server should be printed to stdout.")

Change unicode test, to test decoding and encoding is done correctly.
Change unicode test, to test decoding and encoding is done correctly.

  import subprocess
- import pytest
  
  
- def test_basic(string="This is a test."):
+ def test_basic(string=u"This is a test."):
      """Test function to test echo server and client with inputted string."""
      process = subprocess.Popen(['./echo_client.py', string],
                                 stdout=subprocess.PIPE)
      assert string == process.stdout.readline().rstrip()
  
  
  def test_exact32():
      """Test echo server and client with string length 32, the buffer size."""
-     test_basic("12345678901234567890123456789012")
+     test_basic(u"12345678901234567890123456789012")
  
  
  def test_unicode():
-     """Test that server and client handle decoding and encoding of unicode."""
+     """Test that server and client handle encoding and decoding of unicode."""
-     with pytest.raises(AssertionError):
-         inp = 'Testing «ταБЬℓσ»: 1<2 & 4+1>3, now 20 off!'
+     inp = u'Testing «ταБЬℓσ»: 1<2 & 4+1>3, now 20 off!'
-         inp = inp.decode('utf-8')
-         process = subprocess.Popen(['./echo_client.py', inp],
+     process = subprocess.Popen(['./echo_client.py', inp],
-                                    stdout=subprocess.PIPE)
+                                stdout=subprocess.PIPE)
-         assert inp == process.stdout.readline().rstrip()
+     assert inp == process.stdout.readline().rstrip().decode('utf-8')
  
  
  def test_long():
      """Test server and client can handle long messages."""
-     test_basic("Running the server script in one terminal should allow you to \
+     test_basic(u"Running the server script in one terminal should allow you to \
          run the client script in a separate terminal. The client script should\
           take an argument which is the message to send.  Upon completing, the \
           response from the server should be printed to stdout.")
  
Change unicode test, to test decoding and encoding is done correctly.
## Code Before:
import subprocess
import pytest


def test_basic(string="This is a test."):
    """Test function to test echo server and client with inputted string."""
    process = subprocess.Popen(['./echo_client.py', string],
                               stdout=subprocess.PIPE)
    assert string == process.stdout.readline().rstrip()


def test_exact32():
    """Test echo server and client with string length 32, the buffer size."""
    test_basic("12345678901234567890123456789012")


def test_unicode():
    """Test that server and client handle decoding and encoding of unicode."""
    with pytest.raises(AssertionError):
        inp = 'Testing «ταБЬℓσ»: 1<2 & 4+1>3, now 20 off!'
        inp = inp.decode('utf-8')
        process = subprocess.Popen(['./echo_client.py', inp],
                                   stdout=subprocess.PIPE)
        assert inp == process.stdout.readline().rstrip()


def test_long():
    """Test server and client can handle long messages."""
    test_basic("Running the server script in one terminal should allow you to \
        run the client script in a separate terminal. The client script should\
         take an argument which is the message to send.  Upon completing, the \
         response from the server should be printed to stdout.")

## Instruction:
Change unicode test, to test decoding and encoding is done correctly.
## Code After:
import subprocess


def test_basic(string=u"This is a test."):
    """Test function to test echo server and client with inputted string."""
    process = subprocess.Popen(['./echo_client.py', string],
                               stdout=subprocess.PIPE)
    assert string == process.stdout.readline().rstrip()


def test_exact32():
    """Test echo server and client with string length 32, the buffer size."""
    test_basic(u"12345678901234567890123456789012")


def test_unicode():
    """Test that server and client handle encoding and decoding of unicode."""
    inp = u'Testing «ταБЬℓσ»: 1<2 & 4+1>3, now 20 off!'
    process = subprocess.Popen(['./echo_client.py', inp],
                               stdout=subprocess.PIPE)
    assert inp == process.stdout.readline().rstrip().decode('utf-8')


def test_long():
    """Test server and client can handle long messages."""
    test_basic(u"Running the server script in one terminal should allow you to \
        run the client script in a separate terminal. The client script should\
         take an argument which is the message to send.  Upon completing, the \
         response from the server should be printed to stdout.")
