'Check that yapf reformats the given code as expected.
Invokes yapf in a subprocess, piping the unformatted code into its stdin.
Checks that the formatted output is as expected.
Arguments:
unformatted: unformatted code - input to yapf
expected: expected formatted code at the output of yapf
extra_options: iterable of extra command-line options to pass to yapf'

def assertYapfReformats(self, unformatted, expected, extra_options=None):

    cmdline = (YAPF_BINARY + (extra_options or []))
    p = subprocess.Popen(cmdline, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
    (reformatted_code, stderrdata) = p.communicate(unformatted.encode('utf-8'))
    self.assertEqual(stderrdata, '')
    self.assertMultiLineEqual(reformatted_code.decode('utf-8'), expected)
