+ source, expected = read_data("expression")
+ actual = fs(source)
+ self.assertFormatEqual(expected, actual)
+ black.assert_equivalent(source, actual)
+ black.assert_stable(source, actual, line_length=ll)
+
+ def test_expression_ff(self) -> None:
+ source, expected = read_data("expression")
+ tmp_file = Path(black.dump_to_file(source))
+ try:
+ self.assertTrue(ff(tmp_file, write_back=black.WriteBack.YES))
+ with open(tmp_file) as f:
+ actual = f.read()
+ finally:
+ os.unlink(tmp_file)
+ self.assertFormatEqual(expected, actual)
+ with patch("black.dump_to_file", dump_to_stderr):
+ black.assert_equivalent(source, actual)
+ black.assert_stable(source, actual, line_length=ll)
+
+ def test_expression_diff(self) -> None:
+ source, _ = read_data("expression.py")
+ expected, _ = read_data("expression.diff")
+ tmp_file = Path(black.dump_to_file(source))
+ hold_stdout = sys.stdout
+ try:
+ sys.stdout = StringIO()
+ self.assertTrue(ff(tmp_file, write_back=black.WriteBack.DIFF))
+ sys.stdout.seek(0)
+ actual = sys.stdout.read()
+ actual = actual.replace(tmp_file.name, "<stdin>")
+ finally:
+ sys.stdout = hold_stdout
+ os.unlink(tmp_file)
+ actual = actual.rstrip() + "\n" # the diff output has a trailing space
+ self.assertEqual(expected, actual)
+
+ @patch("black.dump_to_file", dump_to_stderr)
+ def test_fstring(self) -> None:
+ source, expected = read_data("fstring")
+ actual = fs(source)
+ self.assertFormatEqual(expected, actual)
+ black.assert_equivalent(source, actual)
+ black.assert_stable(source, actual, line_length=ll)
+
+ @patch("black.dump_to_file", dump_to_stderr)
+ def test_string_quotes(self) -> None:
+ source, expected = read_data("string_quotes")