Sfoglia il codice sorgente

Use Flake8 code checker as part of running automated tests.

Dan Helfman 6 anni fa
parent
commit
56ad1d164a

+ 1 - 1
NEWS

@@ -1,5 +1,5 @@
 1.2.7.dev0
 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
 1.2.6
  * Fix generated configuration to also include a "keep_daily" value so pruning works out of the
  * Fix generated configuration to also include a "keep_daily" value so pruning works out of the

+ 3 - 2
README.md

@@ -383,8 +383,9 @@ the following deviations from it:
    indentation with an opening delimeter.
    indentation with an opening delimeter.
 
 
 borgmatic code uses the [Black](https://black.readthedocs.io/en/stable/) code
 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
 ### Development

+ 1 - 1
borgmatic/borg/check.py

@@ -84,7 +84,7 @@ def check_archives(
     repository, storage_config, consistency_config, local_path='borg', remote_path=None
     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.
     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.
     If there are no consistency checks to run, skip running them.

+ 0 - 1
borgmatic/commands/convert_config.py

@@ -1,6 +1,5 @@
 from argparse import ArgumentParser
 from argparse import ArgumentParser
 import os
 import os
-from subprocess import CalledProcessError
 import sys
 import sys
 import textwrap
 import textwrap
 
 

+ 1 - 3
borgmatic/commands/generate_config.py

@@ -1,9 +1,7 @@
 from argparse import ArgumentParser
 from argparse import ArgumentParser
-import os
-from subprocess import CalledProcessError
 import sys
 import sys
 
 
-from borgmatic.config import convert, generate, validate
+from borgmatic.config import generate, validate
 
 
 
 
 DEFAULT_DESTINATION_CONFIG_FILENAME = '/etc/borgmatic/config.yaml'
 DEFAULT_DESTINATION_CONFIG_FILENAME = '/etc/borgmatic/config.yaml'

+ 1 - 1
borgmatic/config/convert.py

@@ -109,5 +109,5 @@ Please remove the "--excludes" argument and run borgmatic again.'''
 
 
 
 
 def guard_excludes_filename_omitted(excludes_filename):
 def guard_excludes_filename_omitted(excludes_filename):
-    if excludes_filename != None:
+    if excludes_filename is not None:
         raise LegacyExcludesFilenamePresent()
         raise LegacyExcludesFilenamePresent()

+ 0 - 1
borgmatic/config/generate.py

@@ -1,4 +1,3 @@
-from collections import OrderedDict
 import os
 import os
 
 
 from ruamel import yaml
 from ruamel import yaml

+ 0 - 2
borgmatic/config/validate.py

@@ -1,6 +1,4 @@
 import logging
 import logging
-import sys
-import warnings
 
 
 import pkg_resources
 import pkg_resources
 import pykwalify.core
 import pykwalify.core

+ 2 - 4
borgmatic/tests/integration/commands/test_borgmatic.py

@@ -1,5 +1,3 @@
-import os
-
 from flexmock import flexmock
 from flexmock import flexmock
 import pytest
 import pytest
 
 
@@ -13,7 +11,7 @@ def test_parse_arguments_with_no_arguments_uses_defaults():
     parser = module.parse_arguments()
     parser = module.parse_arguments()
 
 
     assert parser.config_paths == config_paths
     assert parser.config_paths == config_paths
-    assert parser.excludes_filename == None
+    assert parser.excludes_filename is None
     assert parser.verbosity is 0
     assert parser.verbosity is 0
     assert parser.json is False
     assert parser.json is False
 
 
@@ -44,7 +42,7 @@ def test_parse_arguments_with_verbosity_flag_overrides_default():
     parser = module.parse_arguments('--verbosity', '1')
     parser = module.parse_arguments('--verbosity', '1')
 
 
     assert parser.config_paths == config_paths
     assert parser.config_paths == config_paths
-    assert parser.excludes_filename == None
+    assert parser.excludes_filename is None
     assert parser.verbosity == 1
     assert parser.verbosity == 1
 
 
 
 

+ 0 - 1
borgmatic/tests/integration/config/test_validate.py

@@ -1,7 +1,6 @@
 import io
 import io
 import string
 import string
 import sys
 import sys
-import os
 
 
 from flexmock import flexmock
 from flexmock import flexmock
 import pytest
 import pytest

+ 2 - 1
borgmatic/tests/unit/borg/test_check.py

@@ -1,5 +1,6 @@
 from subprocess import STDOUT
 from subprocess import STDOUT
-import logging, sys
+import logging
+import sys
 
 
 from flexmock import flexmock
 from flexmock import flexmock
 import pytest
 import pytest

+ 5 - 4
borgmatic/tests/unit/borg/test_create.py

@@ -1,4 +1,5 @@
-import logging, os
+import logging
+import os
 
 
 from flexmock import flexmock
 from flexmock import flexmock
 
 
@@ -45,9 +46,9 @@ def test_initialize_environment_without_configuration_should_not_set_environment
     try:
     try:
         os.environ = {}
         os.environ = {}
         module.initialize_environment({})
         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:
     finally:
         os.environ = orig_environ
         os.environ = orig_environ
 
 

+ 2 - 2
borgmatic/tests/unit/borg/test_extract.py

@@ -1,9 +1,9 @@
-import logging, sys
+import logging
+import sys
 
 
 from flexmock import flexmock
 from flexmock import flexmock
 
 
 from borgmatic.borg import extract as module
 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
 from borgmatic.tests.unit.test_verbosity import insert_logging_mock
 
 
 
 

+ 0 - 1
borgmatic/tests/unit/borg/test_info.py

@@ -1,5 +1,4 @@
 import logging
 import logging
-from collections import OrderedDict
 
 
 from flexmock import flexmock
 from flexmock import flexmock
 
 

+ 0 - 1
borgmatic/tests/unit/borg/test_list.py

@@ -1,5 +1,4 @@
 import logging
 import logging
-from collections import OrderedDict
 
 
 from flexmock import flexmock
 from flexmock import flexmock
 
 

+ 0 - 1
borgmatic/tests/unit/commands/test_borgmatic.py

@@ -2,7 +2,6 @@ import json
 import sys
 import sys
 
 
 from flexmock import flexmock
 from flexmock import flexmock
-import pytest
 
 
 from borgmatic.commands import borgmatic
 from borgmatic.commands import borgmatic
 
 

+ 1 - 0
test_requirements.txt

@@ -1,4 +1,5 @@
 black==18.9b0
 black==18.9b0
+flake8==3.5.0
 flexmock==0.10.2
 flexmock==0.10.2
 pykwalify==1.6.1
 pykwalify==1.6.1
 pytest==3.8.1
 pytest==3.8.1

+ 5 - 0
tox.ini

@@ -8,8 +8,13 @@ deps=-rtest_requirements.txt
 commands =
 commands =
     py.test --cov-report term-missing:skip-covered --cov=borgmatic borgmatic []
     py.test --cov-report term-missing:skip-covered --cov=borgmatic borgmatic []
     black --skip-string-normalization --line-length 100 --check .
     black --skip-string-normalization --line-length 100 --check .
+    flake8 .
 
 
 [testenv:black]
 [testenv:black]
 basepython=python3.7
 basepython=python3.7
 commands =
 commands =
     black --skip-string-normalization --line-length 100 .
     black --skip-string-normalization --line-length 100 .
+
+[flake8]
+ignore=E501,W503
+exclude=*.*/*