Unverified Commit e6cd10e7 authored by Sagi Shadur's avatar Sagi Shadur Committed by GitHub
Browse files

Extract formatting tests (#1785)

* Update test versions

* Use parametrize to remove tests duplications

* Extract sources format tests

* Fix mypy errors

* Fix .travis.yml
parent cabeb5b5
Loading
Loading
Loading
Loading
+2 −2
Changes for .travis.yml: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -4,9 +4,9 @@ cache:
  directories:
    - $HOME/.cache/pre-commit
env:
  - TEST_CMD="coverage run -m unittest"
  - TEST_CMD="tox -e py"
install:
  - pip install coverage coveralls pre-commit
  - pip install coverage coveralls pre-commit tox
  - pip install -e '.[d]'
script:
  - $TEST_CMD
+5 −4
Changes for test_requirements.txt: 5 added lines, 4 removed lines.
Original line number Diff line number Diff line
pytest >= 6.0.1
pytest-mock >= 3.2.0
pytest-cases >= 2.1.2
coverage >= 5.2.1
 No newline at end of file
pytest >= 6.1.1
pytest-mock >= 3.3.1
pytest-cases >= 2.3.0
coverage >= 5.3
parameterized >= 0.7.4
 No newline at end of file
+11 −405

File changed.

Preview size limit exceeded, changes collapsed.

tests/test_format.py

0 → 100644
+98 −0
Changes for tests/test_format.py: 98 added lines, 0 removed lines.
Original line number Diff line number Diff line
from unittest.mock import patch

import black
from parameterized import parameterized

from tests.util import (
    BlackBaseTestCase,
    fs,
    ff,
    DEFAULT_MODE,
    dump_to_stderr,
    read_data,
    THIS_DIR,
)

SIMPLE_CASES = [
    "beginning_backslash",
    "bracketmatch",
    "cantfit",
    "class_blank_parentheses",
    "class_methods_new_line",
    "collections",
    "comments",
    "comments2",
    "comments3",
    "comments4",
    "comments5",
    "comments6",
    "comments7",
    "comment_after_escaped_newline",
    "composition",
    "composition_no_trailing_comma",
    "docstring",
    "empty_lines",
    "expression",
    "fmtonoff",
    "fmtonoff2",
    "fmtonoff3",
    "fmtonoff4",
    "fstring",
    "function",
    "function2",
    "function_trailing_comma",
    "import_spacing",
    "long_strings",
    "long_strings__edge_case",
    "long_strings__regression",
    "numeric_literals_py2",
    "percent_precedence",
    "python2",
    "python2_unicode_literals",
    "remove_parens",
    "slices",
    "string_prefixes",
    "tricky_unicode_symbols",
    "tupleassign",
]


SOURCES = [
    "tests/test_black.py",
    "tests/test_format.py",
    "tests/test_blackd.py",
    "src/black/__init__.py",
    "src/blib2to3/pygram.py",
    "src/blib2to3/pytree.py",
    "src/blib2to3/pgen2/conv.py",
    "src/blib2to3/pgen2/driver.py",
    "src/blib2to3/pgen2/grammar.py",
    "src/blib2to3/pgen2/literals.py",
    "src/blib2to3/pgen2/parse.py",
    "src/blib2to3/pgen2/pgen.py",
    "src/blib2to3/pgen2/tokenize.py",
    "src/blib2to3/pgen2/token.py",
    "setup.py",
]


class TestSimpleFormat(BlackBaseTestCase):
    @parameterized.expand(SIMPLE_CASES)
    @patch("black.dump_to_file", dump_to_stderr)
    def test_simple_format(self, filename: str) -> None:
        source, expected = read_data(filename)
        actual = fs(source)
        self.assertFormatEqual(expected, actual)
        black.assert_equivalent(source, actual)
        black.assert_stable(source, actual, DEFAULT_MODE)

    @parameterized.expand(SOURCES)
    @patch("black.dump_to_file", dump_to_stderr)
    def test_source_is_formatted(self, filename: str) -> None:
        path = THIS_DIR.parent / filename
        source, expected = read_data(str(path), data=False)
        actual = fs(source, mode=DEFAULT_MODE)
        self.assertFormatEqual(expected, actual)
        black.assert_equivalent(source, actual)
        black.assert_stable(source, actual, DEFAULT_MODE)
        self.assertFalse(ff(path))
+44 −4

File changed.

Preview size limit exceeded, changes collapsed.