From 56ad1d164a95a9f47548b47ef948d2d1114d6646 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Sat, 29 Sep 2018 23:15:18 -0700 Subject: [PATCH] Use Flake8 code checker as part of running automated tests. --- NEWS | 2 +- README.md | 5 +++-- borgmatic/borg/check.py | 2 +- borgmatic/commands/convert_config.py | 1 - borgmatic/commands/generate_config.py | 4 +--- borgmatic/config/convert.py | 2 +- borgmatic/config/generate.py | 1 - borgmatic/config/validate.py | 2 -- borgmatic/tests/integration/commands/test_borgmatic.py | 6 ++---- borgmatic/tests/integration/config/test_validate.py | 1 - borgmatic/tests/unit/borg/test_check.py | 3 ++- borgmatic/tests/unit/borg/test_create.py | 9 +++++---- borgmatic/tests/unit/borg/test_extract.py | 4 ++-- borgmatic/tests/unit/borg/test_info.py | 1 - borgmatic/tests/unit/borg/test_list.py | 1 - borgmatic/tests/unit/commands/test_borgmatic.py | 1 - test_requirements.txt | 1 + tox.ini | 5 +++++ 18 files changed, 24 insertions(+), 27 deletions(-) diff --git a/NEWS b/NEWS index 21910ca..7355607 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,5 @@ 1.2.7.dev0 - * Use Black code formatter as part of running automated tests. + * Use Black code formatter and Flake8 code checker as part of running automated tests. 1.2.6 * Fix generated configuration to also include a "keep_daily" value so pruning works out of the diff --git a/README.md b/README.md index 7f9eb3d..dd88122 100644 --- a/README.md +++ b/README.md @@ -383,8 +383,9 @@ the following deviations from it: indentation with an opening delimeter. borgmatic code uses the [Black](https://black.readthedocs.io/en/stable/) code -formatter, so some additional code style requirements will be enforced as -well. See the Black documentation for more information. +formatter and [Flake8](http://flake8.pycqa.org/en/latest/) code checker, so +certain code style requirements will be enforced when running automated tests. +See the Black and Flake8 documentation for more information. ### Development diff --git a/borgmatic/borg/check.py b/borgmatic/borg/check.py index 08de0e5..96f0fe2 100644 --- a/borgmatic/borg/check.py +++ b/borgmatic/borg/check.py @@ -84,7 +84,7 @@ def check_archives( repository, storage_config, consistency_config, local_path='borg', remote_path=None ): ''' - Given a local or remote repository path, a storage config dict, a consistency config dict, + Given a local or remote repository path, a storage config dict, a consistency config dict, and a local/remote commands to run, check the contained Borg archives for consistency. If there are no consistency checks to run, skip running them. diff --git a/borgmatic/commands/convert_config.py b/borgmatic/commands/convert_config.py index dc50e25..5a0bca1 100644 --- a/borgmatic/commands/convert_config.py +++ b/borgmatic/commands/convert_config.py @@ -1,6 +1,5 @@ from argparse import ArgumentParser import os -from subprocess import CalledProcessError import sys import textwrap diff --git a/borgmatic/commands/generate_config.py b/borgmatic/commands/generate_config.py index f5056e0..c552f19 100644 --- a/borgmatic/commands/generate_config.py +++ b/borgmatic/commands/generate_config.py @@ -1,9 +1,7 @@ from argparse import ArgumentParser -import os -from subprocess import CalledProcessError import sys -from borgmatic.config import convert, generate, validate +from borgmatic.config import generate, validate DEFAULT_DESTINATION_CONFIG_FILENAME = '/etc/borgmatic/config.yaml' diff --git a/borgmatic/config/convert.py b/borgmatic/config/convert.py index 16e92fc..4b27387 100644 --- a/borgmatic/config/convert.py +++ b/borgmatic/config/convert.py @@ -109,5 +109,5 @@ Please remove the "--excludes" argument and run borgmatic again.''' def guard_excludes_filename_omitted(excludes_filename): - if excludes_filename != None: + if excludes_filename is not None: raise LegacyExcludesFilenamePresent() diff --git a/borgmatic/config/generate.py b/borgmatic/config/generate.py index 5944e7a..509fcc4 100644 --- a/borgmatic/config/generate.py +++ b/borgmatic/config/generate.py @@ -1,4 +1,3 @@ -from collections import OrderedDict import os from ruamel import yaml diff --git a/borgmatic/config/validate.py b/borgmatic/config/validate.py index 35f6d16..a5133f4 100644 --- a/borgmatic/config/validate.py +++ b/borgmatic/config/validate.py @@ -1,6 +1,4 @@ import logging -import sys -import warnings import pkg_resources import pykwalify.core diff --git a/borgmatic/tests/integration/commands/test_borgmatic.py b/borgmatic/tests/integration/commands/test_borgmatic.py index 49225bf..c4dd382 100644 --- a/borgmatic/tests/integration/commands/test_borgmatic.py +++ b/borgmatic/tests/integration/commands/test_borgmatic.py @@ -1,5 +1,3 @@ -import os - from flexmock import flexmock import pytest @@ -13,7 +11,7 @@ def test_parse_arguments_with_no_arguments_uses_defaults(): parser = module.parse_arguments() assert parser.config_paths == config_paths - assert parser.excludes_filename == None + assert parser.excludes_filename is None assert parser.verbosity is 0 assert parser.json is False @@ -44,7 +42,7 @@ def test_parse_arguments_with_verbosity_flag_overrides_default(): parser = module.parse_arguments('--verbosity', '1') assert parser.config_paths == config_paths - assert parser.excludes_filename == None + assert parser.excludes_filename is None assert parser.verbosity == 1 diff --git a/borgmatic/tests/integration/config/test_validate.py b/borgmatic/tests/integration/config/test_validate.py index c510fbe..b1ca098 100644 --- a/borgmatic/tests/integration/config/test_validate.py +++ b/borgmatic/tests/integration/config/test_validate.py @@ -1,7 +1,6 @@ import io import string import sys -import os from flexmock import flexmock import pytest diff --git a/borgmatic/tests/unit/borg/test_check.py b/borgmatic/tests/unit/borg/test_check.py index c909d04..7218584 100644 --- a/borgmatic/tests/unit/borg/test_check.py +++ b/borgmatic/tests/unit/borg/test_check.py @@ -1,5 +1,6 @@ from subprocess import STDOUT -import logging, sys +import logging +import sys from flexmock import flexmock import pytest diff --git a/borgmatic/tests/unit/borg/test_create.py b/borgmatic/tests/unit/borg/test_create.py index 2d5858e..4318867 100644 --- a/borgmatic/tests/unit/borg/test_create.py +++ b/borgmatic/tests/unit/borg/test_create.py @@ -1,4 +1,5 @@ -import logging, os +import logging +import os from flexmock import flexmock @@ -45,9 +46,9 @@ def test_initialize_environment_without_configuration_should_not_set_environment try: os.environ = {} module.initialize_environment({}) - assert os.environ.get('BORG_PASSCOMMAND') == None - assert os.environ.get('BORG_PASSPHRASE') == None - assert os.environ.get('BORG_RSH') == None + assert os.environ.get('BORG_PASSCOMMAND') is None + assert os.environ.get('BORG_PASSPHRASE') is None + assert os.environ.get('BORG_RSH') is None finally: os.environ = orig_environ diff --git a/borgmatic/tests/unit/borg/test_extract.py b/borgmatic/tests/unit/borg/test_extract.py index 93cb474..6be2f5f 100644 --- a/borgmatic/tests/unit/borg/test_extract.py +++ b/borgmatic/tests/unit/borg/test_extract.py @@ -1,9 +1,9 @@ -import logging, sys +import logging +import sys from flexmock import flexmock from borgmatic.borg import extract as module -from borgmatic.verbosity import VERBOSITY_SOME, VERBOSITY_LOTS from borgmatic.tests.unit.test_verbosity import insert_logging_mock diff --git a/borgmatic/tests/unit/borg/test_info.py b/borgmatic/tests/unit/borg/test_info.py index 612f12c..440ecb2 100644 --- a/borgmatic/tests/unit/borg/test_info.py +++ b/borgmatic/tests/unit/borg/test_info.py @@ -1,5 +1,4 @@ import logging -from collections import OrderedDict from flexmock import flexmock diff --git a/borgmatic/tests/unit/borg/test_list.py b/borgmatic/tests/unit/borg/test_list.py index 9bb194a..2e72747 100644 --- a/borgmatic/tests/unit/borg/test_list.py +++ b/borgmatic/tests/unit/borg/test_list.py @@ -1,5 +1,4 @@ import logging -from collections import OrderedDict from flexmock import flexmock diff --git a/borgmatic/tests/unit/commands/test_borgmatic.py b/borgmatic/tests/unit/commands/test_borgmatic.py index 9531f1e..20af02d 100644 --- a/borgmatic/tests/unit/commands/test_borgmatic.py +++ b/borgmatic/tests/unit/commands/test_borgmatic.py @@ -2,7 +2,6 @@ import json import sys from flexmock import flexmock -import pytest from borgmatic.commands import borgmatic diff --git a/test_requirements.txt b/test_requirements.txt index 715183b..deb16a5 100644 --- a/test_requirements.txt +++ b/test_requirements.txt @@ -1,4 +1,5 @@ black==18.9b0 +flake8==3.5.0 flexmock==0.10.2 pykwalify==1.6.1 pytest==3.8.1 diff --git a/tox.ini b/tox.ini index 4f76bb7..b1521a2 100644 --- a/tox.ini +++ b/tox.ini @@ -8,8 +8,13 @@ deps=-rtest_requirements.txt commands = py.test --cov-report term-missing:skip-covered --cov=borgmatic borgmatic [] black --skip-string-normalization --line-length 100 --check . + flake8 . [testenv:black] basepython=python3.7 commands = black --skip-string-normalization --line-length 100 . + +[flake8] +ignore=E501,W503 +exclude=*.*/*