diff --git a/ufmt/core.py b/ufmt/core.py index 548159c..e2ab1d6 100644 --- a/ufmt/core.py +++ b/ufmt/core.py @@ -150,7 +150,7 @@ def ufmt_bytes( mode=black_config, ) except black.report.NothingChanged: - content = result.output + pass elif ufmt_config.formatter == Formatter.ruff_api: ruff_format_options = ruff_api.FormatOptions( target_version=str( diff --git a/ufmt/tests/core.py b/ufmt/tests/core.py index 7cb75a3..f45592f 100644 --- a/ufmt/tests/core.py +++ b/ufmt/tests/core.py @@ -255,6 +255,16 @@ def test_ufmt_bytes_alternate_sorter( ) ruff_mock.assert_not_called() + result = ufmt.ufmt_bytes( + Path("foo.py"), + CORRECTLY_FORMATTED_CODE.encode(), + ufmt_config=UfmtConfig(sorter=Sorter.skip), + black_config=black_config, + usort_config=usort_config, + ) + expected = CORRECTLY_FORMATTED_CODE + self.assertEqual(expected.encode(), result) + with self.subTest("ruff-api"): usort_mock.reset_mock() result = ufmt.ufmt_bytes( @@ -270,6 +280,16 @@ def test_ufmt_bytes_alternate_sorter( "foo.py", POORLY_FORMATTED_CODE, options=ANY, root=None ) + result = ufmt.ufmt_bytes( + Path("foo.py"), + CORRECTLY_FORMATTED_CODE.encode(), + ufmt_config=UfmtConfig(sorter=Sorter.skip), + black_config=black_config, + usort_config=usort_config, + ) + expected = CORRECTLY_FORMATTED_CODE + self.assertEqual(expected.encode(), result) + with self.subTest("skip"): usort_mock.reset_mock() result = ufmt.ufmt_bytes( @@ -283,6 +303,16 @@ def test_ufmt_bytes_alternate_sorter( self.assertEqual(expected.encode(), result) usort_mock.assert_not_called() + result = ufmt.ufmt_bytes( + Path("foo.py"), + CORRECTLY_FORMATTED_CODE.encode(), + ufmt_config=UfmtConfig(sorter=Sorter.skip), + black_config=black_config, + usort_config=usort_config, + ) + expected = CORRECTLY_FORMATTED_CODE + self.assertEqual(expected.encode(), result) + with self.subTest("unsupported sorter"): with self.assertRaisesRegex( ValueError, "'garbage' is not a supported sorter"