]> git.madduck.net Git - etc/vim.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Read simple data cases automatically (#3034)
authorSagi Shadur <saroad2@gmail.com>
Sun, 8 May 2022 19:27:40 +0000 (22:27 +0300)
committerGitHub <noreply@github.com>
Sun, 8 May 2022 19:27:40 +0000 (12:27 -0700)
Co-authored-by: Felix Hildén <felix.hilden@gmail.com>
49 files changed:
tests/data/simple_cases/attribute_access_on_number_literals.py [moved from tests/data/attribute_access_on_number_literals.py with 100% similarity]
tests/data/simple_cases/beginning_backslash.py [moved from tests/data/beginning_backslash.py with 100% similarity]
tests/data/simple_cases/bracketmatch.py [moved from tests/data/bracketmatch.py with 100% similarity]
tests/data/simple_cases/class_blank_parentheses.py [moved from tests/data/class_blank_parentheses.py with 100% similarity]
tests/data/simple_cases/class_methods_new_line.py [moved from tests/data/class_methods_new_line.py with 100% similarity]
tests/data/simple_cases/collections.py [moved from tests/data/collections.py with 100% similarity]
tests/data/simple_cases/comment_after_escaped_newline.py [moved from tests/data/comment_after_escaped_newline.py with 100% similarity]
tests/data/simple_cases/comments.py [moved from tests/data/comments.py with 100% similarity]
tests/data/simple_cases/comments2.py [moved from tests/data/comments2.py with 100% similarity]
tests/data/simple_cases/comments3.py [moved from tests/data/comments3.py with 100% similarity]
tests/data/simple_cases/comments4.py [moved from tests/data/comments4.py with 100% similarity]
tests/data/simple_cases/comments5.py [moved from tests/data/comments5.py with 100% similarity]
tests/data/simple_cases/comments6.py [moved from tests/data/comments6.py with 100% similarity]
tests/data/simple_cases/comments_non_breaking_space.py [moved from tests/data/comments_non_breaking_space.py with 100% similarity]
tests/data/simple_cases/composition.py [moved from tests/data/composition.py with 100% similarity]
tests/data/simple_cases/composition_no_trailing_comma.py [moved from tests/data/composition_no_trailing_comma.py with 100% similarity]
tests/data/simple_cases/docstring.py [moved from tests/data/docstring.py with 100% similarity]
tests/data/simple_cases/empty_lines.py [moved from tests/data/empty_lines.py with 100% similarity]
tests/data/simple_cases/expression.diff [moved from tests/data/expression.diff with 100% similarity]
tests/data/simple_cases/expression.py [moved from tests/data/expression.py with 100% similarity]
tests/data/simple_cases/fmtonoff.py [moved from tests/data/fmtonoff.py with 100% similarity]
tests/data/simple_cases/fmtonoff2.py [moved from tests/data/fmtonoff2.py with 100% similarity]
tests/data/simple_cases/fmtonoff3.py [moved from tests/data/fmtonoff3.py with 100% similarity]
tests/data/simple_cases/fmtonoff4.py [moved from tests/data/fmtonoff4.py with 100% similarity]
tests/data/simple_cases/fmtskip.py [moved from tests/data/fmtskip.py with 100% similarity]
tests/data/simple_cases/fmtskip2.py [moved from tests/data/fmtskip2.py with 100% similarity]
tests/data/simple_cases/fmtskip3.py [moved from tests/data/fmtskip3.py with 100% similarity]
tests/data/simple_cases/fmtskip4.py [moved from tests/data/fmtskip4.py with 100% similarity]
tests/data/simple_cases/fmtskip5.py [moved from tests/data/fmtskip5.py with 100% similarity]
tests/data/simple_cases/fmtskip6.py [moved from tests/data/fmtskip6.py with 100% similarity]
tests/data/simple_cases/fmtskip7.py [moved from tests/data/fmtskip7.py with 100% similarity]
tests/data/simple_cases/fstring.py [moved from tests/data/fstring.py with 100% similarity]
tests/data/simple_cases/function.py [moved from tests/data/function.py with 100% similarity]
tests/data/simple_cases/function2.py [moved from tests/data/function2.py with 100% similarity]
tests/data/simple_cases/function_trailing_comma.py [moved from tests/data/function_trailing_comma.py with 100% similarity]
tests/data/simple_cases/import_spacing.py [moved from tests/data/import_spacing.py with 100% similarity]
tests/data/simple_cases/power_op_spacing.py [moved from tests/data/power_op_spacing.py with 100% similarity]
tests/data/simple_cases/remove_parens.py [moved from tests/data/remove_parens.py with 100% similarity]
tests/data/simple_cases/slices.py [moved from tests/data/slices.py with 100% similarity]
tests/data/simple_cases/string_prefixes.py [moved from tests/data/string_prefixes.py with 100% similarity]
tests/data/simple_cases/torture.py [moved from tests/data/torture.py with 100% similarity]
tests/data/simple_cases/trailing_comma_optional_parens1.py [moved from tests/data/trailing_comma_optional_parens1.py with 100% similarity]
tests/data/simple_cases/trailing_comma_optional_parens2.py [moved from tests/data/trailing_comma_optional_parens2.py with 100% similarity]
tests/data/simple_cases/trailing_comma_optional_parens3.py [moved from tests/data/trailing_comma_optional_parens3.py with 100% similarity]
tests/data/simple_cases/tricky_unicode_symbols.py [moved from tests/data/tricky_unicode_symbols.py with 100% similarity]
tests/data/simple_cases/tupleassign.py [moved from tests/data/tupleassign.py with 100% similarity]
tests/test_black.py
tests/test_format.py
tests/util.py

index 74334d267a1f7a70a9f6a563da376354fd8743c1..281019a0bfa6d90252b42d630e4b12d429f18109 100644 (file)
@@ -179,8 +179,8 @@ class BlackTestCase(BlackBaseTestCase):
             r"(STDIN|STDOUT)\t\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d\.\d\d\d\d\d\d "
             r"\+\d\d\d\d"
         )
-        source, _ = read_data("expression.py")
-        expected, _ = read_data("expression.diff")
+        source, _ = read_data("simple_cases/expression.py")
+        expected, _ = read_data("simple_cases/expression.diff")
         args = [
             "-",
             "--fast",
@@ -197,7 +197,7 @@ class BlackTestCase(BlackBaseTestCase):
         self.assertEqual(expected, actual)
 
     def test_piping_diff_with_color(self) -> None:
-        source, _ = read_data("expression.py")
+        source, _ = read_data("simple_cases/expression.py")
         args = [
             "-",
             "--fast",
@@ -241,7 +241,7 @@ class BlackTestCase(BlackBaseTestCase):
         self.assertIn(black.TargetVersion.PY38, versions)
 
     def test_expression_ff(self) -> None:
-        source, expected = read_data("expression")
+        source, expected = read_data("simple_cases/expression.py")
         tmp_file = Path(black.dump_to_file(source))
         try:
             self.assertTrue(ff(tmp_file, write_back=black.WriteBack.YES))
@@ -255,8 +255,8 @@ class BlackTestCase(BlackBaseTestCase):
             black.assert_stable(source, actual, DEFAULT_MODE)
 
     def test_expression_diff(self) -> None:
-        source, _ = read_data("expression.py")
-        expected, _ = read_data("expression.diff")
+        source, _ = read_data("simple_cases/expression.py")
+        expected, _ = read_data("simple_cases/expression.diff")
         tmp_file = Path(black.dump_to_file(source))
         diff_header = re.compile(
             rf"{re.escape(str(tmp_file))}\t\d\d\d\d-\d\d-\d\d "
@@ -281,8 +281,8 @@ class BlackTestCase(BlackBaseTestCase):
             self.assertEqual(expected, actual, msg)
 
     def test_expression_diff_with_color(self) -> None:
-        source, _ = read_data("expression.py")
-        expected, _ = read_data("expression.diff")
+        source, _ = read_data("simple_cases/expression.py")
+        expected, _ = read_data("simple_cases/expression.diff")
         tmp_file = Path(black.dump_to_file(source))
         try:
             result = BlackRunner().invoke(
@@ -320,7 +320,7 @@ class BlackTestCase(BlackBaseTestCase):
         black.assert_stable(source, not_normalized, mode=mode)
 
     def test_skip_magic_trailing_comma(self) -> None:
-        source, _ = read_data("expression.py")
+        source, _ = read_data("simple_cases/expression.py")
         expected, _ = read_data("expression_skip_magic_trailing_comma.diff")
         tmp_file = Path(black.dump_to_file(source))
         diff_header = re.compile(
@@ -755,7 +755,7 @@ class BlackTestCase(BlackBaseTestCase):
         self.assertEqual(black.get_features_used(node), {Feature.NUMERIC_UNDERSCORES})
         node = black.lib2to3_parse("123456\n")
         self.assertEqual(black.get_features_used(node), set())
-        source, expected = read_data("function")
+        source, expected = read_data("simple_cases/function.py")
         node = black.lib2to3_parse(source)
         expected_features = {
             Feature.TRAILING_COMMA_IN_CALL,
@@ -765,7 +765,7 @@ class BlackTestCase(BlackBaseTestCase):
         self.assertEqual(black.get_features_used(node), expected_features)
         node = black.lib2to3_parse(expected)
         self.assertEqual(black.get_features_used(node), expected_features)
-        source, expected = read_data("expression")
+        source, expected = read_data("simple_cases/expression.py")
         node = black.lib2to3_parse(source)
         self.assertEqual(black.get_features_used(node), set())
         node = black.lib2to3_parse(expected)
@@ -939,7 +939,7 @@ class BlackTestCase(BlackBaseTestCase):
             src1 = (THIS_DIR / "data" / "string_quotes.py").resolve()
             self.invokeBlack([str(src1), "--diff", "--check"], exit_code=1)
             # Files which will not be reformatted.
-            src2 = (THIS_DIR / "data" / "composition.py").resolve()
+            src2 = (THIS_DIR / "data" / "simple_cases" / "composition.py").resolve()
             self.invokeBlack([str(src2), "--diff", "--check"])
             # Multi file command.
             self.invokeBlack([str(src1), str(src2), "--diff", "--check"], exit_code=1)
@@ -1168,7 +1168,7 @@ class BlackTestCase(BlackBaseTestCase):
             report = MagicMock()
             # Even with an existing file, since we are forcing stdin, black
             # should output to stdout and not modify the file inplace
-            p = Path(str(THIS_DIR / "data/collections.py"))
+            p = THIS_DIR / "data" / "simple_cases" / "collections.py"
             # Make sure is_file actually returns True
             self.assertTrue(p.is_file())
             path = Path(f"__BLACK_STDIN_FILENAME__{p}")
index 2f08d1f273d4040c4f62b09cba3bb0fea0b80a71..003f5bbe18863513bf6b9328526e9ffceab32d87 100644 (file)
@@ -12,56 +12,9 @@ from tests.util import (
     assert_format,
     dump_to_stderr,
     read_data,
+    all_data_cases,
 )
 
-SIMPLE_CASES: List[str] = [
-    "attribute_access_on_number_literals",
-    "beginning_backslash",
-    "bracketmatch",
-    "class_blank_parentheses",
-    "class_methods_new_line",
-    "collections",
-    "comments",
-    "comments2",
-    "comments3",
-    "comments4",
-    "comments5",
-    "comments6",
-    "comments_non_breaking_space",
-    "comment_after_escaped_newline",
-    "composition",
-    "composition_no_trailing_comma",
-    "docstring",
-    "empty_lines",
-    "expression",
-    "fmtonoff",
-    "fmtonoff2",
-    "fmtonoff3",
-    "fmtonoff4",
-    "fmtskip",
-    "fmtskip2",
-    "fmtskip3",
-    "fmtskip4",
-    "fmtskip5",
-    "fmtskip6",
-    "fmtskip7",
-    "fstring",
-    "function",
-    "function2",
-    "function_trailing_comma",
-    "import_spacing",
-    "power_op_spacing",
-    "remove_parens",
-    "slices",
-    "string_prefixes",
-    "torture",
-    "trailing_comma_optional_parens1",
-    "trailing_comma_optional_parens2",
-    "trailing_comma_optional_parens3",
-    "tricky_unicode_symbols",
-    "tupleassign",
-]
-
 PY310_CASES: List[str] = [
     "starred_for_target",
     "pattern_matching_simple",
@@ -147,7 +100,7 @@ def check_file(filename: str, mode: black.Mode, *, data: bool = True) -> None:
     assert_format(source, expected, mode, fast=False)
 
 
-@pytest.mark.parametrize("filename", SIMPLE_CASES)
+@pytest.mark.parametrize("filename", all_data_cases("simple_cases"))
 def test_simple_format(filename: str) -> None:
     check_file(filename, DEFAULT_MODE)
 
index 8755111f7c57716c76a8394711e2608cb621490b..1d76681dbeaa8c922402a1cfb223d33e33fa9ab2 100644 (file)
@@ -90,12 +90,21 @@ class BlackBaseTestCase(unittest.TestCase):
         _assert_format_equal(expected, actual)
 
 
+def all_data_cases(dir_name: str, data: bool = True) -> List[str]:
+    base_dir = DATA_DIR if data else PROJECT_ROOT
+    cases_dir = base_dir / dir_name
+    assert cases_dir.is_dir()
+    return [f"{dir_name}/{case_path.stem}" for case_path in cases_dir.iterdir()]
+
+
 def read_data(name: str, data: bool = True) -> Tuple[str, str]:
     """read_data('test_name') -> 'input', 'output'"""
     if not name.endswith((".py", ".pyi", ".out", ".diff")):
         name += ".py"
     base_dir = DATA_DIR if data else PROJECT_ROOT
-    return read_data_from_file(base_dir / name)
+    case_path = base_dir / name
+    assert case_path.is_file(), f"{case_path} is not a file."
+    return read_data_from_file(case_path)
 
 
 def read_data_from_file(file_name: Path) -> Tuple[str, str]: