Exemplo n.º 1
0
 def test_setup(self) -> None:
     source, expected = read_data("../setup")
     actual = fs(source)
     self.assertFormatEqual(expected, actual)
     black.assert_equivalent(source, actual)
     black.assert_stable(source, actual, line_length=ll)
     self.assertFalse(ff(THIS_DIR / ".." / "setup.py"))
Exemplo n.º 2
0
 def test_self(self) -> None:
     source, expected = read_data("test_black")
     actual = fs(source)
     self.assertFormatEqual(expected, actual)
     black.assert_equivalent(source, actual)
     black.assert_stable(source, actual, line_length=ll)
     self.assertFalse(ff(THIS_FILE))
Exemplo n.º 3
0
 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, encoding="utf8") 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)
Exemplo n.º 4
0
 def test_piping(self) -> None:
     source, expected = read_data("../black")
     hold_stdin, hold_stdout = sys.stdin, sys.stdout
     try:
         sys.stdin, sys.stdout = StringIO(source), StringIO()
         sys.stdin.name = "<stdin>"
         black.format_stdin_to_stdout(
             line_length=ll, fast=True, write_back=black.WriteBack.YES
         )
         sys.stdout.seek(0)
         actual = sys.stdout.read()
     finally:
         sys.stdin, sys.stdout = hold_stdin, hold_stdout
     self.assertFormatEqual(expected, actual)
     black.assert_equivalent(source, actual)
     black.assert_stable(source, actual, line_length=ll)
Exemplo n.º 5
0
 def test_new_line_between_class_and_code(self) -> None:
     source, expected = read_data("class_methods_new_line")
     actual = fs(source)
     self.assertFormatEqual(expected, actual)
     black.assert_equivalent(source, actual)
     black.assert_stable(source, actual, line_length=ll)
Exemplo n.º 6
0
 def test_remove_empty_parentheses_after_class(self) -> None:
     source, expected = read_data("class_blank_parentheses")
     actual = fs(source)
     self.assertFormatEqual(expected, actual)
     black.assert_equivalent(source, actual)
     black.assert_stable(source, actual, line_length=ll)
Exemplo n.º 7
0
 def test_fmtonoff(self) -> None:
     source, expected = read_data("fmtonoff")
     actual = fs(source)
     self.assertFormatEqual(expected, actual)
     black.assert_equivalent(source, actual)
     black.assert_stable(source, actual, line_length=ll)
Exemplo n.º 8
0
 def test_stub(self) -> None:
     mode = black.FileMode.PYI
     source, expected = read_data("stub.pyi")
     actual = fs(source, mode=mode)
     self.assertFormatEqual(expected, actual)
     black.assert_stable(source, actual, line_length=ll, mode=mode)
Exemplo n.º 9
0
 def test_python2_unicode_literals(self) -> None:
     source, expected = read_data("python2_unicode_literals")
     actual = fs(source)
     self.assertFormatEqual(expected, actual)
     black.assert_stable(source, actual, line_length=ll)
Exemplo n.º 10
0
 def test_string_prefixes(self) -> None:
     source, expected = read_data("string_prefixes")
     actual = fs(source)
     self.assertFormatEqual(expected, actual)
     black.assert_equivalent(source, actual)
     black.assert_stable(source, actual, line_length=ll)
Exemplo n.º 11
0
 def test_import_spacing(self) -> None:
     source, expected = read_data("import_spacing")
     actual = fs(source)
     self.assertFormatEqual(expected, actual)
     black.assert_equivalent(source, actual)
     black.assert_stable(source, actual, line_length=ll)
Exemplo n.º 12
0
 def test_empty_lines(self) -> None:
     source, expected = read_data("empty_lines")
     actual = fs(source)
     self.assertFormatEqual(expected, actual)
     black.assert_equivalent(source, actual)
     black.assert_stable(source, actual, line_length=ll)