import subprocess
import unittest


class GhostscriptTest(unittest.TestCase):

    def test_installed(self):
        process = subprocess.Popen(
            ['gs', '--version'],
            stdin=None,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
        )
        stdout, stderr = process.communicate()

        self.assertEqual(process.returncode, 0)
        self.assertEqual(str(stderr), "")
        self.assertRegexpMatches(str(stdout), r'9\.\d\d')

import subprocess
import unittest


class GhostscriptTest(unittest.TestCase):

    def test_installed(self):
        process = subprocess.Popen(
            ['gs', '--version'],
            universal_newlines=True,
            stdin=None,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
        )
        stdout, stderr = process.communicate()

        self.assertEqual(process.returncode, 0)
        self.assertEqual(stderr, "")
        self.assertRegexpMatches(stdout, r'9\.\d\d')

Make Popen.communicate return output as strings not bytes.
Make Popen.communicate return output as strings not bytes.

  import subprocess
  import unittest
  
  
  class GhostscriptTest(unittest.TestCase):
  
      def test_installed(self):
          process = subprocess.Popen(
              ['gs', '--version'],
+             universal_newlines=True,
              stdin=None,
              stdout=subprocess.PIPE,
              stderr=subprocess.PIPE,
          )
          stdout, stderr = process.communicate()
  
          self.assertEqual(process.returncode, 0)
-         self.assertEqual(str(stderr), "")
+         self.assertEqual(stderr, "")
-         self.assertRegexpMatches(str(stdout), r'9\.\d\d')
+         self.assertRegexpMatches(stdout, r'9\.\d\d')
  
Make Popen.communicate return output as strings not bytes.
## Code Before:
import subprocess
import unittest


class GhostscriptTest(unittest.TestCase):

    def test_installed(self):
        process = subprocess.Popen(
            ['gs', '--version'],
            stdin=None,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
        )
        stdout, stderr = process.communicate()

        self.assertEqual(process.returncode, 0)
        self.assertEqual(str(stderr), "")
        self.assertRegexpMatches(str(stdout), r'9\.\d\d')

## Instruction:
Make Popen.communicate return output as strings not bytes.
## Code After:
import subprocess
import unittest


class GhostscriptTest(unittest.TestCase):

    def test_installed(self):
        process = subprocess.Popen(
            ['gs', '--version'],
            universal_newlines=True,
            stdin=None,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
        )
        stdout, stderr = process.communicate()

        self.assertEqual(process.returncode, 0)
        self.assertEqual(stderr, "")
        self.assertRegexpMatches(stdout, r'9\.\d\d')
