From 5f6357b884f12ad0b309c384790c3aea8e2cf827 Mon Sep 17 00:00:00 2001 From: Caleb Lemoine <21261388+circa10a@users.noreply.github.com> Date: Sun, 30 Dec 2018 16:06:23 -0600 Subject: [PATCH] Pre merge code quality checks (#72) * fix files with flake8 * bump version for per merge checks --- .dockerignore | 1 + .flake8 | 2 ++ .travis.yml | 1 + dev-environment.yml | 3 ++- ouroboros/cli.py | 5 ++--- requirements-dev.txt | 3 ++- setup.py | 2 +- tests/unit/_metrics_test.py | 3 +-- tests/unit/cli_test.py | 1 + tests/unit/container_object.py | 2 +- tests/unit/container_test.py | 1 + tests/unit/defaults_test.py | 1 + tests/unit/image_test.py | 1 - tests/unit/logger_test.py | 1 + tests/unit/main_unit_test.py | 8 ++++---- tests/unit/webhook_test.py | 2 +- 16 files changed, 22 insertions(+), 15 deletions(-) create mode 100644 .flake8 diff --git a/.dockerignore b/.dockerignore index b969110d..0d4dba00 100644 --- a/.dockerignore +++ b/.dockerignore @@ -7,3 +7,4 @@ tests/ .coveragerc .travis.yml doc/ +.flake8 \ No newline at end of file diff --git a/.flake8 b/.flake8 new file mode 100644 index 00000000..16520fcd --- /dev/null +++ b/.flake8 @@ -0,0 +1,2 @@ +[flake8] +ignore = E501 \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index e3d21cdb..5496769a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,7 @@ services: script: - ./run_tests.sh + - flake8 after_script: - codecov diff --git a/dev-environment.yml b/dev-environment.yml index 89777eaa..cc3b79e4 100644 --- a/dev-environment.yml +++ b/dev-environment.yml @@ -8,4 +8,5 @@ dependencies: - pytest - pytest-cov - pytest-mock - - codecov \ No newline at end of file + - codecov + - flake8 \ No newline at end of file diff --git a/ouroboros/cli.py b/ouroboros/cli.py index f626e5a6..b7b483fb 100644 --- a/ouroboros/cli.py +++ b/ouroboros/cli.py @@ -6,7 +6,7 @@ def checkURI(uri): """Validate tcp:// regex""" - regex = re.compile( r"""(?xi) # "verbose" mode & case-insensitive + regex = re.compile(r"""(?xi) # "verbose" mode & case-insensitive \A # in the beginning... tcps?:// # tcp or tcps protocol (?: # hostname / IP address @@ -46,8 +46,7 @@ def get_int_env_var(env_var): def parse(sysargs): """Declare command line options""" parser = argparse.ArgumentParser(description='ouroboros', - epilog='Example: ouroboros -u tcp://1.2.3.4:5678' - + '-i 20 -m container1 container2 -l warn') + epilog='Example: ouroboros -u tcp://1.2.3.4:5678 -i 20 -m container1 container2 -l warn') parser.add_argument('-u', '--url', default=defaults.LOCAL_UNIX_SOCKET, help='Url for tcp host (defaults to "unix://var/run/docker.sock")') diff --git a/requirements-dev.txt b/requirements-dev.txt index aece82a8..5f42acc3 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -5,4 +5,5 @@ requests pytest pytest-cov pytest-mock -codecov \ No newline at end of file +codecov +flake8 \ No newline at end of file diff --git a/setup.py b/setup.py index a5cbb984..c8cfff41 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ def read_reqs(requirements): setup( name='ouroboros-cli', - version='0.4.0', + version='0.4.1', description='Automatically update running docker containers', long_description=readme(), long_description_content_type='text/markdown', diff --git a/tests/unit/_metrics_test.py b/tests/unit/_metrics_test.py index 08d364ef..a542cee4 100644 --- a/tests/unit/_metrics_test.py +++ b/tests/unit/_metrics_test.py @@ -1,4 +1,3 @@ -import pytest from prometheus_client import REGISTRY import ouroboros.metrics as metrics @@ -14,4 +13,4 @@ def test_monitored_containers(): test_count = 5.0 metrics.monitored_containers(num=test_count) num_monitored = REGISTRY.get_sample_value('containers_being_monitored') - assert num_monitored == test_count \ No newline at end of file + assert num_monitored == test_count diff --git a/tests/unit/cli_test.py b/tests/unit/cli_test.py index b2292227..7df0a69c 100644 --- a/tests/unit/cli_test.py +++ b/tests/unit/cli_test.py @@ -215,6 +215,7 @@ def test_metrics_port_arg_invalid_value(mocker): cli.parse(['--metrics-port', 'test']) assert pytest_wrapped_e.type == SystemExit + # Webhooks @pytest.mark.parametrize('webhook_args, webhook_result', [ (['-w', 'http://my-webhook-1 ', 'http://my-webhook-2', 'http://my-webhook-3'], ['http://my-webhook-1 ', 'http://my-webhook-2', 'http://my-webhook-3']), diff --git a/tests/unit/container_object.py b/tests/unit/container_object.py index 394ffc8e..98a1cdea 100644 --- a/tests/unit/container_object.py +++ b/tests/unit/container_object.py @@ -225,4 +225,4 @@ } } } -} \ No newline at end of file +} diff --git a/tests/unit/container_test.py b/tests/unit/container_test.py index 6eca38c7..30117107 100644 --- a/tests/unit/container_test.py +++ b/tests/unit/container_test.py @@ -5,6 +5,7 @@ import ouroboros.defaults import logging + @pytest.fixture() def fake_container(): return container_object diff --git a/tests/unit/defaults_test.py b/tests/unit/defaults_test.py index ddb30a37..789c4dac 100644 --- a/tests/unit/defaults_test.py +++ b/tests/unit/defaults_test.py @@ -1,6 +1,7 @@ import pytest import ouroboros.defaults as defaults + @pytest.mark.parametrize('default, result', [ (defaults.INTERVAL, 300), (defaults.LOCAL_UNIX_SOCKET, 'unix://var/run/docker.sock'), diff --git a/tests/unit/image_test.py b/tests/unit/image_test.py index 81d38055..5d4db832 100644 --- a/tests/unit/image_test.py +++ b/tests/unit/image_test.py @@ -1,4 +1,3 @@ -import pytest import ouroboros.image as image import docker diff --git a/tests/unit/logger_test.py b/tests/unit/logger_test.py index 3dfb219f..d03baf8d 100644 --- a/tests/unit/logger_test.py +++ b/tests/unit/logger_test.py @@ -1,6 +1,7 @@ import pytest import ouroboros.logger as log + @pytest.mark.parametrize('level_string, level_code', [ ('debug', 10), ('info', 20), diff --git a/tests/unit/main_unit_test.py b/tests/unit/main_unit_test.py index 5aa0227b..fb65ff06 100644 --- a/tests/unit/main_unit_test.py +++ b/tests/unit/main_unit_test.py @@ -36,12 +36,12 @@ def test_main_full(fake_namespace, fake_api, caplog): fake_namespace.keep_tag = True fake_namespace.webhook_urls = ["http://testurl1"] - fake_api.inspect_container.return_value = container_object # called twice - fake_api.containers.return_value = [container_object] # called twice + fake_api.inspect_container.return_value = container_object # called twice + fake_api.containers.return_value = [container_object] # called twice fake_api.inspect_image.side_effect = [{'RepoTags': ["repo:1.1"], 'Id': '1'}, {'RepoTags': ["repo:latest"], - 'Id': '2'}] # called twice + 'Id': '2'}] # called twice fake_api.create_container.return_value = {'Id': '2'} with pytest.raises(SystemExit) as e: @@ -71,7 +71,7 @@ def test_main_exception(fake_namespace, fake_api, caplog): fake_api.inspect_container.return_value = container_object # called twice fake_api.containers.return_value = [container_object] # called twice - fake_api.inspect_image.return_value = {'RepoTags': ["repo:1.1"], 'Id': '1'} # called once + fake_api.inspect_image.return_value = {'RepoTags': ["repo:1.1"], 'Id': '1'} # called once fake_api.pull.side_effect = docker.errors.APIError("I blew up!!") fake_api.create_container.return_value = {'Id': '2'} diff --git a/tests/unit/webhook_test.py b/tests/unit/webhook_test.py index dfe626fd..6cd95f22 100644 --- a/tests/unit/webhook_test.py +++ b/tests/unit/webhook_test.py @@ -1,7 +1,7 @@ import pytest -import requests import ouroboros.webhook as webhook + def test_webook_schema_error(): with pytest.raises(Exception): assert webhook.post(urls=['http:/my-false-url'], container_name='test_name', old_sha='1', new_sha='2')