Skip to content

Commit

Permalink
Tidy up the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
msullivan committed Oct 2, 2019
1 parent 82deeb2 commit 3b3ce35
Showing 1 changed file with 25 additions and 93 deletions.
118 changes: 25 additions & 93 deletions tests/test_black.py
Expand Up @@ -158,6 +158,16 @@ def invokeBlack(
result = runner.invoke(black.main, args)
self.assertEqual(result.exit_code, exit_code, msg=runner.stderr_bytes.decode())

@patch("black.dump_to_file", dump_to_stderr)
def checkSourceFile(self, name: str) -> None:
path = THIS_DIR.parent / name
source, expected = read_data(str(path), data=False)
actual = fs(source)
self.assertFormatEqual(expected, actual)
black.assert_equivalent(source, actual)
black.assert_stable(source, actual, black.FileMode())
self.assertFalse(ff(path))

@patch("black.dump_to_file", dump_to_stderr)
def test_empty(self) -> None:
source = expected = ""
Expand All @@ -177,113 +187,44 @@ def test_empty_ff(self) -> None:
os.unlink(tmp_file)
self.assertFormatEqual(expected, actual)

@patch("black.dump_to_file", dump_to_stderr)
def test_self(self) -> None:
source, expected = read_data("test_black", data=False)
actual = fs(source)
self.assertFormatEqual(expected, actual)
black.assert_equivalent(source, actual)
black.assert_stable(source, actual, black.FileMode())
self.assertFalse(ff(THIS_FILE))
self.checkSourceFile("tests/test_black.py")

@patch("black.dump_to_file", dump_to_stderr)
def test_black(self) -> None:
source, expected = read_data("../black", data=False)
actual = fs(source)
self.assertFormatEqual(expected, actual)
black.assert_equivalent(source, actual)
black.assert_stable(source, actual, black.FileMode())
self.assertFalse(ff(THIS_DIR / ".." / "black.py"))
self.checkSourceFile("black.py")

@patch("black.dump_to_file", dump_to_stderr)
def test_pygram(self) -> None:
source, expected = read_data("../blib2to3/pygram", data=False)
actual = fs(source)
self.assertFormatEqual(expected, actual)
black.assert_equivalent(source, actual)
black.assert_stable(source, actual, black.FileMode())
self.assertFalse(ff(THIS_DIR / ".." / "blib2to3" / "pygram.py"))
self.checkSourceFile("blib2to3/pygram.py")

@patch("black.dump_to_file", dump_to_stderr)
def test_pytree(self) -> None:
source, expected = read_data("../blib2to3/pytree", data=False)
actual = fs(source)
self.assertFormatEqual(expected, actual)
black.assert_equivalent(source, actual)
black.assert_stable(source, actual, black.FileMode())
self.assertFalse(ff(THIS_DIR / ".." / "blib2to3" / "pytree.py"))
self.checkSourceFile("blib2to3/pytree.py")

@patch("black.dump_to_file", dump_to_stderr)
def test_conv(self) -> None:
source, expected = read_data("../blib2to3/pgen2/conv", data=False)
actual = fs(source)
self.assertFormatEqual(expected, actual)
black.assert_equivalent(source, actual)
black.assert_stable(source, actual, black.FileMode())
self.assertFalse(ff(THIS_DIR / ".." / "blib2to3" / "pgen2" / "conv.py"))
self.checkSourceFile("blib2to3/pgen2/conv.py")

@patch("black.dump_to_file", dump_to_stderr)
def test_driver(self) -> None:
source, expected = read_data("../blib2to3/pgen2/driver", data=False)
actual = fs(source)
self.assertFormatEqual(expected, actual)
black.assert_equivalent(source, actual)
black.assert_stable(source, actual, black.FileMode())
self.assertFalse(ff(THIS_DIR / ".." / "blib2to3" / "pgen2" / "driver.py"))
self.checkSourceFile("blib2to3/pgen2/driver.py")

@patch("black.dump_to_file", dump_to_stderr)
def test_grammar(self) -> None:
source, expected = read_data("../blib2to3/pgen2/grammar", data=False)
actual = fs(source)
self.assertFormatEqual(expected, actual)
black.assert_equivalent(source, actual)
black.assert_stable(source, actual, black.FileMode())
self.assertFalse(ff(THIS_DIR / ".." / "blib2to3" / "pgen2" / "grammar.py"))
self.checkSourceFile("blib2to3/pgen2/grammar.py")

@patch("black.dump_to_file", dump_to_stderr)
def test_literals(self) -> None:
source, expected = read_data("../blib2to3/pgen2/literals", data=False)
actual = fs(source)
self.assertFormatEqual(expected, actual)
black.assert_equivalent(source, actual)
black.assert_stable(source, actual, black.FileMode())
self.assertFalse(ff(THIS_DIR / ".." / "blib2to3" / "pgen2" / "literals.py"))
self.checkSourceFile("blib2to3/pgen2/literals.py")

@patch("black.dump_to_file", dump_to_stderr)
def test_parse(self) -> None:
source, expected = read_data("../blib2to3/pgen2/parse", data=False)
actual = fs(source)
self.assertFormatEqual(expected, actual)
black.assert_equivalent(source, actual)
black.assert_stable(source, actual, black.FileMode())
self.assertFalse(ff(THIS_DIR / ".." / "blib2to3" / "pgen2" / "parse.py"))
self.checkSourceFile("blib2to3/pgen2/parse.py")

@patch("black.dump_to_file", dump_to_stderr)
def test_pgen(self) -> None:
source, expected = read_data("../blib2to3/pgen2/pgen", data=False)
actual = fs(source)
self.assertFormatEqual(expected, actual)
black.assert_equivalent(source, actual)
black.assert_stable(source, actual, black.FileMode())
self.assertFalse(ff(THIS_DIR / ".." / "blib2to3" / "pgen2" / "pgen.py"))
self.checkSourceFile("blib2to3/pgen2/pgen.py")

@patch("black.dump_to_file", dump_to_stderr)
def test_tokenize(self) -> None:
source, expected = read_data("../blib2to3/pgen2/tokenize", data=False)
actual = fs(source)
self.assertFormatEqual(expected, actual)
black.assert_equivalent(source, actual)
black.assert_stable(source, actual, black.FileMode())
self.assertFalse(ff(THIS_DIR / ".." / "blib2to3" / "pgen2" / "tokenize.py"))
self.checkSourceFile("blib2to3/pgen2/tokenize.py")

@patch("black.dump_to_file", dump_to_stderr)
def test_token(self) -> None:
source, expected = read_data("../blib2to3/pgen2/token", data=False)
actual = fs(source)
self.assertFormatEqual(expected, actual)
black.assert_equivalent(source, actual)
black.assert_stable(source, actual, black.FileMode())
self.assertFalse(ff(THIS_DIR / ".." / "blib2to3" / "pgen2" / "token.py"))
self.checkSourceFile("blib2to3/pgen2/token.py")

def test_setup(self) -> None:
self.checkSourceFile("setup.py")

def test_piping(self) -> None:
source, expected = read_data("../black", data=False)
Expand Down Expand Up @@ -320,15 +261,6 @@ def test_piping_diff(self) -> None:
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_setup(self) -> None:
source, expected = read_data("../setup", data=False)
actual = fs(source)
self.assertFormatEqual(expected, actual)
black.assert_equivalent(source, actual)
black.assert_stable(source, actual, black.FileMode())
self.assertFalse(ff(THIS_DIR / ".." / "setup.py"))

@patch("black.dump_to_file", dump_to_stderr)
def test_function(self) -> None:
source, expected = read_data("function")
Expand Down

0 comments on commit 3b3ce35

Please sign in to comment.