From f71db23824a25300618dd0625085ade8d2b3a7a8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C5=81ukasz=20Langa?= Date: Wed, 6 Jun 2018 15:39:58 -0700 Subject: [PATCH] Move test data to data --- tests/{ => data}/cantfit.py | 0 tests/{ => data}/class_blank_parentheses.py | 0 tests/{ => data}/class_methods_new_line.py | 0 tests/{ => data}/comments.py | 0 tests/{ => data}/comments2.py | 0 tests/{ => data}/comments3.py | 0 tests/{ => data}/comments4.py | 0 tests/{ => data}/comments5.py | 0 tests/{ => data}/composition.py | 0 tests/{ => data}/debug_visitor.out | 0 tests/{ => data}/debug_visitor.py | 0 tests/{ => data}/empty_lines.py | 0 tests/{ => data}/expression.diff | 0 tests/{ => data}/expression.py | 0 tests/{ => data}/fmtonoff.py | 0 tests/{ => data}/force_py36.py | 0 tests/{ => data}/force_pyi.py | 0 tests/{ => data}/fstring.py | 0 tests/{ => data}/function.py | 0 tests/{ => data}/function2.py | 0 tests/{ => data}/import_spacing.py | 0 .../b/.definitely_exclude/a.pie | 0 .../b/.definitely_exclude/a.py | 0 .../b/.definitely_exclude/a.pyi | 0 .../b/dont_exclude/a.pie | 0 .../include_exclude_tests/b/dont_exclude/a.py | 0 .../b/dont_exclude/a.pyi | 0 .../include_exclude_tests/b/exclude/a.pie | 0 .../include_exclude_tests/b/exclude/a.py | 0 .../include_exclude_tests/b/exclude/a.pyi | 0 tests/{ => data}/python2.py | 0 tests/{ => data}/python2_unicode_literals.py | 0 tests/{ => data}/slices.py | 0 tests/{ => data}/string_prefixes.py | 0 tests/{ => data}/string_quotes.py | 0 tests/{ => data}/stub.pyi | 0 tests/test_black.py | 31 ++++++++++--------- 37 files changed, 16 insertions(+), 15 deletions(-) rename tests/{ => data}/cantfit.py (100%) rename tests/{ => data}/class_blank_parentheses.py (100%) rename tests/{ => data}/class_methods_new_line.py (100%) rename tests/{ => data}/comments.py (100%) rename tests/{ => data}/comments2.py (100%) rename tests/{ => data}/comments3.py (100%) rename tests/{ => data}/comments4.py (100%) rename tests/{ => data}/comments5.py (100%) rename tests/{ => data}/composition.py (100%) rename tests/{ => data}/debug_visitor.out (100%) rename tests/{ => data}/debug_visitor.py (100%) rename tests/{ => data}/empty_lines.py (100%) rename tests/{ => data}/expression.diff (100%) rename tests/{ => data}/expression.py (100%) rename tests/{ => data}/fmtonoff.py (100%) rename tests/{ => data}/force_py36.py (100%) rename tests/{ => data}/force_pyi.py (100%) rename tests/{ => data}/fstring.py (100%) rename tests/{ => data}/function.py (100%) rename tests/{ => data}/function2.py (100%) rename tests/{ => data}/import_spacing.py (100%) rename tests/{ => data}/include_exclude_tests/b/.definitely_exclude/a.pie (100%) rename tests/{ => data}/include_exclude_tests/b/.definitely_exclude/a.py (100%) rename tests/{ => data}/include_exclude_tests/b/.definitely_exclude/a.pyi (100%) rename tests/{ => data}/include_exclude_tests/b/dont_exclude/a.pie (100%) rename tests/{ => data}/include_exclude_tests/b/dont_exclude/a.py (100%) rename tests/{ => data}/include_exclude_tests/b/dont_exclude/a.pyi (100%) rename tests/{ => data}/include_exclude_tests/b/exclude/a.pie (100%) rename tests/{ => data}/include_exclude_tests/b/exclude/a.py (100%) rename tests/{ => data}/include_exclude_tests/b/exclude/a.pyi (100%) rename tests/{ => data}/python2.py (100%) rename tests/{ => data}/python2_unicode_literals.py (100%) rename tests/{ => data}/slices.py (100%) rename tests/{ => data}/string_prefixes.py (100%) rename tests/{ => data}/string_quotes.py (100%) rename tests/{ => data}/stub.pyi (100%) diff --git a/tests/cantfit.py b/tests/data/cantfit.py similarity index 100% rename from tests/cantfit.py rename to tests/data/cantfit.py diff --git a/tests/class_blank_parentheses.py b/tests/data/class_blank_parentheses.py similarity index 100% rename from tests/class_blank_parentheses.py rename to tests/data/class_blank_parentheses.py diff --git a/tests/class_methods_new_line.py b/tests/data/class_methods_new_line.py similarity index 100% rename from tests/class_methods_new_line.py rename to tests/data/class_methods_new_line.py diff --git a/tests/comments.py b/tests/data/comments.py similarity index 100% rename from tests/comments.py rename to tests/data/comments.py diff --git a/tests/comments2.py b/tests/data/comments2.py similarity index 100% rename from tests/comments2.py rename to tests/data/comments2.py diff --git a/tests/comments3.py b/tests/data/comments3.py similarity index 100% rename from tests/comments3.py rename to tests/data/comments3.py diff --git a/tests/comments4.py b/tests/data/comments4.py similarity index 100% rename from tests/comments4.py rename to tests/data/comments4.py diff --git a/tests/comments5.py b/tests/data/comments5.py similarity index 100% rename from tests/comments5.py rename to tests/data/comments5.py diff --git a/tests/composition.py b/tests/data/composition.py similarity index 100% rename from tests/composition.py rename to tests/data/composition.py diff --git a/tests/debug_visitor.out b/tests/data/debug_visitor.out similarity index 100% rename from tests/debug_visitor.out rename to tests/data/debug_visitor.out diff --git a/tests/debug_visitor.py b/tests/data/debug_visitor.py similarity index 100% rename from tests/debug_visitor.py rename to tests/data/debug_visitor.py diff --git a/tests/empty_lines.py b/tests/data/empty_lines.py similarity index 100% rename from tests/empty_lines.py rename to tests/data/empty_lines.py diff --git a/tests/expression.diff b/tests/data/expression.diff similarity index 100% rename from tests/expression.diff rename to tests/data/expression.diff diff --git a/tests/expression.py b/tests/data/expression.py similarity index 100% rename from tests/expression.py rename to tests/data/expression.py diff --git a/tests/fmtonoff.py b/tests/data/fmtonoff.py similarity index 100% rename from tests/fmtonoff.py rename to tests/data/fmtonoff.py diff --git a/tests/force_py36.py b/tests/data/force_py36.py similarity index 100% rename from tests/force_py36.py rename to tests/data/force_py36.py diff --git a/tests/force_pyi.py b/tests/data/force_pyi.py similarity index 100% rename from tests/force_pyi.py rename to tests/data/force_pyi.py diff --git a/tests/fstring.py b/tests/data/fstring.py similarity index 100% rename from tests/fstring.py rename to tests/data/fstring.py diff --git a/tests/function.py b/tests/data/function.py similarity index 100% rename from tests/function.py rename to tests/data/function.py diff --git a/tests/function2.py b/tests/data/function2.py similarity index 100% rename from tests/function2.py rename to tests/data/function2.py diff --git a/tests/import_spacing.py b/tests/data/import_spacing.py similarity index 100% rename from tests/import_spacing.py rename to tests/data/import_spacing.py diff --git a/tests/include_exclude_tests/b/.definitely_exclude/a.pie b/tests/data/include_exclude_tests/b/.definitely_exclude/a.pie similarity index 100% rename from tests/include_exclude_tests/b/.definitely_exclude/a.pie rename to tests/data/include_exclude_tests/b/.definitely_exclude/a.pie diff --git a/tests/include_exclude_tests/b/.definitely_exclude/a.py b/tests/data/include_exclude_tests/b/.definitely_exclude/a.py similarity index 100% rename from tests/include_exclude_tests/b/.definitely_exclude/a.py rename to tests/data/include_exclude_tests/b/.definitely_exclude/a.py diff --git a/tests/include_exclude_tests/b/.definitely_exclude/a.pyi b/tests/data/include_exclude_tests/b/.definitely_exclude/a.pyi similarity index 100% rename from tests/include_exclude_tests/b/.definitely_exclude/a.pyi rename to tests/data/include_exclude_tests/b/.definitely_exclude/a.pyi diff --git a/tests/include_exclude_tests/b/dont_exclude/a.pie b/tests/data/include_exclude_tests/b/dont_exclude/a.pie similarity index 100% rename from tests/include_exclude_tests/b/dont_exclude/a.pie rename to tests/data/include_exclude_tests/b/dont_exclude/a.pie diff --git a/tests/include_exclude_tests/b/dont_exclude/a.py b/tests/data/include_exclude_tests/b/dont_exclude/a.py similarity index 100% rename from tests/include_exclude_tests/b/dont_exclude/a.py rename to tests/data/include_exclude_tests/b/dont_exclude/a.py diff --git a/tests/include_exclude_tests/b/dont_exclude/a.pyi b/tests/data/include_exclude_tests/b/dont_exclude/a.pyi similarity index 100% rename from tests/include_exclude_tests/b/dont_exclude/a.pyi rename to tests/data/include_exclude_tests/b/dont_exclude/a.pyi diff --git a/tests/include_exclude_tests/b/exclude/a.pie b/tests/data/include_exclude_tests/b/exclude/a.pie similarity index 100% rename from tests/include_exclude_tests/b/exclude/a.pie rename to tests/data/include_exclude_tests/b/exclude/a.pie diff --git a/tests/include_exclude_tests/b/exclude/a.py b/tests/data/include_exclude_tests/b/exclude/a.py similarity index 100% rename from tests/include_exclude_tests/b/exclude/a.py rename to tests/data/include_exclude_tests/b/exclude/a.py diff --git a/tests/include_exclude_tests/b/exclude/a.pyi b/tests/data/include_exclude_tests/b/exclude/a.pyi similarity index 100% rename from tests/include_exclude_tests/b/exclude/a.pyi rename to tests/data/include_exclude_tests/b/exclude/a.pyi diff --git a/tests/python2.py b/tests/data/python2.py similarity index 100% rename from tests/python2.py rename to tests/data/python2.py diff --git a/tests/python2_unicode_literals.py b/tests/data/python2_unicode_literals.py similarity index 100% rename from tests/python2_unicode_literals.py rename to tests/data/python2_unicode_literals.py diff --git a/tests/slices.py b/tests/data/slices.py similarity index 100% rename from tests/slices.py rename to tests/data/slices.py diff --git a/tests/string_prefixes.py b/tests/data/string_prefixes.py similarity index 100% rename from tests/string_prefixes.py rename to tests/data/string_prefixes.py diff --git a/tests/string_quotes.py b/tests/data/string_quotes.py similarity index 100% rename from tests/string_quotes.py rename to tests/data/string_quotes.py diff --git a/tests/stub.pyi b/tests/data/stub.pyi similarity index 100% rename from tests/stub.pyi rename to tests/data/stub.pyi diff --git a/tests/test_black.py b/tests/test_black.py index 1271290..e555ba9 100644 --- a/tests/test_black.py +++ b/tests/test_black.py @@ -31,13 +31,14 @@ def dump_to_stderr(*output: str) -> str: return "\n" + "\n".join(output) + "\n" -def read_data(name: str) -> Tuple[str, str]: +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" _input: List[str] = [] _output: List[str] = [] - with open(THIS_DIR / name, "r", encoding="utf8") as test: + base_dir = THIS_DIR / "data" if data else THIS_DIR + with open(base_dir / name, "r", encoding="utf8") as test: lines = test.readlines() result = _input for line in lines: @@ -141,7 +142,7 @@ class BlackTestCase(unittest.TestCase): @patch("black.dump_to_file", dump_to_stderr) def test_self(self) -> None: - source, expected = read_data("test_black") + source, expected = read_data("test_black", data=False) actual = fs(source) self.assertFormatEqual(expected, actual) black.assert_equivalent(source, actual) @@ -150,7 +151,7 @@ class BlackTestCase(unittest.TestCase): @patch("black.dump_to_file", dump_to_stderr) def test_black(self) -> None: - source, expected = read_data("../black") + source, expected = read_data("../black", data=False) actual = fs(source) self.assertFormatEqual(expected, actual) black.assert_equivalent(source, actual) @@ -158,7 +159,7 @@ class BlackTestCase(unittest.TestCase): self.assertFalse(ff(THIS_DIR / ".." / "black.py")) def test_piping(self) -> None: - source, expected = read_data("../black") + source, expected = read_data("../black", data=False) stderrbuf = BytesIO() result = BlackRunner(stderrbuf).invoke( black.main, ["-", "--fast", f"--line-length={ll}"], input=source @@ -186,7 +187,7 @@ class BlackTestCase(unittest.TestCase): @patch("black.dump_to_file", dump_to_stderr) def test_setup(self) -> None: - source, expected = read_data("../setup") + source, expected = read_data("../setup", data=False) actual = fs(source) self.assertFormatEqual(expected, actual) black.assert_equivalent(source, actual) @@ -931,14 +932,14 @@ class BlackTestCase(unittest.TestCase): def test_check_diff_use_together(self) -> None: with cache_dir(): # Files which will be reformatted. - src1 = (THIS_DIR / "string_quotes.py").resolve() + src1 = (THIS_DIR / "data" / "string_quotes.py").resolve() result = CliRunner().invoke(black.main, [str(src1), "--diff", "--check"]) - self.assertEqual(result.exit_code, 1) + self.assertEqual(result.exit_code, 1, result.output) # Files which will not be reformatted. - src2 = (THIS_DIR / "composition.py").resolve() + src2 = (THIS_DIR / "data" / "composition.py").resolve() result = CliRunner().invoke(black.main, [str(src2), "--diff", "--check"]) - self.assertEqual(result.exit_code, 0) + self.assertEqual(result.exit_code, 0, result.output) # Multi file command. result = CliRunner().invoke( @@ -1080,14 +1081,14 @@ class BlackTestCase(unittest.TestCase): self.assertFormatEqual(actual, expected) def test_include_exclude(self) -> None: - path = THIS_DIR / "include_exclude_tests" + path = THIS_DIR / "data" / "include_exclude_tests" include = re.compile(r"\.pyi?$") exclude = re.compile(r"/exclude/|/\.definitely_exclude/") report = black.Report() sources: List[Path] = [] expected = [ - Path(THIS_DIR / "include_exclude_tests/b/dont_exclude/a.py"), - Path(THIS_DIR / "include_exclude_tests/b/dont_exclude/a.pyi"), + Path(path / "b/dont_exclude/a.py"), + Path(path / "b/dont_exclude/a.pyi"), ] this_abs = THIS_DIR.resolve() sources.extend( @@ -1096,7 +1097,7 @@ class BlackTestCase(unittest.TestCase): self.assertEqual(sorted(expected), sorted(sources)) def test_empty_include(self) -> None: - path = THIS_DIR / "include_exclude_tests" + path = THIS_DIR / "data" / "include_exclude_tests" report = black.Report() empty = re.compile(r"") sources: List[Path] = [] @@ -1120,7 +1121,7 @@ class BlackTestCase(unittest.TestCase): self.assertEqual(sorted(expected), sorted(sources)) def test_empty_exclude(self) -> None: - path = THIS_DIR / "include_exclude_tests" + path = THIS_DIR / "data" / "include_exclude_tests" report = black.Report() empty = re.compile(r"") sources: List[Path] = [] -- 2.39.5