Skip to content

Commit

Permalink
Match black/flake8 max-line-length (syrusakbary#138)
Browse files Browse the repository at this point in the history
Reformat long doc strings and comments to black's
preferred max-line-length of 88, so that flake8
can use the same setting.

(I'm deliberately noqa-punting on the generated
Django settings.py file.)
  • Loading branch information
medmunds authored Oct 1, 2020
1 parent 261c794 commit 05dec29
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 16 deletions.
2 changes: 1 addition & 1 deletion examples/django_project/django_project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@

AUTH_PASSWORD_VALIDATORS = [
{
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", # noqa: E501
},
{
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
Expand Down
13 changes: 8 additions & 5 deletions examples/pytest/test_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,19 @@ def __repr__(self):

def test_object(snapshot):
"""
Test a snapshot with a custom object. The object will be represented in the snapshot using
`snapshottest.GenericRepr`. The snapshot will only match if the object's repr remains the same.
Test a snapshot with a custom object. The object will be represented in the
snapshot using `snapshottest.GenericRepr`. The snapshot will only match if the
object's repr remains the same.
"""
test_value = SomeObject(3)
snapshot.assert_match(test_value)


def test_file(snapshot, tmpdir):
"""
Test a file snapshot. The file contents will be saved in a sub-folder of the snapshots folder. Useful for large
files (e.g. media files) that aren't suitable for storage as text inside the snap_***.py file.
Test a file snapshot. The file contents will be saved in a sub-folder of the
snapshots folder. Useful for large files (e.g. media files) that aren't suitable
for storage as text inside the snap_***.py file.
"""
temp_file = tmpdir.join("example.txt")
temp_file.write("Hello, world!")
Expand All @@ -51,7 +53,8 @@ def test_file(snapshot, tmpdir):

def test_multiple_files(snapshot, tmpdir):
"""
Each file is stored separately with the snapshot's name inside the module's file snapshots folder.
Each file is stored separately with the snapshot's name inside the module's file
snapshots folder.
"""
temp_file1 = tmpdir.join("example1.txt")
temp_file1.write("Hello, world 1!")
Expand Down
4 changes: 1 addition & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

[flake8]
exclude = snapshots .tox venv
# (Although black recommends `max-line-length = 88`, there are still
# several longer doc strings, which black won't reformat.)
max-line-length = 120
max-line-length = 88
extend-ignore = E203

[tool:pytest]
Expand Down
10 changes: 6 additions & 4 deletions snapshottest/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
class FileSnapshot(object):
def __init__(self, path):
"""
Create a file snapshot pointing to the specified `path`. In a snapshot, `path` is considered to be relative to
the test module's "snapshots" folder. (This is done to prevent ugly path manipulations inside the snapshot
file.)
Create a file snapshot pointing to the specified `path`. In a snapshot, `path`
is considered to be relative to the test module's "snapshots" folder. (This is
done to prevent ugly path manipulations inside the snapshot file.)
"""
self.path = path

Expand All @@ -29,7 +29,9 @@ def can_format(self, value):
def store(self, test, value):
"""
Copy the file from the test location to the snapshot location.
If the original test file has an extension, the snapshot file will use the same extension.
If the original test file has an extension, the snapshot file will
use the same extension.
"""

file_snapshot_dir = self.get_file_snapshot_dir(test)
Expand Down
4 changes: 3 additions & 1 deletion snapshottest/pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ def pytest_terminal_summary(terminalreporter):
terminalreporter.config._snapshotsession.display(terminalreporter)


@pytest.mark.trylast # force the other plugins to initialise, fixes issue with capture not being properly initialised
# force the other plugins to initialise first
# (fixes issue with capture not being properly initialised)
@pytest.mark.trylast
def pytest_configure(config):
config._snapshotsession = SnapshotSession(config)
# config.pluginmanager.register(bs, "snapshottest")
6 changes: 4 additions & 2 deletions tests/test_pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def test_pytest_snapshottest_property_test_name_parametrize_singleline(
pytest_snapshot_test.assert_match("counter")
assert (
pytest_snapshot_test.test_name
== "test_pytest_snapshottest_property_test_name_parametrize_singleline[single line string] 1"
== "test_pytest_snapshottest_property_test_name_parametrize_singleline"
"[single line string] 1"
)


Expand All @@ -87,5 +88,6 @@ def test_pytest_snapshottest_property_test_name_parametrize_multiline(
pytest_snapshot_test.assert_match("counter")
assert (
pytest_snapshot_test.test_name
== "test_pytest_snapshottest_property_test_name_parametrize_multiline[ multi line string ] 1"
== "test_pytest_snapshottest_property_test_name_parametrize_multiline"
"[ multi line string ] 1"
)

0 comments on commit 05dec29

Please sign in to comment.